Skip to main content

TypewayCodec

Derive Macro TypewayCodec 

Source
#[derive(TypewayCodec)]
{
    // Attributes available to this derive:
    #[proto]
}
Expand description

Derive TypewayEncode and TypewayDecode for a struct.

Generates specialized encode/decode functions with no runtime dispatch. Each field is encoded/decoded directly based on its Rust type and proto tag number.

§Attributes

  • #[proto(tag = N)] — Set the protobuf field tag number (default: 1-indexed position)

§Supported field types

Rust typeProto typeWire type
u32uint32varint (0)
u64uint64varint (0)
i32int32varint (0)
i64int64varint (0)
boolboolvarint (0)
f32float32-bit (5)
f64double64-bit (1)
Stringstringlen-delimited (2)
Vec<u8>byteslen-delimited (2)
Vec<T>repeated T(varies)
Option<T>optional T(varies)

§Example

#[derive(TypewayCodec)]
struct User {
    #[proto(tag = 1)]
    id: u32,
    #[proto(tag = 2)]
    name: String,
    #[proto(tag = 3)]
    active: bool,
}