Expand description
A protocol message is defined as follows:
component | size (bits) | description |
---|---|---|
msg_type | 2 | The type (action) of the message |
msg_length | 6 | The length of the entire message |
msg_payload | 0 - 62 bytes | The payload of the message |
checksum | 8 | The checksum of the message |
Note that:
- the
msg_type
andmsg_length
form the first byte of the message, which is the first two bits of the byte formsg_type
and the following six bits formsg_length
. - the value of
msg_length
is the length of the entire message in bytes, as 6 (unsigned) bits can hold value from0
to63
. Its maximum value is defined asMAX_PROTOCOL_SIZE
. So a single protocol message is capable of carryingMAX_PROTOCOL_SIZE
- 2 = 61
bytes as payload, this value is denoted asMAX_PAYLOAD_SIZE
. - the checksum is not included in the
Message
struct, it is calculated and appended when serializing the message. Similarly, the process of deserializing will also validate the checksum.
Structs
- A protocol message. See the module-level documentation for more details.
Enums
- The type (action) of a message which is the first two bits of a message.
Constants
- Maximum size of payload comes from
MAX_PROTOCOL_SIZE - 2
. - Maximum size of a protocol message. It is counted in bytes.
Type Aliases
- A byte is logically equivalent to an 8-bit unsigned integer.