Skip to main content

Module framing

Module framing 

Source
Expand description

Length-prefixed framing for the binary (CBOR) protocol.

Port of the upstream packages/protocol/ module. 4-byte big-endian unsigned payload length followed by the payload bytes. FrameDecoder incrementally splits arbitrary byte chunks into complete payloads and enforces a maximum frame length so a corrupt/hostile stream cannot make the peer allocate unbounded memory.

Structs§

FrameDecoder
Incremental decoder: feed byte chunks, get whole payloads back.
FrameError
Framing error.

Constants§

DEFAULT_MAX_FRAME_LENGTH
Native DEFAULT_MAX_FRAME_LENGTH (16 MiB).
FRAME_HEADER_LENGTH
Native FRAME_HEADER_LENGTH.
PAYLOAD_BLOCK_SIZE
Native PAYLOAD_BLOCK_SIZE.

Functions§

assert_complete_frame
Validate that frame contains exactly one complete frame within max.
encode_frame
Prefix payload with its 4-byte big-endian length.