Packet

Trait Packet 

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

Source

fn from_buf(buf: &[u8]) -> Option<Self>

Parse from a byte slice.

Source

fn from_bytes(bytes: Bytes) -> Option<Self>

Parse from raw bytes. (with ownership)

Source

fn to_bytes(&self) -> Bytes

Serialize into raw bytes.

Source

fn header(&self) -> Bytes

Get the header of the packet.

Source

fn payload(&self) -> Bytes

Get the payload of the packet.

Source

fn header_len(&self) -> usize

Get the length of the header.

Source

fn payload_len(&self) -> usize

Get the length of the payload.

Source

fn total_len(&self) -> usize

Get the total length of the packet (header + payload).

Source

fn into_parts(self) -> (Self::Header, Bytes)

Provided Methods§

Source

fn to_bytes_mut(&self) -> BytesMut

Convert the packet to a mutable byte buffer.

Source

fn header_mut(&self) -> BytesMut

Get a mutable byte buffer for the header.

Source

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.

Implementors§

Source§

impl Packet for ArpPacket

Source§

impl Packet for DhcpPacket

Source§

impl Packet for DnsPacket

Source§

impl Packet for DnsQueryPacket

Source§

impl Packet for DnsResponsePacket

Source§

impl Packet for EthernetPacket

Source§

impl Packet for FlowControlPacket

Source§

impl Packet for GrePacket

Source§

impl Packet for IcmpPacket

Source§

impl Packet for EchoReplyPacket

Source§

impl Packet for EchoRequestPacket

Source§

impl Packet for NdpOptionPacket

Source§

impl Packet for NeighborAdvertPacket

Source§

impl Packet for NeighborSolicitPacket

Source§

impl Packet for RedirectPacket

Source§

impl Packet for RouterAdvertPacket

Source§

impl Packet for RouterSolicitPacket

Source§

impl Packet for Icmpv6Packet

Source§

impl Packet for Ipv4Packet

Source§

impl Packet for Ipv6Packet

Source§

impl Packet for TcpPacket

Source§

impl Packet for UdpPacket

Source§

impl Packet for VlanPacket

Source§

impl Packet for VxlanPacket