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 peeking.

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,

source

pub fn new(reader: R) -> PeekReader<R, BUFFER_SIZE>

Instantiates a new PeekReader, wrapping the provided std::io::Reader and using the default chunk size

source

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::Reader 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.

source

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::Reader 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.

source

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::Reader 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.

source

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.

source

pub fn reader_ref(&mut self) -> &R

Returns an immutable reference to the underlying std::io::Reader

Reading directly from the underlying stream will cause data loss

source

pub fn reader_mut(&mut self) -> &mut R

Returns a mutable reference to the underlying std::io::Reader

Reading directly from the underlying stream will cause data loss

Auto Trait Implementations§

§

impl<R, const BUFFER_SIZE: usize> Freeze for PeekReader<R, BUFFER_SIZE>
where R: Freeze,

§

impl<R, const BUFFER_SIZE: usize> RefUnwindSafe for PeekReader<R, BUFFER_SIZE>
where R: RefUnwindSafe,

§

impl<R, const BUFFER_SIZE: usize> Send for PeekReader<R, BUFFER_SIZE>
where R: Send,

§

impl<R, const BUFFER_SIZE: usize> Sync for PeekReader<R, BUFFER_SIZE>
where R: Sync,

§

impl<R, const BUFFER_SIZE: usize> Unpin for PeekReader<R, BUFFER_SIZE>
where R: Unpin,

§

impl<R, const BUFFER_SIZE: usize> UnwindSafe for PeekReader<R, BUFFER_SIZE>
where R: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

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

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.