Struct mavlink::peek_reader::PeekReader
source · pub struct PeekReader<R, const BUFFER_SIZE: usize = 280> { /* private fields */ }
Expand description
A buffered/peekable reader
This reader wraps a type implementing std::io::Read
and adds buffering via an internal buffer.
It allows the user to peek
a specified number of bytes (without consuming them),
to read
bytes (consuming them), or to consume
them after peek
ing.
NOTE: This reader is generic over the size of the buffer, defaulting to MAVLink’s current largest possible message size of 280 bytes
Implementations§
source§impl<R, const BUFFER_SIZE: usize> PeekReader<R, BUFFER_SIZE>where
R: Read,
impl<R, const BUFFER_SIZE: usize> PeekReader<R, BUFFER_SIZE>where
R: Read,
sourcepub fn new(reader: R) -> PeekReader<R, BUFFER_SIZE>
pub fn new(reader: R) -> PeekReader<R, BUFFER_SIZE>
Instantiates a new PeekReader
, wrapping the provided std::io::Read
er and using the default chunk size
sourcepub fn peek_exact(&mut self, amount: usize) -> Result<&[u8], MessageReadError>
pub fn peek_exact(&mut self, amount: usize) -> Result<&[u8], MessageReadError>
Peeks an exact amount of bytes from the internal buffer
If the internal buffer does not contain enough data, this function will read
from the underlying std::io::Read
er until it does, an error occurs or no more data can be read (EOF).
If an EOF occurs and the specified amount could not be read, this function will return an [ErrorKind::UnexpectedEof
].
This function does not consume data from the buffer, so subsequent calls to peek
or read
functions
will still return the peeked data.
sourcepub fn read_exact(&mut self, amount: usize) -> Result<&[u8], MessageReadError>
pub fn read_exact(&mut self, amount: usize) -> Result<&[u8], MessageReadError>
Reads a specified amount of bytes from the internal buffer
If the internal buffer does not contain enough data, this function will read
from the underlying std::io::Read
er until it does, an error occurs or no more data can be read (EOF).
If an EOF occurs and the specified amount could not be read, this function will return an [ErrorKind::UnexpectedEof
].
This function consumes the data from the buffer, unless an error occurs, in which case no data is consumed.
sourcepub fn read_u8(&mut self) -> Result<u8, MessageReadError>
pub fn read_u8(&mut self) -> Result<u8, MessageReadError>
Reads a byte from the internal buffer
If the internal buffer does not contain enough data, this function will read
from the underlying std::io::Read
er until it does, an error occurs or no more data can be read (EOF).
If an EOF occurs and the specified amount could not be read, this function will return an [ErrorKind::UnexpectedEof
].
This function consumes the data from the buffer, unless an error occurs, in which case no data is consumed.
sourcepub fn consume(&mut self, amount: usize) -> usize
pub fn consume(&mut self, amount: usize) -> usize
Consumes a specified amount of bytes from the buffer
If the internal buffer does not contain enough data, this function will consume as much data as is buffered.
sourcepub fn reader_ref(&mut self) -> &R
pub fn reader_ref(&mut self) -> &R
Returns an immutable reference to the underlying std::io::Read
er
Reading directly from the underlying stream will cause data loss
sourcepub fn reader_mut(&mut self) -> &mut R
pub fn reader_mut(&mut self) -> &mut R
Returns a mutable reference to the underlying std::io::Read
er
Reading directly from the underlying stream will cause data loss