Trait scuttlebutt::serialization::SequenceSerializer
source · [−]pub trait SequenceSerializer<E>: Sized {
fn serialized_size(n: usize) -> usize;
fn new<W: Write>(dst: &mut W) -> Result<Self>;
fn write<W: Write>(&mut self, dst: &mut W, e: E) -> Result<()>;
fn finish<W: Write>(self, dst: &mut W) -> Result<()>;
}
Expand description
A way to serialize a sequence of elements.
The [Serializer::from_bytes
] and [Serializer::to_bytes
] methods for
require that elements serialize and deserialize to the byte boundary.
For algebraic structures like crate::field::F2
, where
each element can be represented in only one bit, using the to_bytes
and from_bytes
methods is 8x less efficient than just sending each bit of the elements.
To enable more efficient communication, we can use the SequenceSerializer
and
SequenceDeserializer
types to enable stateful serialization and deserialization.
Required Methods
sourcefn serialized_size(n: usize) -> usize
fn serialized_size(n: usize) -> usize
The exact number of bytes that will be written if n
elements are serialized.