pub trait Packet: Sized {
type Header;
// Required methods
fn from_buf(buf: &[u8]) -> Option<Self>;
fn from_bytes(bytes: Bytes) -> Option<Self>;
fn to_bytes(&self) -> Bytes;
fn header(&self) -> Bytes;
fn payload(&self) -> Bytes;
fn header_len(&self) -> usize;
fn payload_len(&self) -> usize;
fn total_len(&self) -> usize;
fn into_parts(self) -> (Self::Header, Bytes);
// Provided methods
fn to_bytes_mut(&self) -> BytesMut { ... }
fn header_mut(&self) -> BytesMut { ... }
fn payload_mut(&self) -> BytesMut { ... }
}Expand description
Represents a generic network packet.
Required Associated Types§
Required Methods§
Sourcefn from_bytes(bytes: Bytes) -> Option<Self>
fn from_bytes(bytes: Bytes) -> Option<Self>
Parse from raw bytes. (with ownership)
Sourcefn header_len(&self) -> usize
fn header_len(&self) -> usize
Get the length of the header.
Sourcefn payload_len(&self) -> usize
fn payload_len(&self) -> usize
Get the length of the payload.
fn into_parts(self) -> (Self::Header, Bytes)
Provided Methods§
Sourcefn to_bytes_mut(&self) -> BytesMut
fn to_bytes_mut(&self) -> BytesMut
Convert the packet to a mutable byte buffer.
Sourcefn header_mut(&self) -> BytesMut
fn header_mut(&self) -> BytesMut
Get a mutable byte buffer for the header.
Sourcefn payload_mut(&self) -> BytesMut
fn payload_mut(&self) -> BytesMut
Get a mutable byte buffer for the payload.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.