Skip to main content

FrameReader

Struct FrameReader 

Source
pub struct FrameReader { /* private fields */ }

Implementations§

Source§

impl FrameReader

Source

pub fn new() -> Self

Creates a new FrameReader with an 8 KiB internal buffer.

Source

pub fn read_from<R: Read>( &mut self, reader: &mut R, ) -> Result<Vec<OwnedFrame>, ProtocolError>

Read bytes from reader and return any newly complete frames.

If the internal buffer already holds partial data from a previous call, the reader is drained until the pending frame is complete or EOF. If the buffer is empty, exactly one read is performed and whatever complete frames are present are returned.

Header fields (magic, version, message type, payload length) are validated as soon as a full header is in the buffer — before any payload bytes are accumulated — so a malicious oversized payload_length cannot cause a large allocation.

§Errors
ConditionError kind
Underlying read() returns an I/O errorProtocolErrorKind::InternalError
Magic bytes mismatchProtocolErrorKind::InvalidMagic
Version mismatchProtocolErrorKind::UnsupportedVersion
Unknown msg_type byteProtocolErrorKind::UnknownMessageType
payload_length > MAX_PAYLOAD_SIZEProtocolErrorKind::PayloadTooLarge
§Panics

Never panics. All slice indexing in the extraction loop is guarded by the buffer.len() - offset < HEADER_SIZE check, and the fixed-width try_into() conversions are infallible for the exact slice lengths used.

Trait Implementations§

Source§

impl Default for FrameReader

Source§

fn default() -> Self

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.