pub struct ReadBuffer<BS: BlockSizes> {
buffer: Array<u8, BS>,
}Expand description
Buffer for reading block-generated data.
Fields§
§buffer: Array<u8, BS>The first byte of the block is used as cursor position.
&buffer[usize::from(buffer[0])..] is interpreted as unread bytes.
The cursor position is always bigger than zero and smaller than or equal to block size.
Implementations§
Source§impl<BS: BlockSizes> ReadBuffer<BS>
impl<BS: BlockSizes> ReadBuffer<BS>
Sourcepub fn get_pos(&self) -> usize
pub fn get_pos(&self) -> usize
Return current cursor position, i.e. how many bytes were read from the buffer.
Sourceunsafe fn set_pos_unchecked(&mut self, pos: usize)
unsafe fn set_pos_unchecked(&mut self, pos: usize)
Set cursor position.
§Safety
pos must be smaller than or equal to the buffer block size and be bigger than zero.
Sourcepub fn read_cached(&mut self, len: usize) -> &[u8]
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.
Sourcepub fn write_block(
&mut self,
read_len: usize,
gen_block: impl FnOnce(&mut Array<u8, BS>),
read_fn: impl FnOnce(&[u8]),
)
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.