Derive Macro concordium_std::Serial

#[derive(Serial)]
{
    // Attributes available to this derive:
    #[concordium]
}
Expand description

Derive the Serial trait for the type.

If the type is a struct all fields must implement the Serial trait. If the type is an enum then all fields of each of the enums must implement the Serial trait.

Collections (Vec, BTreeMap, BTreeSet) and strings (String, str) are by default serialized by prepending the number of elements as 4 bytes little-endian. If this is too much or too little, fields of the above types can be annotated with size_length.

The value of this field is the number of bytes that will be used for encoding the number of elements. Supported values are 1, 2, 4, 8.

For BTreeMap and BTreeSet the serialize method will serialize values in increasing order of keys.

Fields of structs are serialized in the order they appear in the code.

Enums can have no more than 65536 variants. They are serialized by using a tag to indicate the variant, enumerating them in the order they are written in source code. If the number of variants is less than or equal 256 then a single byte is used to encode it. Otherwise two bytes are used for the tag, encoded in little endian.

Example

#[derive(Serial)]
struct Foo {
    #[concordium(size_length = 1)]
    bar: BTreeSet<u8>,
}