Skip to main content

Packet

Trait Packet 

Source
pub trait Packet: Sized {
    const PACKET_ID: i32;

    // Required methods
    fn decode(buf: &mut impl Buf) -> Result<Self, ProtocolError>;
    fn encode(&self, buf: &mut impl BufMut);
}
Expand description

Trait implemented by all typed packets.

Required Associated Constants§

Source

const PACKET_ID: i32

The packet ID for this packet type.

Required Methods§

Source

fn decode(buf: &mut impl Buf) -> Result<Self, ProtocolError>

Decode this packet from the payload buffer (after the packet ID has been read).

§Errors

Returns ProtocolError if the data is malformed.

Source

fn encode(&self, buf: &mut impl BufMut)

Encode this packet’s fields into the buffer (without the packet ID).

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§