pub struct LineDecoder { /* private fields */ }Expand description
Incremental newline framer.
Accumulates pushed bytes and yields complete lines split on \n, stripping
a single trailing \r from each (so both \n and \r\n framing work). A
partial final line with no terminating \n stays buffered across pushes
until either a later push completes it or flush is
called.
This is the framing half of sim-lib-agent-runner-http’s old per-decoder
line_buffer loop, lifted into one shared, tested type.
Implementations§
Source§impl LineDecoder
impl LineDecoder
Sourcepub fn push(&mut self, bytes: &[u8]) -> Vec<Vec<u8>>
pub fn push(&mut self, bytes: &[u8]) -> Vec<Vec<u8>>
Append bytes and return every line completed by a \n. The trailing
\r of a \r\n pair is stripped. Bytes after the last \n remain
buffered.
Sourcepub fn flush(&mut self) -> Option<Vec<u8>>
pub fn flush(&mut self) -> Option<Vec<u8>>
Take any buffered remainder (an unterminated final line). Returns None
when nothing is buffered. A single trailing \r is stripped to match
push.
Sourcepub fn buffered_len(&self) -> usize
pub fn buffered_len(&self) -> usize
Number of bytes currently buffered as a partial line.
Sourcepub fn buffered(&self) -> &[u8] ⓘ
pub fn buffered(&self) -> &[u8] ⓘ
Borrow the bytes currently buffered as a partial (unterminated) line.
Sourcepub fn has_buffered(&self) -> bool
pub fn has_buffered(&self) -> bool
Whether any partial line is currently buffered.