---
sidebar_position: 5
title: Protobuf
description: "A message generated by prost carries its own bytes with #[wire(prost)]: no serde, no codec feature, encoded once into the buffer that leaves."
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Protobuf
A message generated by `prost` carries its own bytes with `#[wire(prost)]`: no serde, no codec feature, encoded once into the buffer that leaves.
The message derives [`Serialized`](api:ruststream::Serialized) and [`Deserialized`](api:ruststream::Deserialized) next to `prost::Message`, and `#[wire(prost)]` tells both derives to call `prost`'s encoder and decoder.
The type then rides the [byte lanes](./bytes.md): a handler reads `&Order`, decoded by `prost` before the call, and a publish or a reply writes the value with `prost` into the publish path's own buffer.
No codec is resolved for the type anywhere, so the service builds with no codec feature.
In a real service `prost-build` generates the type: its `message_attribute` setting adds the derives and the `#[wire(prost)]` line to every message it emits.
The example writes the generated struct out by hand.
Another format uses the general form, `#[wire(encode = <path>, decode = <path>)]`, which names the format's own writer and reader: Cap'n Proto, FlatBuffers and a hand-rolled frame fit it.
A payload that `prost` cannot decode is a decode failure, settled by the subscriber's [failure policy](../failure-policy.md).
In the manual form the impls the derives write are spelled out, and `wire_bytes` and `from_payload` call `prost` directly.
## Example
The example builds with no codec feature:
```text
cargo test --example protobuf --no-default-features --features testing,macros,memory
```
<Tabs groupId="api">
<TabItem value="macros" label="Macros">
```rust reference="examples/protobuf.rs#message"
```
</TabItem>
<TabItem value="manual" label="Manual">
```rust reference="examples/manual/protobuf.rs#message"
```
</TabItem>
</Tabs>
The handler reads the message type, and the publish names no codec.
<Tabs groupId="api">
<TabItem value="macros" label="Macros">
```rust reference="examples/protobuf.rs#app"
```
</TabItem>
<TabItem value="manual" label="Manual">
```rust reference="examples/manual/protobuf.rs#app"
```
</TabItem>
</Tabs>