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>
impl<'a> WireCursor<'a>
pub fn new(bytes: &'a [u8]) -> Self
pub fn is_empty(&self) -> bool
Sourcepub fn read_u8(&mut self) -> Result<u8, WireError>
pub fn read_u8(&mut self) -> Result<u8, WireError>
Read one byte, or return UnexpectedEof without advancing.
Sourcepub fn read_u32(&mut self) -> Result<u32, WireError>
pub fn read_u32(&mut self) -> Result<u32, WireError>
Read four bytes as a little-endian u32, or return UnexpectedEof without advancing.
Sourcepub fn read_u64(&mut self) -> Result<u64, WireError>
pub fn read_u64(&mut self) -> Result<u64, WireError>
Read eight bytes as a little-endian u64, or return UnexpectedEof without advancing.
Sourcepub fn read_len(&mut self) -> Result<usize, WireError>
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.
Sourcepub fn read_exact(&mut self, len: usize) -> Result<&'a [u8], WireError>
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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
Source§fn type_id(&self) -> TypeId
fn type_id(&self) -> TypeId
TypeId of self. Read moreSource§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
Source§fn borrow(&self) -> &T
fn borrow(&self) -> &T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere
U: From<T>,
Source§fn into(self) -> U
fn into(self) -> U
Calls U::from(self).
That is, this conversion is whatever the implementation of
From<T> for U chooses to do.