Expand description
An implementation of the SSZ serialization scheme.
Examples
De/serialize a simple value:
let mut buf = Vec::new();
42u64.serialize(&mut buf);
assert_eq!(u64::deserialize(&buf).unwrap(), 42);
De/serialize a custom type using the derive macro:
#[derive(Debug, Default, PartialEq, Eq, SimpleSerialize)]
struct Data {
flag: bool,
value: u64
}
let mut buf = Vec::new();
Data { flag: true, value: 42 }.serialize(&mut buf);
assert_eq!(
Data::deserialize(&buf).unwrap(),
Data { flag: true, value: 42 }
);
Re-exports
pub use crate::SimpleSerialize;
pub use crate::Sized;
Modules
- The
prelude
contains common traits and types a user of this library would want to have handy with a simple (single) import.
Structs
- A homogenous collection of a variable number of boolean values.
- A homogenous collection of a fixed number of boolean values.
- A homogenous collection of a variable number of values.
- A node in a merkle tree.
- An unsigned integer represented by 256 bits
- A homogenous collection of a fixed number of values. NOTE: a
Vector
of length0
is illegal.
Enums
- Deserialization errors.
- An invalid value.
- An error encountered during merkleization.
- Serialization errors.
- Top-level error to wrap all other errors in this crate
- An invalid type.
Traits
- A data structure that can be deserialized using SSZ.
- A
Merkleized
type provides a “hash tree root” following the SSZ spec. - A data structure that can be serialized using SSZ.
SimpleSerialize
is a trait for types conforming to the SSZ spec.Sized
is a trait for types that can provide sizing information relevant for the SSZ spec.
Functions
deserialize
is a convenience function for taking an encoding for some value that implementsSimpleSerialize
in a&[u8]
and attempting to deserialize that value from the byte representation.is_valid_merkle_branch
verifies the Merkle proof against theroot
given the other metadata.serialize
is a convenience function for taking a value that implementsSimpleSerialize
and attempting to encode it to aVec<u8>
according to the SSZ spec.