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§
- prelude
- The
prelude
contains common traits and types a user of this library would want to have handy with a simple (single) import.
Structs§
- Bitlist
- A homogenous collection of a variable number of boolean values.
- Bitvector
- A homogenous collection of a fixed number of boolean values.
- List
- A homogenous collection of a variable number of values.
- Node
- A node in a merkle tree.
- U256
- An unsigned integer represented by 256 bits
- Vector
- A homogenous collection of a fixed number of values.
NOTE: a
Vector
of length0
is illegal.
Enums§
- Deserialize
Error - Deserialization errors.
- Instance
Error - An invalid value.
- Merkleization
Error - An error encountered during merkleization.
- Serialize
Error - Serialization errors.
- Simple
Serialize Error - Top-level error to wrap all other errors in this crate
- Type
Error - An invalid type.
Traits§
- Deserialize
- A data structure that can be deserialized using SSZ.
- Merkleized
- A
Merkleized
type provides a “hash tree root” following the SSZ spec. - Serialize
- A data structure that can be serialized using SSZ.
- Simple
Serialize SimpleSerialize
is a trait for types conforming to the SSZ spec.- Sized
Sized
is a trait for types that can provide sizing information relevant for the SSZ spec.
Functions§
- deserialize
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 is_valid_merkle_branch
verifies the Merkle proof against theroot
given the other metadata.- serialize
serialize
is a convenience function for taking a value that implementsSimpleSerialize
and attempting to encode it to aVec<u8>
according to the SSZ spec.