pub struct Reader<'a> { /* private fields */ }Expand description
Implementations§
source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
sourcepub fn slice(&mut self, len: usize) -> Result<&'a [u8]>
pub fn slice(&mut self, len: usize) -> Result<&'a [u8]>
Reads a slice of data from the input. No copying is done.
Returns an error if there is not enough data left, in which case the read position is unchanged.
sourcepub fn array<const N: usize>(&mut self) -> Result<[u8; N]>
pub fn array<const N: usize>(&mut self) -> Result<[u8; N]>
Reads a fixed-size slice of data from the input.
Handles errors identically to slice.
sourcepub fn read_into(&mut self, buf: &mut [u8]) -> Result<()>
pub fn read_into(&mut self, buf: &mut [u8]) -> Result<()>
Reads a slice of data into a preexisting buffer.
Handles errors identically to slice.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the total length of the input.
Note that this is the total length, which does not change. See
remaining for the number of bytes left that can be read.
sourcepub fn data(&self) -> &'a [u8] ⓘ
pub fn data(&self) -> &'a [u8] ⓘ
Returns the data being read from.
This is the full slice; for only the remainder, see remaining.
sourcepub fn seek(&mut self, pos: usize) -> Result<()>
pub fn seek(&mut self, pos: usize) -> Result<()>
Sets the read position.
Returns an error if the position is out of bounds.
See at for a version that returns a copy.
sourcepub fn at(&self, pos: usize) -> Result<Self>
pub fn at(&self, pos: usize) -> Result<Self>
Returns a copy of the reader at the specified position.
See also ptrN for a shorthand for the common pattern of
f.clone().at(f.u32()? as usize)?.
source§impl Reader<'_>
impl Reader<'_>
Functions for reading primitives from the stream. The underlying functions are hidden from the docs for brevity.
Supported primitives are u8..=u128, i8..=i128, f32, f64.
The functions are suffixed with either _le or _be, for endianness. To use unsuffixed
versions, import either the Le or Be trait.
sourcepub fn check_T(&mut self, v: T) -> Result<()>
pub fn check_T(&mut self, v: T) -> Result<()>
Read a primitive from the input, giving an error if it is not as expected.
If it not match, the read position is not affected.
sourcepub fn ptrN(&mut self) -> Result<Self>
pub fn ptrN(&mut self) -> Result<Self>
Read a uN primitive from the input, and return a new Reader at that position.
This is a shorthand for the common pattern of f.clone().at(f.uN()? as usize)?.
Note that no checking is made that the value actually fits inside a usize; the higher bits are simply discarded.