Skip to main content

FrameDecoder

Struct FrameDecoder 

Source
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: usize

Read position into buf; consumed bytes are reclaimed by compaction, not per-frame drain.

§poisoned: bool

Set 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

Source

pub fn new() -> Self

Source

pub fn push(&mut self, data: &[u8])

Append received bytes to the internal buffer.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for FrameDecoder

Source§

fn default() -> FrameDecoder

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.