pub struct Reader<'a> { /* private fields */ }Expand description
Reader for decoding binary data.
Wraps a byte slice and provides methods for reading primitives with bounds checking and error handling.
Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub fn remaining_len(&self) -> usize
pub fn remaining_len(&self) -> usize
Returns the number of remaining bytes.
Sourcepub fn read_byte(&mut self, context: &'static str) -> Result<u8, DecodeError>
pub fn read_byte(&mut self, context: &'static str) -> Result<u8, DecodeError>
Reads a single byte.
Sourcepub fn read_bytes(
&mut self,
n: usize,
context: &'static str,
) -> Result<&'a [u8], DecodeError>
pub fn read_bytes( &mut self, n: usize, context: &'static str, ) -> Result<&'a [u8], DecodeError>
Reads exactly n bytes.
Sourcepub fn read_id(&mut self, context: &'static str) -> Result<Id, DecodeError>
pub fn read_id(&mut self, context: &'static str) -> Result<Id, DecodeError>
Reads a 16-byte UUID.
Sourcepub fn read_varint(&mut self, context: &'static str) -> Result<u64, DecodeError>
pub fn read_varint(&mut self, context: &'static str) -> Result<u64, DecodeError>
Reads an unsigned varint (LEB128).
Sourcepub fn read_signed_varint(
&mut self,
context: &'static str,
) -> Result<i64, DecodeError>
pub fn read_signed_varint( &mut self, context: &'static str, ) -> Result<i64, DecodeError>
Reads a signed varint (zigzag encoded).
Sourcepub fn read_string(
&mut self,
max_len: usize,
field: &'static str,
) -> Result<String, DecodeError>
pub fn read_string( &mut self, max_len: usize, field: &'static str, ) -> Result<String, DecodeError>
Reads a length-prefixed UTF-8 string (allocates).
Sourcepub fn read_str(
&mut self,
max_len: usize,
field: &'static str,
) -> Result<&'a str, DecodeError>
pub fn read_str( &mut self, max_len: usize, field: &'static str, ) -> Result<&'a str, DecodeError>
Reads a length-prefixed UTF-8 string as a borrowed slice (zero-copy).
Sourcepub fn read_bytes_prefixed(
&mut self,
max_len: usize,
field: &'static str,
) -> Result<Vec<u8>, DecodeError>
pub fn read_bytes_prefixed( &mut self, max_len: usize, field: &'static str, ) -> Result<Vec<u8>, DecodeError>
Reads a length-prefixed byte array.
Sourcepub fn read_f64(&mut self, context: &'static str) -> Result<f64, DecodeError>
pub fn read_f64(&mut self, context: &'static str) -> Result<f64, DecodeError>
Reads a little-endian f64.
Sourcepub fn read_f64_unchecked(
&mut self,
context: &'static str,
) -> Result<f64, DecodeError>
pub fn read_f64_unchecked( &mut self, context: &'static str, ) -> Result<f64, DecodeError>
Reads a little-endian f64 without NaN check.
Sourcepub fn read_id_vec(
&mut self,
max_len: usize,
field: &'static str,
) -> Result<Vec<Id>, DecodeError>
pub fn read_id_vec( &mut self, max_len: usize, field: &'static str, ) -> Result<Vec<Id>, DecodeError>
Reads a vector of IDs with length prefix.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Reader<'a>
impl<'a> RefUnwindSafe for Reader<'a>
impl<'a> Send for Reader<'a>
impl<'a> Sync for Reader<'a>
impl<'a> Unpin for Reader<'a>
impl<'a> UnwindSafe for Reader<'a>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more