[][src]Module exonum::proto

Protobuf generated structs and traits for conversion.

The central part of this module is ProtobufConvert. The main purpose of this trait is to allow users to create a map between their types and the types generated from .proto descriptions, while providing a mechanism for additional validation of protobuf data.

Most of the time you do not have to implement this trait because most of the use cases are covered by #[derive(ProtobufConvert)] from exonum_derive crate.

A typical example of such mapping with validation is manual implementation of this trait for crypto::Hash. crypto::Hash is a fixed sized array of bytes but protobuf does not allow us to express this constraint since only dynamically sized arrays are supported. If you would like to use Hash as a part of your protobuf struct, you would have to write a conversion function from protobuf proto::Hash(which is dynamically sized array of bytes) tocrypto::Hash and call it every time when you want to use crypto::Hash in your application.

The provided ProtobufConvert implementation for Hash allows you to embed this field into your struct and generate ProtobufConvert for it using #[derive(ProtobufConvert)], which will validate your struct based on the validation function for Hash.

Examples

extern crate exonum;
#[macro_use] extern crate exonum_derive;

use exonum::crypto::{PublicKey, Hash};

// See doc_tests.proto for protobuf definitions of this structs.

#[derive(ProtobufConvert)]
#[exonum(pb = "exonum::proto::schema::doc_tests::MyStructSmall")]
struct MyStructSmall {
    key: PublicKey,
    num_field: u32,
    string_field: String,
}

#[derive(ProtobufConvert)]
#[exonum(pb = "exonum::proto::schema::doc_tests::MyStructBig")]
struct MyStructBig {
    hash: Hash,
    my_struct_small: MyStructSmall,
}

Re-exports

pub use self::schema::blockchain::Block;
pub use self::schema::blockchain::ConfigReference;
pub use self::schema::blockchain::TransactionResult;
pub use self::schema::blockchain::TxLocation;
pub use self::schema::helpers::BitVec;
pub use self::schema::helpers::Hash;
pub use self::schema::helpers::PublicKey;
pub use self::schema::helpers::Signature;
pub use self::schema::protocol::BlockRequest;
pub use self::schema::protocol::BlockResponse;
pub use self::schema::protocol::Connect;
pub use self::schema::protocol::PeersRequest;
pub use self::schema::protocol::Precommit;
pub use self::schema::protocol::Prevote;
pub use self::schema::protocol::PrevotesRequest;
pub use self::schema::protocol::Propose;
pub use self::schema::protocol::ProposeRequest;
pub use self::schema::protocol::Status;
pub use self::schema::protocol::TransactionsRequest;
pub use self::schema::protocol::TransactionsResponse;

Modules

schema

Module with protobuf generated files from schema/exonum.

Traits

ProtobufConvert

Used for establishing correspondence between rust struct and protobuf rust struct