Expand description
Layer 1: packet encoding, decoding, and Fletcher-16 checksum.
This module deals only in bytes and packet structures. It has no notion of sessions, sync counters, or file transfer.
§Wire format
offset size field notes
------ ---- ---------------------- -----------------------------------
0 2 start_token (0xB5AD) little-endian; NOT in checksum
2 1 sync wraps mod 256
3 1 proto<<4 | packet_type high nibble proto, low nibble type
4 2 payload_len (u16 LE)
6 2 header_checksum (u16) Fletcher-16 of bytes [2..6]
8 N payload absent if N == 0
8+N 2 payload_checksum (u16) Fletcher-16 of bytes [2..8+N]
ABSENT if payload_len == 0Structs§
- Packet
- A protocol packet, borrowed from a buffer.
Enums§
- Decode
Error - Reasons a
decodecall may fail. - Encode
Error - Reasons an
encodecall may fail. None of these can occur for packets constructed viaPacket::new, which validates up front.
Constants§
- HEADER_
LEN - Header overhead in bytes: token(2) + sync(1) + proto/type(1) + length(2)
- MAX_
PAYLOAD - Maximum payload size in a single packet (the length field is u16).
- PACKET_
TOKEN - Marlin BFT packet start token. Encoded little-endian on the wire.
Functions§
- decode
- Decode a packet from the start of
buf. - encode
- Encode a packet, appending the wire bytes to
out. - fletcher16
- Fletcher-16, mod-255 variant — exactly matches Marlin’s host protocol.