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::bounded caps payloads at
LengthPrefixed::DEFAULT_MAX_PAYLOAD (8 MiB) and
LengthPrefixed::bounded_to at a limit you choose: use one of them for
input from untrusted peers. LengthPrefixed::unbounded sets the limit to
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. LengthPrefixed::new keeps the 1.0 unbounded behaviour, is
deprecated since 1.2.0, and becomes bounded in 2.0.
Structs§
- Length
Prefixed - Length-prefixed framer.
Enums§
- Endian
- Byte order for the length prefix.
- Length
Width - Width of the length prefix, in bytes.