[][src]Derive Macro fluvio_protocol_derive::Decode

    // Attributes available to this derive:

Custom derive for decoding structure or enum from bytes using fluvio protocol format. This assumes all fields implement fluvio decode traits.


use fluvio_protocol::Decoder;
use fluvio_protocol::derive::Decode;

pub struct SimpleRecord {
    val: u8

let data = [

let record = SimpleRecord::decode_from(&mut Cursor::new(&data),0).expect("decode");

Decode applies to either Struct of Enum. For enum, it implements TryFrom trait.
Currently it only supports integer variants.

So this works

pub enum ThreeChoice {
    First = 1,
    Second = 2,
    Third = 3

Also, enum without integer literal works as well

pub enum ThreeChoice {

In this case, 1 is decoded as First, 2 as Second, 3 as Third.

Currently, mixing enum variants are not supported.

Decode support container and field level attributes. Container level applies to struct. For field attributes

  • #[varint] force decode using varint format.
  • #fluvio(min_version = <version>)] decodes only if version is equal or greater than min_version
  • #fluvio(max_version = <version>)]decodes only if version is less or equal than max_version