Skip to main content

PartialSerializer

Trait PartialSerializer 

Source
pub trait PartialSerializer<C: SerializationContext> {
    // Required method
    fn partial_serialize_new_buf<B: GrowBufferMut, A: LayoutBufferAlloc<B>>(
        &self,
        context: &mut C,
        constraints: PacketConstraints,
        alloc: A,
    ) -> Result<(B, usize), SerializeError<A::Error>>;

    // Provided method
    fn partial_serialize<B: GrowBufferMut + ContiguousBuffer, A: LayoutBufferAlloc<B>>(
        &self,
        context: &mut C,
        alloc: A,
    ) -> Result<PartialSerializeResult<'_, B>, SerializeError<A::Error>> { ... }
}
Expand description

A serializer that supports partial serialization.

Partial serialization allows to serialize only packet headers without calculating packet checksums (if any).

Required Methods§

Source

fn partial_serialize_new_buf<B: GrowBufferMut, A: LayoutBufferAlloc<B>>( &self, context: &mut C, constraints: PacketConstraints, alloc: A, ) -> Result<(B, usize), SerializeError<A::Error>>

Serializes the headers into a new buffer allocated used alloc.

Returns a buffer with serialized headers. If the serializer doesn’t serialize any headers then an empty buffer is returned. In either case, the buffer is guaranteed to contain exactly constraints.header_len() at the head.

The second returned value indicates total number of bytes in the packet, including the headers.

Provided Methods§

Source

fn partial_serialize<B: GrowBufferMut + ContiguousBuffer, A: LayoutBufferAlloc<B>>( &self, context: &mut C, alloc: A, ) -> Result<PartialSerializeResult<'_, B>, SerializeError<A::Error>>

If the packet is already serialized then returns the whole seialized packet as PartialSerializeResult::Slice. Otherwise serializes the headers into a new buffer returned as PartialSerializeResult::NewBuffer.

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.

Implementors§