pub trait CanonicalSerialize {
// Required methods
fn serialize_with_mode<W: Write>(
&self,
writer: W,
compress: Compress
) -> Result<(), SerializationError>;
fn serialized_size(&self, compress: Compress) -> usize;
// Provided methods
fn serialize_compressed<W: Write>(
&self,
writer: W
) -> Result<(), SerializationError> { ... }
fn compressed_size(&self) -> usize { ... }
fn serialize_uncompressed<W: Write>(
&self,
writer: W
) -> Result<(), SerializationError> { ... }
fn uncompressed_size(&self) -> usize { ... }
}
Expand description
Serializer in little endian format.
This trait can be derived if all fields of a struct implement
CanonicalSerialize
and the derive
feature is enabled.
§Example
// The `derive` feature must be set for the derivation to work.
use snarkvm_utilities::serialize::*;
#[derive(CanonicalSerialize)]
struct TestStruct {
a: u64,
b: (u64, (u64, u64)),
}
Required Methods§
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
Provided Methods§
fn serialize_compressed<W: Write>( &self, writer: W ) -> Result<(), SerializationError>
fn compressed_size(&self) -> usize
fn serialize_uncompressed<W: Write>( &self, writer: W ) -> Result<(), SerializationError>
fn uncompressed_size(&self) -> usize
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl CanonicalSerialize for bool
impl CanonicalSerialize for bool
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, _compress: Compress) -> usize
source§impl CanonicalSerialize for u8
impl CanonicalSerialize for u8
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, _compress: Compress) -> usize
source§impl CanonicalSerialize for u16
impl CanonicalSerialize for u16
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, _compress: Compress) -> usize
source§impl CanonicalSerialize for u32
impl CanonicalSerialize for u32
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, _compress: Compress) -> usize
source§impl CanonicalSerialize for u64
impl CanonicalSerialize for u64
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, _compress: Compress) -> usize
source§impl CanonicalSerialize for usize
impl CanonicalSerialize for usize
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, _compress: Compress) -> usize
source§impl CanonicalSerialize for String
impl CanonicalSerialize for String
fn serialize_with_mode<W: Write>( &self, writer: W, _compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, _compress: Compress) -> usize
source§impl<'a, T: CanonicalSerialize + ToOwned> CanonicalSerialize for Cow<'a, T>
impl<'a, T: CanonicalSerialize + ToOwned> CanonicalSerialize for Cow<'a, T>
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
source§impl<'a, T: CanonicalSerialize> CanonicalSerialize for &'a [T]
impl<'a, T: CanonicalSerialize> CanonicalSerialize for &'a [T]
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
source§impl<A, B> CanonicalSerialize for (A, B)where
A: CanonicalSerialize,
B: CanonicalSerialize,
impl<A, B> CanonicalSerialize for (A, B)where
A: CanonicalSerialize,
B: CanonicalSerialize,
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
source§impl<A, B, C> CanonicalSerialize for (A, B, C)
impl<A, B, C> CanonicalSerialize for (A, B, C)
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
source§impl<A, B, C, D> CanonicalSerialize for (A, B, C, D)
impl<A, B, C, D> CanonicalSerialize for (A, B, C, D)
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
source§impl<K, V> CanonicalSerialize for BTreeMap<K, V>where
K: CanonicalSerialize,
V: CanonicalSerialize,
impl<K, V> CanonicalSerialize for BTreeMap<K, V>where
K: CanonicalSerialize,
V: CanonicalSerialize,
source§fn serialize_with_mode<W: Write>(
&self,
writer: W,
compress: Compress
) -> Result<(), SerializationError>
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress ) -> Result<(), SerializationError>
Serializes a BTreeMap
as len(map) || key 1 || value 1 || ... || key n || value n
.