After my gRPC From Scratch series, I realized how simple the Protobuf binary encoding actually is. My benchmarks comparing varints and fixed-size integers in Go got me experimenting with the binary encoding. I wanted to see what Protobuf would look like with different tradeoffs, more modern encoding techniques, and the ability to blind-decode message values. What if we kept .proto files and services, but swapped out the binary wire format underneath? That experiment turned into an encoding that I call OmniBuf.
Protobuf’s schema language and wire format are separate. A .proto file defines messages and services, while an encoding determines how message values are stored or sent. Protobuf already supports other encodings, including ProtoJSON and Text Format.
OmniBuf is a self-describing binary wire format built to work with .proto schemas, gRPC, and Connect, as well as plain native types in code. You can keep your .proto schemas and service definitions, though using OmniBuf for RPCs requires registering an OmniBuf codec on both the client and server. It keeps what makes Protobuf good for schema evolution, while changing the wire encoding to make a few different tradeoffs:
- Faster on modern CPUs: Replaces byte-by-byte LEB128 varints with prefix-varints whose encoded length can be determined from the first byte, encodes nested messages in a single forward pass, and encodes arrays and maps natively as length-prefixed containers.
- Blind-decodable without a schema: Expands the wire format to 16 explicit types (plus optional Field #0 field names), so a CLI, proxy, or debugger can inspect a raw
.obufpayload and distinguish strings, bytes, numbers, booleans, arrays, maps, and nested messages without the original Protobuf schema or guessing like protoscope does. - Cheap partial reads and edits: If you just want to read and write a field or two, you can skip full message decoding to read a single field and splice an updated value back in much faster than decoding the full message.
- Smoother on-ramp: Annotated structs with matching field numbers and types use the same OmniBuf wire format as generated code, so you can start with native types and move to
.protofiles later (or not!).
OmniBuf works both as an alternate encoding for .proto schemas and directly on native types across 12 languages.
Partial Reads and Splicing
Protobuf already lets you skip length-delimited fields like strings, bytes, and nested messages once you read their length. Integer varints take more work because you have to scan continuation bits one byte at a time to find where each number ends, and maps or non-packed repeated fields are split across separate tagged entries. OmniBuf puts an integer’s encoded width in its first byte and wraps whole arrays and maps as length-prefixed containers, so the reader hops directly from field to field:
We can also use these length-delimited fields to splice in an edited value without parsing and re-encoding the rest of the message. There is a full walkthrough of how this works on the website:
var view pb.OpaquePeerUpdate
_ = view.Unmarshal(pkt)
router := view.GetRouterId() // skips earlier fields by byte length
view.SetActive(false) // marks field #3 dirty
pkt = view.MarshalAppend(nil)
Plain Structs
I want to address an elephant in the room when talking about Protobuf. It’s weird. You’re defining types in a specialized language and need tooling to generate types in the language that you actually want to use. I can understand how that will turn people off from the format altogether. I wanted a way to use the format without the song and dance of Protobuf code generation.
With OmniBuf, you can use language features like Go struct tags (omnibuf:"1"), Rust derive macros, and TypeScript defineMessage definitions to emit the exact same messages as .proto generated code. The idea is that you can start with types that are native to your language of choice and then move to .proto files later with no change to the data on the wire:
// From .proto
protoPkt, _ := omnibuf.Marshal(&pb.Node{Id: 1, City: "FRA"})
// From a plain Go struct
type Node struct {
ID uint32 `omnibuf:"1"`
City string `omnibuf:"2"`
}
structPkt, _ := omnibuf.Marshal(&Node{ID: 1, City: "FRA"})
This gives you an on-ramp to OmniBuf without having to buy into the schema-first design philosophy. I think schema-first design is worth it, but I don’t want that to get in the way of using a more efficient message format.
Benchmarks and Tradeoffs
Okay, so how fast is OmniBuf, really? I expected these changes to help. I didn’t expect gains this large.
These charts compare OmniBuf’s generated codecs with Protobuf implementations in 11 languages, using an 11-field PeerUpdate message on an Apple M1 Pro. The Protobuf baselines include google.golang.org/protobuf in Go, prost in Rust, and protobuf-java in Java. Full methodology, library versions, and non-codegen struct benchmarks are on the benchmark page.
Other formats still beat OmniBuf in a few areas. On the PeerUpdate fixture, Protobuf produces 341 bytes to OmniBuf’s 366 bytes. OmniBuf is also still early and experimental compared to Protobuf’s two decades in production. FlatBuffers and Cap’n Proto are faster at reading a single field from large messages by using offset tables. JSON loses on every benchmarked metric here (encode speed, decode speed, and payload size), though it is still the only format on the list you can read directly as text.
Languages and Tooling
There are first-party runtimes and plugins for Buf and protoc across 12 languages, all verified against the same conformance suite so behavior stays consistent across ecosystems:
- Go
- TypeScript / JS
- Rust
- Python
- C++
- C99 / Embedded (Nano): zero-allocation runtime for microcontrollers
- Java
- C# / .NET
- Swift
- Dart
- PHP
- Elixir
I also made a CLI to convert OmniBuf messages to and from JSON, and to inspect raw .obuf payloads without a schema. Because the wire types don’t collide, blind-decoding a packet gives you typed values instead of protoscope’s guesses:
# Blind-decoding a raw packet with no .proto file:
$ omnibuf -c packet.obuf
{"field_1": true, "field_2": -2, "field_3": "FRA", "field_4": [10, 20]}
# With optional Field #0 metadata enabled:
$ omnibuf -c packet-field0.obuf
{"active": true, "delta": -2, "city": "FRA", "peers": [10, 20]}
You can also pipe JSON in or run jq queries directly against binary messages:
brew install omnibuf/tap/omnibuf
# or: mise use -g github:omnibuf/omnibuf-cli
omnibuf < event.json > event.obuf
omnibuf -r '.neighbors[] | select(.established) | .router' event.obuf
I also made editor extensions for VS Code (omnibuf-vscode) and Vim / Neovim (omnibuf-vim).
omnibuf.comFast, self-describing binary wire format for Protocol Buffers and native types.