ReadBuffer

Struct ReadBuffer 

Source
pub struct ReadBuffer<BS: ArraySize> { /* private fields */ }
Expand description

Buffer for reading block-generated data.

Implementations§

Source§

impl<BS: ArraySize> ReadBuffer<BS>

Source

pub fn get_pos(&self) -> usize

Return current cursor position, i.e. how many bytes were read from the buffer.

Source

pub fn size(&self) -> usize

Return size of the internal buffer in bytes.

Source

pub fn remaining(&self) -> usize

Return number of remaining bytes in the internal buffer.

Source

pub fn read_cached(&mut self, len: usize) -> &[u8]

Read up to len bytes of remaining data in the buffer.

Returns slice with length of ret_len = min(len, buffer.remaining()) bytes and sets the cursor position to buffer.get_pos() + ret_len.

Source

pub fn write_block( &mut self, read_len: usize, gen_block: impl FnOnce(&mut Array<u8, BS>), read_fn: impl FnOnce(&[u8]), )

Write new block and consume read_len bytes from it.

If read_len is equal to zero, immediately returns without calling the closures. Otherwise, the method calls gen_block to fill the internal buffer, passes to read_fn slice with first read_len bytes of the block, and sets the cursor position to read_len.

§Panics

If read_len is bigger than block size.

Source

pub fn reset(&mut self)

Reset buffer into exhausted state.

Source

pub fn read( &mut self, buf: &mut [u8], gen_block: impl FnMut(&mut Array<u8, BS>), )

Write remaining data inside buffer into buf, fill remaining space in buf with blocks generated by gen_block, and save leftover data from the last generated block into the buffer for future use.

Source

pub fn serialize(&self) -> Array<u8, BS>

Serialize buffer into a byte array.

Source

pub fn deserialize(buffer: &Array<u8, BS>) -> Result<Self, Error>

Deserialize buffer from a byte array.

Trait Implementations§

Source§

impl<BS: ArraySize> Clone for ReadBuffer<BS>

Source§

fn clone(&self) -> Self

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<BS: ArraySize> Debug for ReadBuffer<BS>

Source§

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

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

impl<BS: ArraySize> Default for ReadBuffer<BS>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<BS> Freeze for ReadBuffer<BS>
where <BS as ArraySize>::ArrayType<u8>: Freeze,

§

impl<BS> RefUnwindSafe for ReadBuffer<BS>

§

impl<BS> Send for ReadBuffer<BS>

§

impl<BS> Sync for ReadBuffer<BS>

§

impl<BS> Unpin for ReadBuffer<BS>
where <BS as ArraySize>::ArrayType<u8>: Unpin,

§

impl<BS> UnwindSafe for ReadBuffer<BS>
where <BS as ArraySize>::ArrayType<u8>: 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, 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, 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.