pub struct FrameDecoder { /* private fields */ }Expand description
Streaming Lumberjack v2 frame decoder.
Accepts arbitrary slices of bytes via FrameDecoder::feed and emits
fully decoded Frame values via FrameDecoder::next_frame. The
internal buffer grows on demand and is compacted when consumed bytes
pass a threshold so long-lived decoders do not accumulate unbounded
dead capacity.
The decoder is not zero-copy: each Frame variant owns its
payload bytes. This is deliberate — yielded frames are typically
JSON-decoded immediately and the original bytes are dropped.
§Resource bounding
Both raw payload lengths (J, C frames) and decompressed
inner sizes (C frame contents) are capped by
FrameDecoder::with_max_frame_payload. The default
is crate::DEFAULT_MAX_FRAME_PAYLOAD (64 MiB). This protects
servers reading from untrusted peers from naive resource-exhaustion
attacks (huge declared lengths, zlib bombs).
Implementations§
Source§impl FrameDecoder
impl FrameDecoder
Sourcepub const fn with_max_frame_payload(max_frame_payload: usize) -> Self
pub const fn with_max_frame_payload(max_frame_payload: usize) -> Self
Create a decoder with a custom per-frame size cap.
Applies to both raw payload lengths and decompressed inner
content of C frames. Set to usize::MAX for “no cap” (not
recommended on inputs from untrusted peers).
Sourcepub fn feed(&mut self, bytes: &[u8])
pub fn feed(&mut self, bytes: &[u8])
Append bytes to the internal buffer. The bytes will be parsed on
subsequent calls to Self::next_frame.
Sourcepub const fn pending(&self) -> usize
pub const fn pending(&self) -> usize
How many fed bytes remain unconsumed in the internal buffer.
Sourcepub fn next_frame(&mut self) -> Result<Option<Frame>, FrameError>
pub fn next_frame(&mut self) -> Result<Option<Frame>, FrameError>
Try to decode one frame from the buffered bytes.
Returns:
Ok(Some(frame))— a complete frame is available.Ok(None)— not enough bytes yet; feed more.Err(_)— malformed input; the buffer is left untouched at the offending position so the caller may inspect it. To continue parsing, callers typically tear down the connection.