[−][src]Crate ssz
Provides encoding (serialization) and decoding (deserialization) in the SimpleSerialize (SSZ) format designed for use in Ethereum 2.0.
Conforms to v0.7.1 of the Ethereum 2.0 specification.
Example
use ssz_derive::{Encode, Decode}; use ssz::{Decode, Encode}; #[derive(PartialEq, Debug, Encode, Decode)] struct Foo { a: u64, b: Vec<u16>, } fn main() { let foo = Foo { a: 42, b: vec![1, 3, 3, 7] }; let ssz_bytes: Vec<u8> = foo.as_ssz_bytes(); let decoded_foo = Foo::from_ssz_bytes(&ssz_bytes).unwrap(); assert_eq!(foo, decoded_foo); }
See examples/
for manual implementations of the Encode
and Decode
traits.
Macros
impl_decode_via_from | Implements |
impl_encode_via_from | Implements |
Structs
SszDecoder | Decodes some slices of SSZ into object instances. Should be instantiated using
|
SszDecoderBuilder | Builds an |
SszEncoder | Allow for encoding an ordered series of distinct or indistinct objects as SSZ bytes. |
Enums
DecodeError | Returned when SSZ decoding fails. |
Constants
BYTES_PER_LENGTH_OFFSET | The number of bytes used to represent an offset. |
MAX_LENGTH_VALUE |
Traits
Decode | Provides SSZ decoding (de-serialization) via the |
Encode | Provides SSZ encoding (serialization) via the |
Functions
decode_list_of_variable_length_items | Decodes |
ssz_encode | Convenience function to SSZ encode an object supporting ssz::Encode. |