Trait packet::serialize::PacketBuilder

source ·
pub trait PacketBuilder {
    // Required methods
    fn constraints(&self) -> PacketConstraints;
    fn serialize(
        &self,
        target: &mut SerializeTarget<'_>,
        body: FragmentedBytesMut<'_, '_>,
    );
}
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, target: &mut SerializeTarget<'_>, body: FragmentedBytesMut<'_, '_>, )

Serializes this packet into an existing buffer.

This method is usually called by this crate during the serialization of a Serializer, not directly by the user.

§Preconditions

The caller is responsible for initializing body with the body to be encapsulated, and for ensuring that the body satisfies both the minimum and maximum body length requirements, possibly by adding padding or by truncating the body.

§Postconditions

serialize is responsible for serializing its header and footer into target.header and target.footer respectively.

§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 target.header or target.footer are not large enough to fit the packet’s header and footer respectively, or if the body does not satisfy the minimum or maximum body length requirements.

Implementations on Foreign Types§

source§

impl PacketBuilder for Infallible

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize( &self, _target: &mut SerializeTarget<'_>, _body: FragmentedBytesMut<'_, '_>, )

source§

impl PacketBuilder for ()

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize( &self, _target: &mut SerializeTarget<'_>, _body: FragmentedBytesMut<'_, '_>, )

source§

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

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize( &self, target: &mut SerializeTarget<'_>, body: FragmentedBytesMut<'_, '_>, )

source§

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

source§

fn constraints(&self) -> PacketConstraints

source§

fn serialize( &self, target: &mut SerializeTarget<'_>, body: FragmentedBytesMut<'_, '_>, )

Implementors§