OutputBuffer

Trait OutputBuffer 

Source
pub trait OutputBuffer: Buffer {
    // Required methods
    fn write_each(
        &mut self,
        callback: &mut OutputBufferCallback<'_>,
    ) -> Result<usize, Errno>;
    fn available(&self) -> usize;
    fn bytes_written(&self) -> usize;
    fn zero(&mut self) -> Result<usize, Errno>;
    unsafe fn advance(&mut self, length: usize) -> Result<(), Errno>;

    // Provided methods
    fn write(&mut self, buffer: &[u8]) -> Result<usize, Errno> { ... }
    fn write_all(&mut self, buffer: &[u8]) -> Result<usize, Errno> { ... }
    fn write_buffer(
        &mut self,
        input: &mut dyn InputBuffer,
    ) -> Result<usize, Errno> { ... }
}
Expand description

The OutputBuffer allows for writing bytes to a buffer. A single OutputBuffer will only write up to MAX_RW_COUNT bytes which is the maximum size of a single operation.

Required Methods§

Source

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

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

Returns the total number of bytes written.

Source

fn available(&self) -> usize

Returns the number of bytes available to be written into the buffer.

Source

fn bytes_written(&self) -> usize

Returns the number of bytes already written into the buffer.

Source

fn zero(&mut self) -> Result<usize, Errno>

Fills this buffer with zeros.

Source

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

Advance the output buffer by length bytes.

§Safety

The caller must guarantee that the length bytes are initialized.

Provided Methods§

Source

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

Write the content of buffer into this buffer. If this buffer is too small, the write will be partial.

Returns the number of bytes written in this buffer.

Source

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

Write the content of buffer into this buffer. It is an error to pass a buffer larger than the number of bytes available in this buffer. In that case, the content of the buffer after the operation is unspecified.

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

Source

fn write_buffer(&mut self, input: &mut dyn InputBuffer) -> Result<usize, Errno>

Write the content of the given InputBuffer into this buffer. The number of bytes written will be the smallest between the number of bytes available in this buffer and in the InputBuffer.

Returns the number of bytes read and written.

Implementors§