Macro exonum::encoding_struct [] [src]

macro_rules! encoding_struct {
    (
    $(#[$attr:meta])*
    struct $name:ident {
        const SIZE = $body:expr;

        $(
        $(#[$field_attr:meta])*
        field $field_name:ident : $field_type:ty [$from:expr => $to:expr]
        )*
    }) => { ... };
}

encoding_struct! implement structure that could be saved in blockchain.

Storage value unlike message, could be mapped on buffers without any checks. For now it's required to set encoding_struct fixed part size as const SIZE.

For each field, it's required to set exact position in encoding_struct.

Usage Example:

#[macro_use] extern crate exonum;

encoding_struct! {
    struct SaveTwoInteger {
        const SIZE = 16;

        field first: u64 [0 => 8]
        field second: u64 [8 => 16]
    }
}
    let first = 1u64;
    let second = 2u64;
    let s = SaveTwoInteger::new(first, second);
    println!("Debug structure = {:?}", s);

For additional reference about data layout see also encoding documentation.

encoding_struct! internaly use ident_count!, be sure to add this macro to namespace.