[][src]Struct anpp::Packet

pub struct Packet { /* fields omitted */ }

An arbitrary chunk of bytes with a user-defined ID.

Methods

impl Packet
[src]

pub const MAX_PACKET_SIZE: usize[src]

The maximum size a packet can be.

pub fn new(id: u8) -> Packet
[src]

Create a new empty Packet.

pub fn with_data(id: u8, content: &[u8]) -> Result<Packet, InsufficientCapacity>
[src]

Create a Packet already filled with data.

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

Get the Packet's identifier.

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

Get the contents of the Packet.

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

How long is the Packet's contents?

pub fn is_empty(&self) -> bool
[src]

Is this Packet empty?

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

How many more bytes can be added to this Packet before it is full?

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

The number of bytes this Packet will take up when encoded and written to a buffer.

pub fn write_to_buffer(&self, buffer: &mut [u8]) -> Result<usize, EncodeError>
[src]

Encode a Packet and copy it into the provided buffer.

Note

The minimum required buffer size can be determined via the total_length() method. If the buffer isn't big enough, nothing will be written to the buffer and this method will fail with an InsufficientCapacity error.

pub fn push_data(&mut self, data: &[u8]) -> Result<(), InsufficientCapacity>
[src]

Try to append some data to the Packet's contents, bailing without writing anything if there isn't enough space.

Trait Implementations

impl Clone for Packet
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Packet
[src]

impl PartialEq<Packet> for Packet
[src]

impl Default for Packet
[src]

Auto Trait Implementations

impl Send for Packet

impl Sync for Packet

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T