Skip to main content

ByteReader

Struct ByteReader 

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

Interface to safely read plain data which implements FromBytes from a u8 slice

Implementations§

Source§

impl<'a> ByteReader<'a>

Source

pub fn new(bytes: &'a [u8]) -> Self

Creates a new ByteReader over the specified bytes.

Source

pub fn new_with_rel(bytes: &'a [u8], pos: usize) -> Self

Creates a new relative ByteReader over the specified bytes.

All operations including RVA’s will be relative to the specified position.

Source

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

Returns a reference to the bytes of this ByteReader.

Source

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

Returns a reference to the remaining bytes of this ByteReader.

Source

pub fn bytes_at(&self, pos: usize) -> Result<&'a [u8]>

Returns a reference to the bytes of this ByteReader, starting at the specified position

§Errors

This function will return Error::InsufficientBuffer if the specified position is outside of the buffers bounds.

Source

pub fn rel_pos(&self) -> Option<usize>

Returns the relative position set by ByteReader::new_with_rel of this ByteReader.

Source

pub fn pos_to_rel(&self, pos: usize) -> usize

Converts the specified RVA to a position within the buffer

Source

pub fn skip_to(&mut self, pos: Pos) -> &mut Self

Advances the internal data buffer to the specified position

Source

pub fn read<T>(&mut self) -> Result<&'a T>
where T: FromBytes,

Reads a plain data structure implementing FromBytes from the current position

§Errors

This function will return an error if the current position is invalid or the bytes at the current position do not have the right memory layout for the requested structure

Source

pub fn read_at<T>(&self, pos: usize) -> Result<&'a T>
where T: FromBytes,

Reads a plain data structure implementing FromBytes from the specified position

§Errors

This function will return an error if the specified position is invalid or the bytes at the current position do not have the right memory layout for the requested structure

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> UnsafeUnpin 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> 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, 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.