pub trait PacketBuilder {
    // Required methods
    fn constraints(&self) -> PacketConstraints;
    fn serialize(&self, buffer: &mut SerializeBuffer<'_, '_>);
}
Expand description

A builder capable of serializing a packet’s headers and footers.

A PacketBuilder describes a packet’s headers and footers, and is capable of serializing that packet into an existing buffer via the serialize method. A PacketBuilder never describes a body - one must always be provided in order to call serialize.

Thanks to a blanket implementation, every PacketBuilder is also a NestedPacketBuilder. While a PacketBuilder represents exactly one “layer” of a packet - a pair of a header and a footer - a NestedPacketBuilder can represent multiple nested layers of a packet, and can be composed from other NestedPacketBuilders. See the trait documentation for more details.

() may be used as an “empty” PacketBuilder with no header, footer, minimum body length requirement, or maximum body length requirement.

Required Methods§

source

fn constraints(&self) -> PacketConstraints

Gets the constraints for this PacketBuilder.

source

fn serialize(&self, buffer: &mut SerializeBuffer<'_, '_>)

Serializes this packet into an existing buffer.

serialize is called with a SerializeBuffer which provides access to the parts of a buffer corresponding to the header, body, and footer of this packet. The buffer’s body is initialized with the body to be encapsulated, and serialize is responsible for serializing the header and footer into the appropriate sections of the buffer. The caller is responsible for ensuring that the body satisfies both the minimum and maximum body length requirements, possibly by adding padding or truncating the body.

This method is usually called from NestedPacketBuilder::serialize_into, not directly by the user.

Security

serialize must initialize the bytes of the header and footer, even if only to zero, in order to avoid leaking the contents of packets previously stored in the same buffer.

Panics

May panic if the SerializeBuffer’s header or footer are not large enough to fit the packet’s header and footer, or if the body does not satisfy the minimum or maximum body length requirements.

Implementations on Foreign Types§

source§

impl PacketBuilder for ()

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize(&self, _buffer: &mut SerializeBuffer<'_, '_>)

source§

impl<'a, B: PacketBuilder> PacketBuilder for &'a mut B

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize(&self, buffer: &mut SerializeBuffer<'_, '_>)

source§

impl<'a, B: PacketBuilder> PacketBuilder for &'a B

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize(&self, buffer: &mut SerializeBuffer<'_, '_>)

source§

impl PacketBuilder for Never

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize(&self, _buffer: &mut SerializeBuffer<'_, '_>)

Implementors§