Struct ByteReader

Source
pub struct ByteReader<'a> { /* private fields */ }
Expand description

Reads bytes from an underlying byte-slice.

Implementations§

Source§

impl<'a> ByteReader<'a>

Source

pub fn new(data: &'a [u8]) -> ByteReader<'a>

Creates a new reader for a slice of bytes.

Source

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.

Source

pub fn take_remaining(&mut self) -> ByteReader<'a>

Returns a new sub-reader with the remaining slice and advances the reader.

Source

pub fn read_byte(&mut self) -> Result<u8, ParseError>

Reads a single byte and advances the reader.

Source

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.

Source

pub fn read_array<const N: usize>(&mut self) -> Result<[u8; N], ParseError>

Reads an array of N bytes and advances the reader.

Source

pub fn remaining_slice(&self) -> &'a [u8]

Returns the remaining slice without advancing the offset.

Source

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.

Source

pub fn len(&self) -> usize

Returns the length of the remaining slice.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no bytes left to read.

Trait Implementations§

Source§

impl<'a> Clone for ByteReader<'a>

Source§

fn clone(&self) -> ByteReader<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ByteReader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for ByteReader<'a>

Source§

fn eq(&self, other: &ByteReader<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for ByteReader<'a>

Source§

impl<'a> StructuralPartialEq for ByteReader<'a>

Auto 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> UnwindSafe for ByteReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V