protocol library
Protocol layer: wire-format constants, header calculations and the Magpie / Packet interfaces.
Import this facade when you only need the wire format primitives
(constants, calculators, command values, interfaces), without the
concrete packet classes. See docs/protocol.md for the wire format.
Classes
Constants
- ATTACHMENT_LENGTH → const int
- Attachment length: HMAC-SHA256, 32 bytes.
- MAGIC_CODE → const int
- Magic Code: 'M', 'P', '\0', '\1' (Messaging Protocol v1).
- MAX_HEADER_LENGTH → const int
- Maximum header size (all optional fields present, E=4).
- MAX_PAYLOAD_LENGTH → const int
- Suggested payload cap on the sender side (bytes).
- MIN_HEADER_LENGTH → const int
- Fixed header size: magic(4) + type(1) + headerLen(1) + payloadLen(2).
- MSS → const int
- Max datagram size (IPv6 minimum MTU 1280 - 40 ipv6 header - 8 udp header) MSS hard cap: header + payload (+ attachment) <= 1232.
Functions
-
calcCmd(
int command) → int - C flag: command == 0 => C=0 (plain DATA).
-
calcDsn(
int sn) → int - D flag: sn == 0 => D=0 (system command).
-
calcExt(
int count) → int - E width: count >= 65536 => 4; count >= 2 => 2; else 0.
-
calcHeaderLength(
{required int bid, required int cmd, required int dsn, required int ext}) → int - Header length: N = 8 + 8·B + 4·D + 2·E + 4·C.
-
calcType(
{required int ack, required int bid, required int cmd, required int dsn, required int ext}) → int - Compose the type byte: A(7) B(6) C(5) D(4) E(low 3 bits).