Trait ark_serialize::CanonicalSerialize[][src]

pub trait CanonicalSerialize {
    fn serialize<W: Write>(&self, writer: W) -> Result<(), SerializationError>;
fn serialized_size(&self) -> usize; fn serialize_uncompressed<W: Write>(
        &self,
        writer: W
    ) -> Result<(), SerializationError> { ... }
fn serialize_unchecked<W: Write>(
        &self,
        writer: W
    ) -> Result<(), SerializationError> { ... }
fn uncompressed_size(&self) -> usize { ... } }
Expand description

Serializer in little endian format. The serialization format must be ‘length-extension’ safe. e.g. if T implements Canonical Serialize and Deserialize, then for all strings x, y, if a = T::deserialize(Reader(x)) and a is not an error, then it must be the case that a = T::deserialize(Reader(x || y)), and that both readers read the same number of bytes.

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 ark_serialize::*;

#[derive(CanonicalSerialize)]
struct TestStruct {
    a: u64,
    b: (u64, (u64, u64)),
}

If your code depends on algebra instead, the example works analogously when importing algebra::serialize::*.

Required methods

Serializes self into writer. It is left up to a particular type for how it strikes the serialization efficiency vs compression tradeoff. For standard types (e.g. bool, lengths, etc.) typically an uncompressed form is used, whereas for algebraic types compressed forms are used.

Particular examples of interest: bool - 1 byte encoding uints - Direct encoding Length prefixing (for any container implemented by default) - 8 byte encoding Elliptic curves - compressed point encoding

Provided methods

Serializes self into writer without compression.

Serializes self into writer without compression, and without performing validity checks. Should be used only when there is no danger of adversarial manipulation of the output.

Implementations on Foreign Types

Implementors