Expand description
Frame extraction strategies.
A Framer is a stateless protocol that locates and emits one frame at a
time from a borrowed byte slice. Frames are described by Frame, which
carries a zero-copy reference to the payload alongside the count of bytes
the framer consumed from the input.
Concrete framers shipped with the crate:
length::LengthPrefixedfor fixed-width length-prefixed protocols (1, 2, 3, 4, or 8 byte prefixes, either byte order, optional length adjustment).varint_prefixed::VarintPrefixedfor LEB128 length-prefixed messages, the “length-delimited” framing used by Protocol Buffers and gRPC-style transports.delimiter::Delimitedfor byte-delimited protocols such as newline- terminated text.checksummed::Checksummed, a decorator that appends and verifies a CRC (or anyChecksum) after the frames of any other framer.
Custom framers are implemented by writing a Framer impl on a user-defined
type.
§Untrusted input
A framer only guards memory if it has a limit. Use the bounded
constructors (LengthPrefixed::bounded, Delimited::bounded) or
with_max_payload for any stream that comes from a peer you do not
control. VarintPrefixed::new is bounded by default.
When bytes arrive in pieces, drive the framer through a StreamDecoder
(or Framer::next_frame_from) so that a delimiter search resumes where
the previous call stopped instead of rescanning the whole buffer. That
keeps the total work linear in the input size even when a peer drips one
byte at a time.
Re-exports§
pub use checksummed::ChecksumScope;pub use checksummed::Checksummed;pub use delimiter::Delimited;pub use length::Endian;pub use length::LengthPrefixed;pub use length::LengthWidth;pub use varint_prefixed::VarintPrefixed;
Modules§
- checksummed
- Checksum-trailer framing.
- delimiter
- Byte-delimited framing.
- length
- Length-prefixed framing.
- varint_
prefixed - Varint length-prefixed framing.
Structs§
- Frame
- A frame extracted from an input byte slice.
- Stream
Decoder - Stateful wrapper that drives a
Framerover a growing input buffer.
Traits§
- Framer
- Strategy that extracts and emits one frame at a time.