Struct BinaryReader

Source
pub struct BinaryReader {
    pub data: Vec<u8>,
    pub pos: usize,
    pub length: usize,
    pub endian: Endian,
}
Expand description

Binary reader.

Fields§

§data: Vec<u8>

The buffer data.

§pos: usize

The current position.

§length: usize

The length of the buffer.

§endian: Endian

The endian of the buffer.

Implementations§

Source§

impl BinaryReader

Source

pub fn from_u8(get: &[u8]) -> BinaryReader

Initialize BinaryReader from u8 slice.

Source

pub fn from_vec(vec: &Vec<u8>) -> BinaryReader

Initialize BinaryReader from u8 Vector.

Source

pub fn from_file(file: &mut File) -> BinaryReader

Initialize BinaryReader from std::fs::File.

Source

pub fn set_endian(&mut self, endian: Endian)

Set endian for read method.

Source

pub fn jmp(&mut self, pos: usize)

Jump position.

Source

pub fn adv(&mut self, size: usize)

Source

pub fn align(&mut self, size: usize)

Source

pub fn read(&mut self, size: usize) -> Option<&[u8]>

Read provided length size bytes.

Source

pub fn read_bytes(&mut self, bytes: usize) -> Result<&[u8]>

Read provided length size bytes. Similar to BinaryReader::read but this returns std::io::Result instead of Option.

Source

pub fn read_cstr(&mut self) -> Result<String>

Read cstr strings until null(aka 0x00) using std::string::String::from_utf8.

Source

pub fn read_cstr_lossy(&mut self) -> Result<String>

Read cstr strings until null(aka 0x00) using std::string::String::from_utf8_lossy.

Source

pub fn read_bool(&mut self) -> Result<bool>

Read boolean. Note that anything other than 0x00 is considered true.

Source

pub fn read_i8(&mut self) -> Result<i8>

Read signed 8 bit integer.

Source

pub fn read_i16(&mut self) -> Result<i16>

Read signed 16 bit integer.

Source

pub fn read_i24(&mut self) -> Result<i32>

Read signed 24 bit integer. Stored in i32.

Source

pub fn read_i32(&mut self) -> Result<i32>

Read signed 32 bit integer.

Source

pub fn read_i48(&mut self) -> Result<i64>

Read signed 48 bit integer. Stored in i64.

Source

pub fn read_i64(&mut self) -> Result<i64>

Read signed 64 bit integer.

Source

pub fn read_i128(&mut self) -> Result<i128>

Read signed 128 bit integer.

Source

pub fn read_u8(&mut self) -> Result<u8>

Read unsigned 8 bit integer.

Source

pub fn read_u16(&mut self) -> Result<u16>

Read unsigned 16 bit integer.

Source

pub fn read_u24(&mut self) -> Result<u32>

Read unsigned 24 bit integer. Stored in u32.

Source

pub fn read_u32(&mut self) -> Result<u32>

Read unsigned 32 bit integer.

Source

pub fn read_u48(&mut self) -> Result<u64>

Read unsigned 48 bit integer. Stored in u64.

Source

pub fn read_u64(&mut self) -> Result<u64>

Read unsigned 64 bit integer.

Source

pub fn read_u128(&mut self) -> Result<u128>

Read unsigned 128 bit integer.

Source

pub fn read_f32(&mut self) -> Result<f32>

Read 32 bit floating point number.

Source

pub fn read_f64(&mut self) -> Result<f64>

Read 64 bit floating point number.

Trait Implementations§

Source§

impl Clone for BinaryReader

Source§

fn clone(&self) -> BinaryReader

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 Debug for BinaryReader

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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