-
-
Notifications
You must be signed in to change notification settings - Fork 12
Description
I have a bit of a weid and complex protocol, where I attempt to be robust for the following pattern:
XX XX ID DATA CHECKSUM XX XX
Since the message length is variable due to a lot of optional / conditional fields, the decoding attempts to reason back from the checksum towards the front of the message. At least that is my interpretation. If there are garbage bytes around the message, the decoder is unable to parse the data properly. I use a deque for the incoming datastream, and I have played around with error status and discarding bytes, but it does not seem the right approach.
While debugging I discovered the following when garbage bytes are found in front of the message. The message id layer reports (correctly) an invalid message id. However, the checksum layer only checks for the NotEnoughData and ProtocolError states. See the screenshot below.
In the end a 'ProtocolError' is reported instead, which is also 'sort of fine', but a ProtocolError can be anything. Ideally, I would like to pop bytes from the front of the stream while there is enough data and an invalid message id is found. This would allow me to properly align the datastream with the protocol decoding. Does that make sense?