Struct WireReader

Source
pub struct WireReader<'a, const E: bool = true> { /* private fields */ }
Expand description

A wrapper around a &[u8] slice that provides an easy interface for reading data types from the slice.

Implementations§

Source§

impl<'a, const E: bool> WireReader<'a, E>

Source

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

Create a WireReader that can read data types sequentially from the bytes slice.

The generic boolean E designates the intended endianness of the data being read. If E is set to true, then the data will be deserialized in big endian format; if false, it will be deserialized in little endian. If unset, this will default to true, or big endian.

Source

pub fn advance(&mut self, amount: usize) -> Result<(), WireError>

Advance the reader’s index forward by the given amount of bytes, returning an error if there are insufficient bytes on the wire to do so.

Source

pub fn advance_up_to(&mut self, amount: usize)

Advance the reader’s index forward by the given number of bytes, or to the end of the wire if the amount exceeds the number of remaining bytes.

Source

pub fn finalize(&self) -> Result<(), WireError>

Check if the reader has no more bytes left on the wire that can be read. If any bytes remain, return WireError::ExtraBytes; otherwise, return Ok().

Source

pub fn finalize_after<T>( action: Result<T, WireError>, reader: &Self, ) -> Result<T, WireError>

Check if the reader has no more bytes left on the wire that can be read after the given action. If any bytes remain, return WireError::ExtraBytes; otherwise, return Ok().

Source

pub fn is_empty(&self) -> bool

Check whether the reader has any remaining bytes to be read.

Source

pub fn peek<T>(&self) -> Result<T, WireError>
where T: WireRead,

Read the given data type T from the wire without advancing the index of the reader.

Source

pub fn peek_comp<T>(&self) -> Result<T, WireError>
where T: WireReadComp<'a>,

Read the given data type T from the wire without advancing the index of the reader.

Source

pub fn peek_part<T, const L: usize>(&mut self) -> Result<T, WireError>
where T: WireReadPart,

Read the given data type T from L bytes on the wire without advancing the index of the reader.

Source

pub fn peek_ref<T>(&mut self, size: usize) -> Result<&'a T, WireError>
where T: WireReadRef + ?Sized,

Read the given data type T from size bytes on the wire without advancing the index of the reader.

Source

pub fn read<T>(&mut self) -> Result<T, WireError>
where T: WireRead,

Read the given data type T from the wire.

Source

pub fn read_comp<T>(&mut self) -> Result<T, WireError>
where T: WireReadComp<'a>,

Read the given data type T from the wire.

Source

pub fn read_part<T, const L: usize>(&mut self) -> Result<T, WireError>
where T: WireReadPart,

Read the given data type T from size bytes on the wire.

Source

pub fn read_ref<T>(&mut self, size: usize) -> Result<&'a T, WireError>
where T: WireReadRef + ?Sized,

Read the given data type T from the wire.

Source

pub fn read_remaining<T>(&mut self) -> Result<&'a T, WireError>
where T: WireReadRef + ?Sized,

Read the given data type T from the remaining data on the wire. Note that this operation may succeed even if there are no bytes remaining on the wire for the given reader.

Trait Implementations§

Source§

impl<'a, const E: bool> Clone for WireReader<'a, E>

Source§

fn clone(&self) -> WireReader<'a, E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl From<WireReader<'_>> for WireIndex

Source§

fn from(reader: WireReader<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'a, const E: bool> From<WireReader<'a, E>> for &'a [u8]

Source§

fn from(value: WireReader<'a, E>) -> Self

Converts to this type from the input type.
Source§

impl<'a, const E: bool> Copy for WireReader<'a, E>

Auto Trait Implementations§

§

impl<'a, const E: bool> Freeze for WireReader<'a, E>

§

impl<'a, const E: bool> RefUnwindSafe for WireReader<'a, E>

§

impl<'a, const E: bool> Send for WireReader<'a, E>

§

impl<'a, const E: bool> Sync for WireReader<'a, E>

§

impl<'a, const E: bool> Unpin for WireReader<'a, E>

§

impl<'a, const E: bool> UnwindSafe for WireReader<'a, E>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.