Skip to main content

Module framing

Module framing 

Source
Expand description

Length-prefixed wire framing for deCDN ALPNs (ADR 013).

Every message on every QUIC stream is varint(len) || postcard_bytes[0..len]. The varint uses postcard’s native continuation-bit encoding (7 data bits per byte, MSB = continuation, little-endian, 1–5 bytes for u32).

Receivers read the varint length, reject anything above MAX_MESSAGE_SIZE before allocation, allocate exactly that many bytes, then deserialize the frame with decode_message (a thin wrapper over postcard::take_from_bytes that preserves the trailing remainder for future Tier-1 extension fields).

Enums§

FrameError
Errors produced by the framing helpers. The handler-layer mapping to QUIC application error codes lives in the node crate.

Constants§

MAX_MESSAGE_SIZE
Maximum framed message size. Pinned at exactly 16 MiB by ADR 013 §Wire Framing, uniformly across all ALPNs in v1.

Traits§

TopLevelEnum
A top-level ALPN protocol enum (one per ALPN — crate::ProbeMessage, crate::ClientMessage, crate::DhtMessage). Serialized as the outermost postcard value in a frame, so its variant discriminant is the frame’s leading varint.

Functions§

decode_message
Decode a frame into a message and the unconsumed remainder. The remainder is reserved for Tier-1 extension fields (ADR 013 §Tier 1).
encode_message
Serialize msg to a postcard buffer suitable for passing to write_frame.
is_unknown_variant
Classify a failed top-level-enum decode per ADR 013: return true iff the frame’s leading discriminant names a variant at or beyond M::VARIANT_COUNT — i.e. an unknown/unsupported variant the receiver must answer with UNSUPPORTED_MESSAGE (0x01) rather than MALFORMED_MESSAGE (0x03).
parse_frame
Try to locate one complete length-prefixed frame at the front of buf without consuming it, returning (header_len, payload_len) — the byte counts of the varint prefix and the payload it announces. Returns Ok(None) when buf does not yet hold a complete frame (the varint is truncated, or fewer than payload_len payload bytes have arrived).
read_frame
Read one length-prefixed frame from an async reader.
write_frame
Write one length-prefixed frame to an async writer.