Struct FixedLengthReader

Source
pub struct FixedLengthReader<'a, R: Read> { /* private fields */ }
Expand description

Essentially std::io::Take but a bit simpler and with a method to walk the underlying stream forward to ensure we always consume exactly the fixed length specified.

This is not exported to bindings users as manual TLV building is not currently supported in bindings

Implementations§

Source§

impl<'a, R: Read> FixedLengthReader<'a, R>

Source

pub fn new(read: &'a mut R, total_bytes: u64) -> Self

Returns a new FixedLengthReader.

Source

pub fn bytes_remain(&mut self) -> bool

Returns whether some bytes are remaining or not.

Source

pub fn eat_remaining(&mut self) -> Result<(), DecodeError>

Consumes the remaining bytes.

Trait Implementations§

Source§

impl<'a, R: Read> Read for FixedLengthReader<'a, R>

Source§

fn read(&mut self, dest: &mut [u8]) -> Result<usize, Error>

Reads bytes from source into buf.
Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads bytes from source until buf is full.
Source§

fn take(&mut self, limit: u64) -> Take<'_, Self>

Creates an adapter which will read at most limit bytes.
Source§

fn read_to_limit( &mut self, buf: &mut Vec<u8>, limit: u64, ) -> Result<usize, Error>

Attempts to read up to limit bytes from the reader, allocating space in buf as needed. Read more

Auto Trait Implementations§

§

impl<'a, R> Freeze for FixedLengthReader<'a, R>

§

impl<'a, R> RefUnwindSafe for FixedLengthReader<'a, R>
where R: RefUnwindSafe,

§

impl<'a, R> Send for FixedLengthReader<'a, R>
where R: Send,

§

impl<'a, R> Sync for FixedLengthReader<'a, R>
where R: Sync,

§

impl<'a, R> Unpin for FixedLengthReader<'a, R>

§

impl<'a, R> !UnwindSafe for FixedLengthReader<'a, R>

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<R> ReadExt for R
where R: Read + ?Sized,

Source§

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

Reads a 64-bit unsigned integer.
Source§

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

Reads a 32-bit unsigned integer.
Source§

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

Reads a 16-bit unsigned integer.
Source§

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

Reads a 64-bit signed integer.
Source§

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

Reads a 32-bit signed integer.
Source§

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

Reads a 16-bit signed integer.
Source§

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

Reads an 8-bit unsigned integer.
Source§

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

Reads an 8-bit signed integer.
Source§

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

Reads a boolean.
Source§

fn read_slice(&mut self, slice: &mut [u8]) -> Result<(), Error>

Reads a byte slice.
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