Trait packet::buffer::Buffer [] [src]

pub trait Buffer {
    type Inner: AsMut<[u8]>;
    fn into_inner(self) -> Self::Inner;
fn next(&mut self, size: usize) -> Result<()>;
fn more(&mut self, size: usize) -> Result<()>;
fn clear(&mut self);
fn used(&self) -> usize;
fn offset(&self) -> usize;
fn length(&self) -> usize;
fn data(&self) -> &[u8];
fn data_mut(&mut self) -> &mut [u8]; }

A buffer to build packets in.

A Buffer is composed of multiple layers, internally an offset and length is used to keep track of the current layer, data() and data_mut() will always return a slice to the current layer.

Example

use packet::buffer::{self, Buffer};

// Create a new dynamic buffer, `buffer::Dynamic` is backed by a `Vec<u8>`.
let mut buffer = buffer::Dynamic::new();

// Create a new layer for 20 bytes, calling `next()` increases the offset
// and zeroes the underlying memory.
buffer.next(20);

// Get more memory in the buffer.
buffer.more(4);

// Get the backing data for the buffer.
let data = buffer.into_inner();
assert_eq!(data.len(), 24);

Associated Types

Inner type used by the buffer.

Required Methods

Convert the buffer into the inner type.

Go to the next layer requesting the given size, zeroeing the layer.

Request more memory for the same layer, zeroeing the new buffer area.

Clear the buffer.

Number of bytes used by the whole buffer.

Offset from the beginning of the whole buffer.

Length of the current layer.

Get a slice over the current layer.

Get a mutable slice over the current layer.

Implementors