Macro exonum::message [] [src]

macro_rules! message {
    (
    $(#[$attr:meta])*
    struct $name:ident {
        const TYPE = $extension:expr;
        const ID = $id:expr;
        const SIZE = $body:expr;

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

message! implement structure that could be sent in exonum network.

Each message is a piece of data that is signed by creators key. For now it's required to set service id as const TYPE, message id as const ID, and message fixed part size as const SIZE.

  • service id should be unique inside whole exonum.
  • message id should be unique inside each service.

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

Usage Example:

#[macro_use] extern crate exonum;

const MY_SERVICE_ID: u16 = 777;
const MY_NEW_MESSAGE_ID: u16 = 1;

message! {
    struct SendTwoInteger {
        const TYPE = MY_NEW_MESSAGE_ID;
        const ID   = MY_SERVICE_ID;
        const SIZE = 16;

        field first: u64 [0 => 8]
        field second: u64 [8 => 16]
    }
}

    let (_, creators_key) = ::exonum::crypto::gen_keypair();

    let first = 1u64;
    let second = 2u64;
    SendTwoInteger::new(first, second, creators_key)

For additionall reference about data layout see also encoding documentation.

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