Skip to main content

Module codec

Module codec 

Expand description

Length-prefixed CBOR framing for the v1 control channel.

Each frame on the wire is:

[u32 length, big-endian] [CBOR body of length bytes]

The length counts only the CBOR body, not the 4-byte prefix. The maximum body size is a per-call parameter, not part of the wire format, so peers enforce a negotiated limit (default crate::v1::limits::DEFAULT_MAX_FRAME_LEN).

Forward compatibility rides on the length prefix. #[serde(other)] absorbs an unknown unit variant, but cannot fold an unknown data-carrying message into a unit catch-all; for those, decode_frames drops the whole (length-delimited) frame and counts the skip, so an unknown message never crashes the stream. A length prefix over the enforced limit is the one unrecoverable case: the boundary can no longer be trusted, so decoding fails hard and the caller tears the connection down.

Structs§

DecodedFrames
Result of decoding a buffer that may hold several frames.
LimitedWriter 🔒
A Write sink that buffers at most limit bytes.

Enums§

FramingError
Error produced while encoding or decoding length-prefixed CBOR frames.

Constants§

LENGTH_PREFIX_LEN 🔒
Number of bytes in a frame’s big-endian u32 length prefix.

Functions§

decode_frames
Decode every complete frame in buffer, consuming it.
encode_frame
Encode a message into a single length-prefixed CBOR frame.