pub struct WireCursor<'a> { /* private fields */ }
Expand description
A cursor that acts as an index over a contiguous immutable slice and provides operations to sequentially read data from it.
When implementing the WireRead
trait or one of its variants, this cursor provides an
interface for reading data from the wire. When an error is returned by the cursor, it
should be returned by the trait method being implemented. This can be easily accomplished
using the ?
operator.
NOTE: this is an internal structure, and is NOT meant to be used to read data from a wire
in the same manner as a WireReader
. A WireReader
is guaranteed to maintain the index
of its last succesful read if any of its methods return an error, while this cursor may move
its internal index forward by some unspecified amount when an error is encountered.
Implementations§
Source§impl<'a> WireCursor<'a>
impl<'a> WireCursor<'a>
Sourcepub fn advance(&mut self, amount: usize) -> Result<(), WireError>
pub fn advance(&mut self, amount: usize) -> Result<(), WireError>
Advance the cursor’s index by the given amount, returning an error if there are insufficient bytes on the wire.
Sourcepub fn advance_up_to(&mut self, amount: usize)
pub fn advance_up_to(&mut self, amount: usize)
Advance the cursor’s index by the given amount, or to the end of the wire if the amount exceeds the number of remaining bytes.
Sourcepub fn get_array<const L: usize>(&mut self) -> Result<&'a [u8; L], WireError>
pub fn get_array<const L: usize>(&mut self) -> Result<&'a [u8; L], WireError>
Retrieve a reference to an array of bytes of size L
from the wire.
Sourcepub fn get_readable<T, const E: bool>(&mut self) -> Result<T, WireError>where
T: WireRead,
pub fn get_readable<T, const E: bool>(&mut self) -> Result<T, WireError>where
T: WireRead,
Deserialize a given type T
that implements the WireRead
trait from the wire, and
return an owned instance of it.
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.
Sourcepub fn get_readable_part<T, const L: usize, const E: bool>(
&mut self,
) -> Result<T, WireError>where
T: WireReadPart,
pub fn get_readable_part<T, const L: usize, const E: bool>(
&mut self,
) -> Result<T, WireError>where
T: WireReadPart,
Deserialize L
bytes from the wire into a given type T
that implements the WireReadPart
trait, and return an owned instance of it.
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.
Sourcepub fn get_readable_ref<T, const E: bool>(
&mut self,
length: usize,
) -> Result<&'a T, WireError>where
T: WireReadRef + ?Sized,
pub fn get_readable_ref<T, const E: bool>(
&mut self,
length: usize,
) -> Result<&'a T, WireError>where
T: WireReadRef + ?Sized,
Deserialize a given type T
that implements the WireReadRef
trait from the wire, and return a
reference to it.
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.
Sourcepub fn get_readable_comp<T, const E: bool>(&mut self) -> Result<T, WireError>where
T: WireReadComp<'a> + ?Sized,
pub fn get_readable_comp<T, const E: bool>(&mut self) -> Result<T, WireError>where
T: WireReadComp<'a> + ?Sized,
Deserialize a given type T
that implements the WireReadComp
trait from the wire, and return
an owned instance of it.
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.
Sourcepub fn get_slice(&mut self, amount: usize) -> Result<&'a [u8], WireError>
pub fn get_slice(&mut self, amount: usize) -> Result<&'a [u8], WireError>
Retrieve a slice of bytes from the wire.
Trait Implementations§
Source§impl<'a> Clone for WireCursor<'a>
impl<'a> Clone for WireCursor<'a>
Source§fn clone(&self) -> WireCursor<'a>
fn clone(&self) -> WireCursor<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more