Expand description
FIFO queue with a packet-based interface preserving packet boundaries
The MsgQueue
is implemented on top of the ByteQueue
. It handles variable-sized messages
using the following format:
Field | Size |
---|---|
Message Prefix | Fixed size, configurable |
Protocol Version | 1 byte |
Data Size | 4 bytes in little endian |
Header CRC | 4 bytes in little endian |
Data | variable-sized - determined by the data size field |
Message CRC | 4 bytes in little endian |
- The Message Prefix is a fixed-size field provided by the user to identify the beginning
of a new message. If it is guaranteed that the memory will not be written by other processes,
it may also be left blank (
b""
) but a short prefix will also not hurt much and provide more robustness. Theoretically, the prefix could also be used to categorize messages, i.e. to multiplex different message channels over the same memory. But currently, this is not implemented and there are currently no plans to do so and aMsgQueue
will consider all bytes preceding the prefix as garbage and remove them. - The Protocol Version is a 1 byte value specifying the version of the communication protocol being used for compatibility checks. It is set to a constant value for each protocol version and guarantees robustness between library versions with protocol changes.
- The Data Size specifies the length of the message data.
- The Header CRC checks the integrity of the Message Prefix, Protocol Version, and Data
Size. This has been introduced to prevent getting stuck when the Data Size field contains
garbage which is interpreted as huge message length so that the
MsgQueue
would wait forever. Since the library isno_std
, this approach has been taken instead of a classic timeout. - The Data field contains the actual message data.
- The Message CRC ensures the integrity of the entire message packet.
Structs§
- MsgQueue
- The
MsgQueue
queue type usingByteQueue
as the underlying communication mechanism. Read the crate and module documentation for further information and usage examples.