Skip to main content

Module framing

Module framing 

Source
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:

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.
StreamDecoder
Stateful wrapper that drives a Framer over a growing input buffer.

Traits§

Framer
Strategy that extracts and emits one frame at a time.