pub struct FrameDecoder {
buf: Vec<u8>,
pos: usize,
poisoned: bool,
}Expand description
Incremental decoder: feed arbitrary chunks via push, pull complete frame
bodies via next_frame. Tolerant of frames split across chunk boundaries.
Fields§
§buf: Vec<u8>§pos: usizeRead position into buf; consumed bytes are reclaimed by compaction, not per-frame drain.
poisoned: boolSet once an oversize length is seen. The stream is then unrecoverable, so every
later next_frame returns Poisoned instead of re-reading the same bad header
forever (the panel-found infinite-error-loop bug).
Implementations§
Source§impl FrameDecoder
impl FrameDecoder
pub fn new() -> Self
Sourcepub fn next_frame(&mut self) -> Result<Option<Vec<u8>>, FrameError>
pub fn next_frame(&mut self) -> Result<Option<Vec<u8>>, FrameError>
Pull the next complete frame body if one is fully buffered.
Ok(None) = need more bytes. Err(TooLarge) on the first oversize length,
Err(Poisoned) on every call thereafter — the caller must drop the connection.
Sourcefn maybe_compact(&mut self)
fn maybe_compact(&mut self)
Drop already-consumed bytes once they exceed half the buffer, so long-running streams do
not grow buf unbounded and no per-frame O(n) drain is paid.