Skip to main content

Module codec

Module codec 

Source
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 == 0

Structs§

Packet
A protocol packet, borrowed from a buffer.

Enums§

DecodeError
Reasons a decode call may fail.
EncodeError
Reasons an encode call may fail. None of these can occur for packets constructed via Packet::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.