Derive Macro fluvio_protocol_derive::Decoder[][src]

    // Attributes available to this derive:
Expand description

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


use std::io::Cursor;
use fluvio_protocol::Decoder;

#[derive(Default, Decoder)]
pub struct SimpleRecord {
    val: u8

let data = [

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

Decoder 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.

Decoder 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