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>
impl<'a, const E: bool> WireReader<'a, E>
Sourcepub fn new(bytes: &'a [u8]) -> Self
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.
Sourcepub fn advance(&mut self, amount: usize) -> Result<(), WireError>
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.
Sourcepub fn advance_up_to(&mut self, amount: usize)
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.
Sourcepub fn finalize(&self) -> Result<(), WireError>
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().
Sourcepub fn finalize_after<T>(
action: Result<T, WireError>,
reader: &Self,
) -> Result<T, WireError>
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().
Sourcepub fn peek<T>(&self) -> Result<T, WireError>where
T: WireRead,
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.
Sourcepub fn peek_comp<T>(&self) -> Result<T, WireError>where
T: WireReadComp<'a>,
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.
Sourcepub fn peek_part<T, const L: usize>(&mut self) -> Result<T, WireError>where
T: WireReadPart,
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.
Sourcepub fn peek_ref<T>(&mut self, size: usize) -> Result<&'a T, WireError>where
T: WireReadRef + ?Sized,
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.
Sourcepub fn read<T>(&mut self) -> Result<T, WireError>where
T: WireRead,
pub fn read<T>(&mut self) -> Result<T, WireError>where
T: WireRead,
Read the given data type T
from the wire.
Sourcepub fn read_comp<T>(&mut self) -> Result<T, WireError>where
T: WireReadComp<'a>,
pub fn read_comp<T>(&mut self) -> Result<T, WireError>where
T: WireReadComp<'a>,
Read the given data type T
from the wire.
Sourcepub fn read_part<T, const L: usize>(&mut self) -> Result<T, WireError>where
T: WireReadPart,
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.
Sourcepub fn read_ref<T>(&mut self, size: usize) -> Result<&'a T, WireError>where
T: WireReadRef + ?Sized,
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.
Sourcepub fn read_remaining<T>(&mut self) -> Result<&'a T, WireError>where
T: WireReadRef + ?Sized,
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>
impl<'a, const E: bool> Clone for WireReader<'a, E>
Source§fn clone(&self) -> WireReader<'a, E>
fn clone(&self) -> WireReader<'a, E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more