Skip to main content

Module length

Module length 

Source
Expand description

Length-prefixed framing.

Each frame is preceded by a fixed-width unsigned integer that gives the length of the payload in bytes. The width and endianness are chosen at construction time. An optional length adjustment covers protocols whose length field counts something other than exactly the payload (for example “length includes the header”).

§Limits

LengthPrefixed::new keeps the 1.0 behaviour: the payload limit is the largest value the prefix can encode (4 GiB for LengthWidth::U32). A caller that buffers until a frame is complete would buffer that much for a hostile peer. For untrusted input, use LengthPrefixed::bounded (a LengthPrefixed::DEFAULT_MAX_PAYLOAD cap) or LengthPrefixed::with_max_payload.

Structs§

LengthPrefixed
Length-prefixed framer.

Enums§

Endian
Byte order for the length prefix.
LengthWidth
Width of the length prefix, in bytes.