pub struct ByteReader<'a> { /* private fields */ }
Expand description
Reads bytes from an underlying byte-slice.
Implementations§
Source§impl<'a> ByteReader<'a>
impl<'a> ByteReader<'a>
Sourcepub fn new(data: &'a [u8]) -> ByteReader<'a>
pub fn new(data: &'a [u8]) -> ByteReader<'a>
Creates a new reader for a slice of bytes.
Sourcepub fn sub_reader(
&mut self,
length: usize,
) -> Result<ByteReader<'a>, ParseError>
pub fn sub_reader( &mut self, length: usize, ) -> Result<ByteReader<'a>, ParseError>
Creates a second reader for a sub-slice of this reader. The slice of the second reader starts at the current
offset
and ends at offset + length
. Also advances this readers offset by length
.
A lot of variable length SOME/IP types are prefixed with their length in bytes, so this allows creating a sub-reader and reading bytes until it is empty.
Sourcepub fn take_remaining(&mut self) -> ByteReader<'a>
pub fn take_remaining(&mut self) -> ByteReader<'a>
Returns a new sub-reader with the remaining slice and advances the reader.
Sourcepub fn read_byte(&mut self) -> Result<u8, ParseError>
pub fn read_byte(&mut self) -> Result<u8, ParseError>
Reads a single byte and advances the reader.
Sourcepub fn read_slice(&mut self, length: usize) -> Result<&'a [u8], ParseError>
pub fn read_slice(&mut self, length: usize) -> Result<&'a [u8], ParseError>
Returns a slice of bytes with the given length and advances the reader.
Sourcepub fn read_array<const N: usize>(&mut self) -> Result<[u8; N], ParseError>
pub fn read_array<const N: usize>(&mut self) -> Result<[u8; N], ParseError>
Reads an array of N
bytes and advances the reader.
Sourcepub fn remaining_slice(&self) -> &'a [u8] ⓘ
pub fn remaining_slice(&self) -> &'a [u8] ⓘ
Returns the remaining slice without advancing the offset.
Sourcepub fn consume_matching_bytes(&mut self, compare_to: &[u8]) -> bool
pub fn consume_matching_bytes(&mut self, compare_to: &[u8]) -> bool
Consumes bytes matching the provided input. Returns whether or not there was a match.
Returns false if are there not enough bytes to compare to.
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>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more