Crate tezos_data_encoding

source ·
Expand description

This crate provides serialization and deserialization functionality for the data types used by the Tezos shell.

You can either implement [NomReader] and [BinWriter] manually, or derive them.


Let’s create encodings for a struct containing two arrays - one of fixed size, and one dynamic.

Derivation is supported across generic structs.

use tezos_data_encoding::nom::NomReader;
use tezos_data_encoding::enc::BinWriter;
use tezos_data_encoding::encoding::HasEncoding;

const INNER_SIZE: usize = 10;

#[derive(Debug, PartialEq, HasEncoding, NomReader, BinWriter)]
struct Inner {
  #[encoding(sized = "INNER_SIZE", bytes)]
  fixed_size: Vec<u8>

#[derive(Debug, PartialEq, HasEncoding, NomReader, BinWriter)]
struct Outer<T>
where T: Debug + PartialEq + HasEncoding + for<'a> NomReader<'a> + BinWriter {
  dynamic_size: Vec<T>



  • Creates impl HasEncoding for given struct backed by lazy_static ref instance with encoding.