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§
Sourcefn peek_each(
&mut self,
callback: &mut InputBufferCallback<'_>,
) -> Result<usize, Errno>
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.
Sourcefn bytes_read(&self) -> usize
fn bytes_read(&self) -> usize
Returns the number of bytes already read from the buffer.
Provided Methods§
Sourcefn read_each(
&mut self,
callback: &mut InputBufferCallback<'_>,
) -> Result<usize, Errno>
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.
Sourcefn read_all(&mut self) -> Result<Vec<u8>, Errno>
fn read_all(&mut self) -> Result<Vec<u8>, Errno>
Read all the remaining content in this buffer and returns it as a Vec.
Sourcefn peek_all(&mut self) -> Result<Vec<u8>, Errno>
fn peek_all(&mut self) -> Result<Vec<u8>, Errno>
Peek all the remaining content in this buffer and returns it as a Vec.
Sourcefn peek(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno>
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.
Sourcefn read(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno>
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.
Sourcefn read_exact(&mut self, buffer: &mut [MaybeUninit<u8>]) -> Result<usize, Errno>
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 + '_
impl InputBufferExt for dyn InputBuffer + '_
Source§fn read_to_vec_limited(&mut self, limit: usize) -> Result<Vec<u8>, Errno>
fn read_to_vec_limited(&mut self, limit: usize) -> Result<Vec<u8>, Errno>
limit bytes into a returned Vec.