Skip to main content

Serialized

Derive Macro Serialized 

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

Derives a self-serialized outgoing type (Serialized in the core crate): Serialize means the framework’s codec does it, Serialized means it is already done by the user’s own type.

Covers the obvious shape - a newtype or single-field struct over an owned byte buffer - and emits the bytes accessor plus the wire spellings that route the type onto the serialized wire (MessageWire for a typed publish, ReplyShape for the reply position), so a handler returning it - or passing it to message(..) - publishes those bytes as they are.

A type that serializes itself names its format’s own writer with #[wire(encode = <path>)], and then holds fields rather than bytes: the path is a function fn(&Self, &mut impl BufMut), returning either nothing or Result<(), E>, and the derive calls it against the buffer the publish path already carries - so the value is encoded once, into the buffer that leaves. Nothing here depends on the format’s crate. #[wire(prost)] is the shorthand for prost::Message::encode.

ⓘ
#[derive(Serialized)]
struct Export(Vec<u8>);

#[subscriber("orders", publish("orders-wire"))]
async fn encode(order: &Order) -> Export { /* your wire format */ }

// What a generator's config puts on every message it emits.
#[derive(Clone, PartialEq, prost::Message, Serialized)]
#[wire(prost)]
struct OrderDone { #[prost(uint64, tag = "1")] id: u64 }