[−][src]Struct anpp::Packet
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]
fn clone(&self) -> Packet
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Default for Packet
[src]
Auto Trait Implementations
impl Unpin for Packet
impl Send for Packet
impl Sync for Packet
impl RefUnwindSafe for Packet
impl UnwindSafe for Packet
Blanket Implementations
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,