pub trait Buffer {
type Inner: AsMut<[u8]>;
// Required methods
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] ⓘ;
}
Expand description
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);
Required Associated Types§
Required Methods§
Sourcefn into_inner(self) -> Self::Inner
fn into_inner(self) -> Self::Inner
Convert the buffer into the inner type.
Sourcefn next(&mut self, size: usize) -> Result<()>
fn next(&mut self, size: usize) -> Result<()>
Go to the next layer requesting the given size, zeroeing the layer.