Struct BinaryReader

Source
pub struct BinaryReader<T: Read> { /* private fields */ }
Expand description

Analogous to the System.IO.BinaryReader C# Class.

Reads from any Read implementor.

Implementations§

Source§

impl<T> BinaryReader<T>
where T: Read,

All functions in this implementation return an error if the underlying Read returns an error, or if there aren’t enough bytes to read. Individual functions list additional error conditions.

Source

pub fn new(input: T) -> Self

Creates a new BinaryReader which will read data from the provided Reader.

Source

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

Equivalent to the ReadByte method in C#. Reads one byte from the stream.

Source

pub fn read_bytes( &mut self, num_bytes: usize, ) -> Result<Result<Vec<u8>, DataDecodeError>, Error>

Equivalent to the ReadBytes method in C#. Reads the specified number of bytes.

Source

pub fn peek_byte(&mut self) -> Result<Result<u8, DataDecodeError>, Error>

Doesn’t correspond to any specific c# method. Provided for convenience. Gets the next byte without advancing the data stream.

Source

pub fn peek_bytes( &mut self, num_bytes: usize, ) -> Result<Result<&[u8], DataDecodeError>, Error>

Doesn’t correspond to any specific c# method. Provided for convenience. Gets the specified number of bytes without advancing the data stream.

Source

pub fn read_7_bit_encoded_int( &mut self, ) -> Result<Result<i32, DataDecodeError>, Error>

Equivalent to the Read7BitEncodedInt method in C#. Returns DataDecodeError::IntegerOverflow if the encoded value does not fit within 32 bits.

Source

pub fn read_7_bit_encoded_int64( &mut self, ) -> Result<Result<i64, DataDecodeError>, Error>

Equivalent to the Read7BitEncodedInt64 method in C#. Returns DataDecodeError::IntegerOverflow if the encoded value does not fit within 64 bits.

Source

pub fn read_boolean(&mut self) -> Result<Result<bool, DataDecodeError>, Error>

Equivalent to the ReadBoolean method in C#.

Source

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

Equivalent to the ReadSingle method in C#.

Source

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

Equivalent to the ReadDouble method in C#.

Source

pub fn read_f16(&mut self) -> Result<Result<f16, DataDecodeError>, Error>

Available on crate feature f16 only.

Equivalent to the ReadHalf method in C#. Requires the f16 feature.

Source

pub fn read_string(&mut self) -> Result<Result<String, DataDecodeError>, Error>

Equivalent to the ReadString method in C#. Returns an DataDecodeError::InvalidUtf8 if the data read is not valid utf-8.

Source

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

Equivalent to the ReadSByte method in C#.

Source

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

Equivalent to the ReadInt16 method in C#.

Source

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

Equivalent to the ReadInt32 method in C#.

Source

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

Equivalent to the ReadInt64 method in C#.

Source

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

Equivalent to the ReadUint16 method in C#.

Source

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

Equivalent to the ReadUint32 method in C#.

Source

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

Equivalent to the ReadUint64 method in C#.

Source

pub fn read_char(&mut self) -> Result<Result<char, DataDecodeError>, Error>

Trait Implementations§

Source§

impl<T: Clone + Read> Clone for BinaryReader<T>

Source§

fn clone(&self) -> BinaryReader<T>

Returns a copy 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<T: Debug + Read> Debug for BinaryReader<T>

Source§

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

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

impl<T: Hash + Read> Hash for BinaryReader<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq + Read> PartialEq for BinaryReader<T>

Source§

fn eq(&self, other: &BinaryReader<T>) -> 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<T: Eq + Read> Eq for BinaryReader<T>

Source§

impl<T: Read> StructuralPartialEq for BinaryReader<T>

Auto Trait Implementations§

§

impl<T> Freeze for BinaryReader<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for BinaryReader<T>
where T: RefUnwindSafe,

§

impl<T> Send for BinaryReader<T>
where T: Send,

§

impl<T> Sync for BinaryReader<T>
where T: Sync,

§

impl<T> Unpin for BinaryReader<T>
where T: Unpin,

§

impl<T> UnwindSafe for BinaryReader<T>
where T: UnwindSafe,

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.