pub trait Packet: Sized {
// Required methods
fn decode(buf: &[u8]) -> Result<(Self, &[u8]), DecodeError>;
fn encoded_len(&self) -> usize;
fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>;
// Provided methods
fn decode_mut(buf: &mut &[u8]) -> Result<Self, DecodeError> { ... }
fn decode_full(buf: &[u8]) -> Result<Self, DecodeError> { ... }
fn encode_to_vec(&self) -> Result<Vec<u8>, EncodeError> { ... }
fn encode_to_bytes(&self) -> Result<Bytes, EncodeError> { ... }
}
Expand description
Trait implemented for all toplevel packet declarations.
Required Methods§
Sourcefn decode(buf: &[u8]) -> Result<(Self, &[u8]), DecodeError>
fn decode(buf: &[u8]) -> Result<(Self, &[u8]), DecodeError>
Try parsing an instance of Self from the input slice. On success, returns the parsed object and the remaining unparsed slice. On failure, returns an error with the reason for the parsing failure.
Sourcefn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Return the length of the encoded packet.
Provided Methods§
Sourcefn decode_mut(buf: &mut &[u8]) -> Result<Self, DecodeError>
fn decode_mut(buf: &mut &[u8]) -> Result<Self, DecodeError>
Try parsing an instance of Packet updating the slice in place to the remainder of the data. The input buffer is not updated if parsing fails.
Sourcefn decode_full(buf: &[u8]) -> Result<Self, DecodeError>
fn decode_full(buf: &[u8]) -> Result<Self, DecodeError>
Try parsing an instance of Packet from the input slice. Returns an error if unparsed bytes remain at the end of the input slice.
Sourcefn encode_to_vec(&self) -> Result<Vec<u8>, EncodeError>
fn encode_to_vec(&self) -> Result<Vec<u8>, EncodeError>
Encode the packet to a byte vector.
Sourcefn encode_to_bytes(&self) -> Result<Bytes, EncodeError>
fn encode_to_bytes(&self) -> Result<Bytes, EncodeError>
Encode the packet to a Bytes object.
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.