Skip to main content

PacketBuilder

Trait PacketBuilder 

Source
pub trait PacketBuilder<C: SerializationContext>: NestablePacketBuilder + Sized {
    // Required method
    fn serialize(
        &self,
        context: &mut C,
        target: &mut SerializeTarget<'_>,
        body: FragmentedBytesMut<'_, '_>,
    );

    // Provided method
    fn context_state(&self) -> C::ContextState { ... }
}
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. NestablePacketBuilder::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 serialize( &self, context: &mut C, 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 context_state(&self) -> C::ContextState

Gets the packet-specific state to use with the SerializationContext.

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<'a, C: SerializationContext, B: PacketBuilder<C>> PacketBuilder<C> for &'a B

Source§

fn context_state(&self) -> C::ContextState

Source§

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

Source§

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

Source§

fn context_state(&self) -> C::ContextState

Source§

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

Source§

impl<C: SerializationContext> PacketBuilder<C> for Infallible

Source§

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

Source§

impl<C: SerializationContext> PacketBuilder<C> for ()

Source§

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

Implementors§