[][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 PartialEq<Packet> for Packet[src]

impl Debug for Packet[src]

impl Clone for Packet[src]

impl Default for Packet[src]

Auto Trait Implementations

impl Unpin for Packet

impl Send for Packet

impl Sync for Packet

impl UnwindSafe for Packet

impl RefUnwindSafe for Packet

Blanket Implementations

impl<T> From<T> for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

The type returned in the event of a conversion error.

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

impl<T> BorrowMut<T> 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

The resulting type after obtaining ownership.