Trait PacketBuilder

Source
pub trait PacketBuilder: Sized {
    // Required methods
    fn constraints(&self) -> PacketConstraints;
    fn serialize(
        &self,
        target: &mut SerializeTarget<'_>,
        body: FragmentedBytesMut<'_, '_>,
    );

    // Provided method
    fn wrap_body<B>(self, body: B) -> Nested<B, Self> { ... }
}
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 the header and the footer into an existing buffer via the serialize method. A PacketBuilder never describes a body. PacketBuilder::wrap_body must be used to create a packet serializer for a whole packet.

() 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.

Provided Methods§

Source

fn wrap_body<B>(self, body: B) -> Nested<B, Self>

Wraps given packet body in this packet.

Consumes the PacketBuilder and the body. If the body implements Serializer then the result implement Serializer as well.

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.

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§