pub struct FrameDecoder { /* private fields */ }Expand description
An owning frame buffer: push received bytes in, take complete frames out.
Built on split_frame_limited. Frames come out as raw payloads, so
a caller can route them as it likes: handshake frames to the
handshake, reply frames to whatever classifies them afterwards.
Consumed bytes are reclaimed lazily: next only
advances a cursor, and a later push moves the
unconsumed tail to the front before appending once the consumed prefix
is at least as large as that tail. Draining a burst of frames then
costs at most one move of the leftover partial frame, and a caller that
interleaves pushes with single next calls still pays amortised
constant work per byte.
§After an error
Once next has reported FrameTooLarge the decoder is
poisoned: the stream has no trustworthy frame boundary left. Every
later next returns the same error, and push discards its input
rather than buffer bytes that can never be framed. Drop the connection
and the decoder with it.
Implementations§
Source§impl FrameDecoder
impl FrameDecoder
Sourcepub fn new() -> Self
pub fn new() -> Self
A decoder enforcing the protocol’s MAX_FRAME_SIZE.
Sourcepub fn with_max_payload(max_payload: usize) -> Self
pub fn with_max_payload(max_payload: usize) -> Self
A decoder refusing any frame whose payload exceeds max_payload.
Preallocates room for one maximal frame (capped at one
MAX_FRAME_SIZE frame, so a generous limit does not reserve
memory up front), sparing the first pushes a reallocation.
Sourcepub fn max_payload(&self) -> usize
pub fn max_payload(&self) -> usize
The payload limit this decoder enforces.
Sourcepub fn is_poisoned(&self) -> bool
pub fn is_poisoned(&self) -> bool
Whether a FrameTooLarge has poisoned the decoder.
Sourcepub fn pending(&self) -> &[u8] ⓘ
pub fn pending(&self) -> &[u8] ⓘ
Bytes received but not yet returned as a frame: a partial frame,
or complete frames still waiting for next.