Struct ReadBuffer

pub struct ReadBuffer<BS: BlockSizes> { /* private fields */ }

Buffer for reading block-generated data.

Implementations

impl<BS: BlockSizes> ReadBuffer<BS>

fn get_pos(&self) -> usize

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

fn size(&self) -> usize

Return size of the internal buffer in bytes.

fn remaining(&self) -> usize

Return number of remaining bytes in the internal buffer.

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.

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.

fn reset(&mut self)

Reset buffer into exhausted state.

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.

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

Serialize buffer into a byte array.

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

Deserialize buffer from a byte array.

Errors

  • If the first byte is 0.
  • If the first byte is bigger than BS.

Trait Implementations

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

fn clone(&self) -> Self

impl<BS: BlockSizes> Debug for ReadBuffer<BS>

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

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

fn default() -> Self

impl<BS: BlockSizes> Drop for ReadBuffer<BS>

fn drop(&mut self)

impl<BS: BlockSizes> ZeroizeOnDrop for ReadBuffer<BS>

Auto Trait Implementations

impl<BS> Freeze for ReadBuffer<BS> where Array<u8, BS>: Freeze,

impl<BS> RefUnwindSafe for ReadBuffer<BS> where Array<u8, BS>: RefUnwindSafe,

impl<BS> Send for ReadBuffer<BS> where Array<u8, BS>: Send,

impl<BS> Sync for ReadBuffer<BS> where Array<u8, BS>: Sync,

impl<BS> Unpin for ReadBuffer<BS> where Array<u8, BS>: Unpin,

impl<BS> UnsafeUnpin for ReadBuffer<BS> where Array<u8, BS>: UnsafeUnpin,

impl<BS> UnwindSafe for ReadBuffer<BS> where Array<u8, BS>: UnwindSafe,

Blanket Implementations

impl<T> Any for ReadBuffer<BS> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ReadBuffer<BS> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ReadBuffer<BS> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for ReadBuffer<BS> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for ReadBuffer<BS>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Same for ReadBuffer<BS>

type Output = T;

impl<T> ToOwned for ReadBuffer<BS> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for ReadBuffer<BS> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for ReadBuffer<BS> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for ReadBuffer<BS> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>