Skip to main content

WireCursor

Struct WireCursor 

Source
pub struct WireCursor<'a> { /* private fields */ }
Expand description

Borrowed, bounds-checked reader for canonical wire primitives.

Integers are little-endian; lengths occupy an unsigned 32-bit field. These widths, byte order and documented consumption/error semantics are public compatibility commitments. Storage and bounds-checking internals remain private; custom payload schemas define their own interpretation. Failed byte reads leave the cursor unchanged. Conversion failures in Self::read_len consume the length field.

Implementations§

Source§

impl<'a> WireCursor<'a>

Source

pub fn new(bytes: &'a [u8]) -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn read_u8(&mut self) -> Result<u8, WireError>

Read one byte, or return UnexpectedEof without advancing.

Source

pub fn read_u32(&mut self) -> Result<u32, WireError>

Read four bytes as a little-endian u32, or return UnexpectedEof without advancing.

Source

pub fn read_u64(&mut self) -> Result<u64, WireError>

Read eight bytes as a little-endian u64, or return UnexpectedEof without advancing.

Source

pub fn read_len(&mut self) -> Result<usize, WireError>

Read a little-endian u32 length and convert it to usize. Returns UnexpectedEof without advancing for a truncated field. If the value cannot fit usize, consumes four bytes and returns LengthOverflow.

Source

pub fn read_exact(&mut self, len: usize) -> Result<&'a [u8], WireError>

Borrow and consume exactly len bytes, including zero bytes. Returns LengthOverflow if offset + len overflows, otherwise UnexpectedEof if the range exceeds the input. Both leave the cursor unchanged. This operation never allocates or panics for any length.

Auto Trait Implementations§

§

impl<'a> Freeze for WireCursor<'a>

§

impl<'a> RefUnwindSafe for WireCursor<'a>

§

impl<'a> Send for WireCursor<'a>

§

impl<'a> Sync for WireCursor<'a>

§

impl<'a> Unpin for WireCursor<'a>

§

impl<'a> UnsafeUnpin for WireCursor<'a>

§

impl<'a> UnwindSafe for WireCursor<'a>

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.