pub struct Packet { /* private fields */ }Expand description
An arbitrary chunk of bytes with a user-defined ID.
Implementations§
Source§impl Packet
impl Packet
Sourcepub const MAX_PACKET_SIZE: usize = 255usize
pub const MAX_PACKET_SIZE: usize = 255usize
The maximum size a packet can be.
Sourcepub fn with_data(id: u8, content: &[u8]) -> Result<Packet, InsufficientCapacity>
pub fn with_data(id: u8, content: &[u8]) -> Result<Packet, InsufficientCapacity>
Create a Packet already filled with data.
Sourcepub fn remaining_capacity(&self) -> usize
pub fn remaining_capacity(&self) -> usize
How many more bytes can be added to this Packet before it is full?
Sourcepub fn total_length(&self) -> usize
pub fn total_length(&self) -> usize
The number of bytes this Packet will take up when encoded and written
to a buffer.
Sourcepub fn write_to_buffer(&self, buffer: &mut [u8]) -> Result<usize, EncodeError>
pub fn write_to_buffer(&self, buffer: &mut [u8]) -> Result<usize, EncodeError>
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.
Trait Implementations§
impl StructuralPartialEq for Packet
Auto Trait Implementations§
impl Freeze for Packet
impl RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnwindSafe for Packet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more