pub struct ByteReader<'a> { /* private fields */ }Expand description
Reader over bytes, tracking a cursor and the payload name used in errors.
Implementations§
Source§impl<'a> ByteReader<'a>
impl<'a> ByteReader<'a>
Sourcepub fn new(bytes: &'a [u8], label: &'static str) -> Self
pub fn new(bytes: &'a [u8], label: &'static str) -> Self
A reader positioned at the start of bytes. label names the payload
kind in every error this reader produces.
Sourcepub fn open_payload(
bytes: &'a [u8],
magic: u32,
header_bytes: usize,
label: &'static str,
) -> Result<Self, String>
pub fn open_payload( bytes: &'a [u8], magic: u32, header_bytes: usize, label: &'static str, ) -> Result<Self, String>
Open a tagged payload: prove it is long enough to hold a header_bytes
header and that it opens with magic, then position the reader just
past the magic. Lets a decoder report a short buffer once rather than
once per header field.
Sourcepub fn take(&mut self, n: usize) -> Result<&'a [u8], String>
pub fn take(&mut self, n: usize) -> Result<&'a [u8], String>
Consume n bytes and return them, or report where the buffer ran out.
Sourcepub fn array<const N: usize>(&mut self) -> Result<[u8; N], String>
pub fn array<const N: usize>(&mut self) -> Result<[u8; N], String>
Consume exactly N bytes as an owned array, ready for from_le_bytes.
Sourcepub fn skip(&mut self, n: usize) -> Result<(), String>
pub fn skip(&mut self, n: usize) -> Result<(), String>
Advance past n bytes without returning them.
Sourcepub fn seek(&mut self, pos: usize) -> Result<(), String>
pub fn seek(&mut self, pos: usize) -> Result<(), String>
Move the cursor to an absolute offset, which must lie within the buffer.
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