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) -> usizeReturn current cursor position, i.e. how many bytes were read from the buffer.
fn size(&self) -> usizeReturn size of the internal buffer in bytes.
fn remaining(&self) -> usizeReturn number of remaining bytes in the internal buffer.
fn read_cached(&mut self, len: usize) -> &[u8]Read up to
lenbytes of remaining data in the buffer.Returns slice with length of
ret_len = min(len, buffer.remaining())bytes and sets the cursor position tobuffer.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_lenbytes from it.If
read_lenis equal to zero, immediately returns without calling the closures. Otherwise, the method callsgen_blockto fill the internal buffer, passes toread_fnslice with firstread_lenbytes of the block, and sets the cursor position toread_len.Panics
If
read_lenis 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 inbufwith blocks generated bygen_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.
- If the first byte is
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)