Module client::protocol::message

source ·
Expand description

A protocol message is defined as follows:

componentsize (bits)description
msg_type2The type (action) of the message
msg_length6The length of the entire message
msg_payload0 - 62 bytesThe payload of the message
checksum8The checksum of the message

Note that:

  1. the msg_type and msg_length form the first byte of the message, which is the first two bits of the byte for msg_type and the following six bits for msg_length.
  2. the value of msg_length is the length of the entire message in bytes, as 6 (unsigned) bits can hold value from 0 to 63. Its maximum value is defined as MAX_PROTOCOL_SIZE. So a single protocol message is capable of carrying MAX_PROTOCOL_SIZE - 2 = 61 bytes as payload, this value is denoted as MAX_PAYLOAD_SIZE.
  3. 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

Type Aliases

  • A byte is logically equivalent to an 8-bit unsigned integer.