pub struct ByteReader<'a> { /* private fields */ }Expand description
A zero-copy big-endian reader confined to one declared byte region.
Implementations§
Source§impl<'a> ByteReader<'a>
impl<'a> ByteReader<'a>
Sourcepub fn new(bytes: &'a [u8], allocation_budget: usize) -> Self
pub fn new(bytes: &'a [u8], allocation_budget: usize) -> Self
Construct a reader whose owned outputs may contain at most allocation_budget bytes/items.
Sourcepub fn allocation_budget(&self) -> usize
pub fn allocation_budget(&self) -> usize
Allocation budget inherited by values decoded from this region.
Sourcepub fn preflight_allocation(&self, amount: usize) -> Result<(), ByteError>
pub fn preflight_allocation(&self, amount: usize) -> Result<(), ByteError>
Reject an allocation before reserving it if its declared size exceeds the budget.
Sourcepub fn read_u2(&mut self) -> Result<u16, ByteError>
pub fn read_u2(&mut self) -> Result<u16, ByteError>
Read an unsigned big-endian two-byte integer.
Sourcepub fn read_u4(&mut self) -> Result<u32, ByteError>
pub fn read_u4(&mut self) -> Result<u32, ByteError>
Read an unsigned big-endian four-byte integer.
Sourcepub fn take(&mut self, length: usize) -> Result<&'a [u8], ByteError>
pub fn take(&mut self, length: usize) -> Result<&'a [u8], ByteError>
Borrow exactly length bytes.
Sourcepub fn sub_reader(&mut self, length: usize) -> Result<ByteReader<'a>, ByteError>
pub fn sub_reader(&mut self, length: usize) -> Result<ByteReader<'a>, ByteError>
Create a child reader bounded to exactly length bytes and advance the parent.
Trait Implementations§
Source§impl<'a> Clone for ByteReader<'a>
impl<'a> Clone for ByteReader<'a>
Source§fn clone(&self) -> ByteReader<'a>
fn clone(&self) -> ByteReader<'a>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for ByteReader<'a>
impl<'a> RefUnwindSafe for ByteReader<'a>
impl<'a> Send for ByteReader<'a>
impl<'a> Sync for ByteReader<'a>
impl<'a> Unpin for ByteReader<'a>
impl<'a> UnsafeUnpin for ByteReader<'a>
impl<'a> UnwindSafe for ByteReader<'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