Derive Macro matterdb_derive::BinaryValue[][src]

#[derive(BinaryValue)]
{
    // Attributes available to this derive:
    #[binary_value]
}

Derives BinaryValue trait. The target type must implement (de)serialization logic, which should be provided externally.

The trait currently supports the following codecs:

  • bincode serialization via the eponymous crate. Switched on by the #[binary_value(codec = "bincode")] attribute.

Container Attributes

codec

Selects the serialization codec to use. Allowed values are protobuf (used by default) and bincode.

Examples

With Protobuf serialization:

With bincode serialization:

#[derive(Clone, Debug, Serialize, Deserialize, BinaryValue)]
#[binary_value(codec = "bincode")]
pub struct Wallet {
    pub username: PublicKey,
    /// Current balance of the wallet.
    pub balance: u64,
}

let wallet = Wallet {
    username: "Alice".to_owned(),
    balance: 100,
};
let bytes = wallet.to_bytes();