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

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

type Inner: AsMut<[u8]>[src]

Inner type used by the buffer.

Loading content...

Required methods

pub fn into_inner(self) -> Self::Inner[src]

Convert the buffer into the inner type.

pub fn next(&mut self, size: usize) -> Result<()>[src]

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

pub fn more(&mut self, size: usize) -> Result<()>[src]

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

pub fn clear(&mut self)[src]

Clear the buffer.

pub fn used(&self) -> usize[src]

Number of bytes used by the whole buffer.

pub fn offset(&self) -> usize[src]

Offset from the beginning of the whole buffer.

pub fn length(&self) -> usize[src]

Length of the current layer.

pub fn data(&self) -> &[u8][src]

Get a slice over the current layer.

pub fn data_mut(&mut self) -> &mut [u8][src]

Get a mutable slice over the current layer.

Loading content...

Implementors

impl Buffer for packet::buffer::Dynamic[src]

type Inner = Vec<u8>

impl<'a> Buffer for packet::buffer::Slice<'a>[src]

type Inner = &'a mut [u8]

Loading content...