Trait Packet

Source
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§

Source

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.

Source

fn encoded_len(&self) -> usize

Return the length of the encoded packet.

Source

fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>

Write the packet to an output buffer.

Provided Methods§

Source

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.

Source

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.

Source

fn encode_to_vec(&self) -> Result<Vec<u8>, EncodeError>

Encode the packet to a byte vector.

Source

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.

Implementors§