InputBuffer

Trait InputBuffer 

Source
pub trait InputBuffer: Buffer {
    // Required methods
    fn peek_each(
        &mut self,
        callback: &mut InputBufferCallback<'_>,
    ) -> Result<usize, Errno>;
    fn available(&self) -> usize;
    fn bytes_read(&self) -> usize;
    fn drain(&mut self) -> usize;
    fn advance(&mut self, length: usize) -> Result<(), Errno>;

    // Provided methods
    fn read_each(
        &mut self,
        callback: &mut InputBufferCallback<'_>,
    ) -> Result<usize, Errno> { ... }
    fn read_all(&mut self) -> Result<Vec<u8>, Errno> { ... }
    fn peek_all(&mut self) -> Result<Vec<u8>, Errno> { ... }
    fn peek(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno> { ... }
    fn read(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno> { ... }
    fn read_exact(
        &mut self,
        buffer: &mut [MaybeUninit<u8>],
    ) -> Result<usize, Errno> { ... }
}
Expand description

The InputBuffer allows for reading bytes from a buffer. A single InputBuffer will only read up to MAX_RW_COUNT bytes which is the maximum size of a single operation.

Required Methods§

Source

fn peek_each( &mut self, callback: &mut InputBufferCallback<'_>, ) -> Result<usize, Errno>

Calls callback for each segment to peek data from. callback must returns the number of bytes actually peeked. When it returns less than the size of the output buffer, the read is stopped.

Returns the total number of bytes peeked.

Source

fn available(&self) -> usize

Returns the number of bytes available to be read from the buffer.

Source

fn bytes_read(&self) -> usize

Returns the number of bytes already read from the buffer.

Source

fn drain(&mut self) -> usize

Clear the remaining content in the buffer. Returns the number of bytes swallowed. After this method returns, available() will returns 0. This does not touch the data in the buffer.

Source

fn advance(&mut self, length: usize) -> Result<(), Errno>

Consumes length bytes of data from this buffer.

Provided Methods§

Source

fn read_each( &mut self, callback: &mut InputBufferCallback<'_>, ) -> Result<usize, Errno>

Calls callback for each segment to read data from. callback must returns the number of bytes actually read. When it returns less than the size of the output buffer, the read is stopped.

Returns the total number of bytes read.

Source

fn read_all(&mut self) -> Result<Vec<u8>, Errno>

Read all the remaining content in this buffer and returns it as a Vec.

Source

fn peek_all(&mut self) -> Result<Vec<u8>, Errno>

Peek all the remaining content in this buffer and returns it as a Vec.

Source

fn peek(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno>

Peeks the content of this buffer into buffer. If buffer is too small, the read will be partial. If buffer is too large, the remaining bytes will be left untouched.

Returns the number of bytes read from this buffer.

Source

fn read(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno>

Write the content of this buffer into buffer. If buffer is too small, the read will be partial. If buffer is too large, the remaining bytes will be left untouched.

Returns the number of bytes read from this buffer.

Source

fn read_exact(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno>

Read the exact number of bytes required to fill buf.

If buffer is larger than the number of available bytes, an error will be returned.

In case of success, always returns buffer.len().

Trait Implementations§

Source§

impl InputBufferExt for dyn InputBuffer + '_

Source§

fn read_to_vec_exact(&mut self, len: usize) -> Result<Vec<u8>, Errno>

Reads exactly len bytes into a returned Vec. Read more
Source§

fn read_to_vec_limited(&mut self, limit: usize) -> Result<Vec<u8>, Errno>

Reads up to limit bytes into a returned Vec.
Source§

fn read_to_array<const N: usize>(&mut self) -> Result<[u8; N], Errno>

Reads bytes into the array. Read more
Source§

fn read_to_object<T: FromBytes>(&mut self) -> Result<T, Errno>

Interprets the buffer as an object. Read more

Implementors§