pub struct Reader<R> { /* private fields */ }Expand description
Struct used in [storekey::Decode] for reading types from the buffer.
This type handles unescaping bytes the buffer mostly transparently. It has an internal flag for marking when an escaped byte can be read from the buffer. Reading from the buffer in any way unmarks this flag.
Implementations§
Source§impl<R: BufRead> Reader<R>
impl<R: BufRead> Reader<R>
Sourcepub fn is_empty(&mut self) -> Result<bool, DecodeError>
pub fn is_empty(&mut self) -> Result<bool, DecodeError>
Returns if the reader is empty / contains no more data.
Sourcepub fn expect_escaped(&mut self)
pub fn expect_escaped(&mut self)
Mark the next byte as possibly containing an escaped bytes.
Sourcepub fn read_terminal(&mut self) -> Result<bool, DecodeError>
pub fn read_terminal(&mut self) -> Result<bool, DecodeError>
Try to read a terminator byte if there is one.
Returns true if the next byte is a terminator, otherwise returns false and the reader does not advance.
Sets the expect_escaped flag marking the next byte as being possibly escaped.
Sourcepub fn read_array<const SIZE: usize>(
&mut self,
) -> Result<[u8; SIZE], DecodeError>
pub fn read_array<const SIZE: usize>( &mut self, ) -> Result<[u8; SIZE], DecodeError>
Reads an fixed size array of u8 from the reader, unescaping possible escaped bytes.
All other read_* functions of Reader which read a fixed size type call this function to
read a certain amount of bytes from the reader.
This type does not expect a null terminator after the end of the array as it is reading a fixed size type.
Calling this function unsets the expected escape flag before returning.
Sourcepub fn read_vec(&mut self) -> Result<Vec<u8>, DecodeError>
pub fn read_vec(&mut self) -> Result<Vec<u8>, DecodeError>
Reads a runtime sized Vec<u8> from the reader, expected the sequence of bytes to be
ended by a terminal zero byte.
Calling this function unsets the expected escape flag before returning.
Sourcepub fn read_string(&mut self) -> Result<String, DecodeError>
pub fn read_string(&mut self) -> Result<String, DecodeError>
Reads a runtime sized String from the reader, expected the sequence of bytes to be
ended by a terminal zero byte.
Calling this function unsets the expected escape flag before returning.