pub trait InnerPacketBuilder {
    // Required methods
    fn bytes_len(&self) -> usize;
    fn serialize(&self, buffer: &mut [u8]);

    // Provided methods
    fn into_serializer(self) -> InnerSerializer<Self, EmptyBuf>
       where Self: Sized { ... }
    fn into_serializer_with<B: ShrinkBuffer>(
        self,
        buffer: B
    ) -> InnerSerializer<Self, B>
       where Self: Sized { ... }
}
Expand description

A builder capable of serializing packets - which do not encapsulate other packets - into an existing buffer.

An InnerPacketBuilder describes a packet, and is capable of serializing that packet into an existing buffer via the serialize method. Unlike the PacketBuilder trait, it describes a packet which does not encapsulate other packets.

§Notable implementations

InnerPacketBuilder is implemented for &[u8], &mut [u8], and Vec<u8> by treating the contents of the slice/Vec as the contents of the packet to be serialized.

Required Methods§

source

fn bytes_len(&self) -> usize

The number of bytes consumed by this packet.

source

fn serialize(&self, buffer: &mut [u8])

Serializes this packet into an existing buffer.

serialize is called with a buffer of length self.bytes_len(), and is responsible for serializing the packet into the buffer.

§Security

All of the bytes of the buffer should be initialized, even if only to zero, in order to avoid leaking the contents of packets previously stored in the same buffer.

§Panics

May panic if buffer.len() != self.bytes_len().

Provided Methods§

source

fn into_serializer(self) -> InnerSerializer<Self, EmptyBuf>
where Self: Sized,

Converts this InnerPacketBuilder into a Serializer.

into_serializer is like into_serializer_with, except that no buffer is provided for reuse in serialization.

source

fn into_serializer_with<B: ShrinkBuffer>( self, buffer: B ) -> InnerSerializer<Self, B>
where Self: Sized,

Converts this InnerPacketBuilder into a Serializer with a buffer that can be used for serialization.

into_serializer_with consumes a buffer and converts self into a type which implements Serialize by treating it as the innermost body to be contained within any encapsulating PacketBuilders. During serialization, buffer will be provided to the BufferProvider, allowing it to reuse the buffer for serialization and avoid allocating a new one if possible.

buffer will have its body shrunk to be zero bytes before the InnerSerializer is constructed.

Implementations on Foreign Types§

source§

impl<'a> InnerPacketBuilder for &'a [u8]

source§

fn bytes_len(&self) -> usize

source§

fn serialize(&self, buffer: &mut [u8])

source§

impl<'a> InnerPacketBuilder for &'a mut [u8]

source§

fn bytes_len(&self) -> usize

source§

fn serialize(&self, buffer: &mut [u8])

source§

impl<'a> InnerPacketBuilder for Vec<u8>

source§

fn bytes_len(&self) -> usize

source§

fn serialize(&self, buffer: &mut [u8])

source§

impl<'a, I: InnerPacketBuilder> InnerPacketBuilder for &'a I

source§

fn bytes_len(&self) -> usize

source§

fn serialize(&self, buffer: &mut [u8])

source§

impl<'a, I: InnerPacketBuilder> InnerPacketBuilder for &'a mut I

source§

fn bytes_len(&self) -> usize

source§

fn serialize(&self, buffer: &mut [u8])

source§

impl<const N: usize> InnerPacketBuilder for ArrayVec<u8, N>

source§

fn bytes_len(&self) -> usize

source§

fn serialize(&self, buffer: &mut [u8])

Implementors§