Skip to main content

LineDecoder

Struct LineDecoder 

Source
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

Source

pub fn new() -> Self

Create an empty decoder.

Source

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.

Source

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.

Source

pub fn buffered_len(&self) -> usize

Number of bytes currently buffered as a partial line.

Source

pub fn buffered(&self) -> &[u8]

Borrow the bytes currently buffered as a partial (unterminated) line.

Source

pub fn has_buffered(&self) -> bool

Whether any partial line is currently buffered.

Trait Implementations§

Source§

impl Debug for LineDecoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LineDecoder

Source§

fn default() -> LineDecoder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.