Struct packet::records::RecordSequenceBuilder
source · pub struct RecordSequenceBuilder<R, I> { /* private fields */ }
Expand description
A builder capable of serializing a sequence of records.
A RecordSequenceBuilder
is instantiated with an Iterator
that provides
RecordBuilder
s to be serialized. The item produced by the iterator can
be any type which implements Borrow<R>
for R: RecordBuilder
.
RecordSequenceBuilder
implements InnerPacketBuilder
.
Implementations§
source§impl<R, I> RecordSequenceBuilder<R, I>
impl<R, I> RecordSequenceBuilder<R, I>
sourcepub fn new(records: I) -> Self
pub fn new(records: I) -> Self
Creates a new RecordSequenceBuilder
with the given records
.
records
must produce the same sequence of values from every iteration,
even if cloned. Serialization is typically performed with two passes on
records
: one to calculate the total length in bytes (serialized_len
)
and another one to serialize to a buffer (serialize_into
). Violating
this rule may result in panics or malformed serialized record sequences.
source§impl<R, I> RecordSequenceBuilder<R, I>where
R: RecordBuilder,
I: Iterator + Clone,
I::Item: Borrow<R>,
impl<R, I> RecordSequenceBuilder<R, I>where R: RecordBuilder, I: Iterator + Clone, I::Item: Borrow<R>,
sourcepub fn serialized_len(&self) -> usize
pub fn serialized_len(&self) -> usize
Returns the total length, in bytes, of the serialized encoding of the
records contained within self
.
sourcepub fn serialize_into(&self, buffer: &mut [u8])
pub fn serialize_into(&self, buffer: &mut [u8])
Serializes all the records contained within self
into the given
buffer.
Panics
serialize_into
expects that buffer
has enough bytes to serialize the
contained records (as obtained from serialized_len
), otherwise it’s
considered a violation of the API contract and the call may panic.
Trait Implementations§
source§impl<R, I> InnerPacketBuilder for RecordSequenceBuilder<R, I>where
R: RecordBuilder,
I: Iterator + Clone,
I::Item: Borrow<R>,
impl<R, I> InnerPacketBuilder for RecordSequenceBuilder<R, I>where R: RecordBuilder, I: Iterator + Clone, I::Item: Borrow<R>,
source§fn serialize(&self, buffer: &mut [u8])
fn serialize(&self, buffer: &mut [u8])
source§fn into_serializer(self) -> InnerSerializer<Self, EmptyBuf>where
Self: Sized,
fn into_serializer(self) -> InnerSerializer<Self, EmptyBuf>where Self: Sized,
source§fn into_serializer_with<B: ShrinkBuffer>(
self,
buffer: B
) -> InnerSerializer<Self, B>where
Self: Sized,
fn into_serializer_with<B: ShrinkBuffer>( self, buffer: B ) -> InnerSerializer<Self, B>where Self: Sized,
InnerPacketBuilder
into a Serializer
with a buffer
that can be used for serialization. Read more