pbrs
A high-performance, pure-Rust Protocol Buffers kernel with the Google protobuf v4 application API.
pbrs provides full support for Protocol Buffers (proto2, proto3, and Editions 2023) with zero C/C++ dependencies, zero unsafe in application code, and 100% official Google conformance.
Why pbrs?
- Pure Rust: No C or C++ compiler required. Unlike crates.io
protobuf4.x (which wraps Google'supbC library via FFI),pbrscompiles entirely withrustc. - Google Protobuf v4 API: Matches the official Google Rust application API traits and shapes (
Parse,Serialize,Clear,proto!,ProtoStr,RepeatedView,DynamicMessage). - 100% Conformance: Passes Google's official
conformance_test_runnerv35.1 (5,631 binary + JSON tests, 909 text tests, 0 unexpected failures, 0 skips). - Prost Alternative: Unlike Prost, which uses custom derive traits and layout conventions,
pbrsgives you the standard protobuf v4 API, exact proto3 presence semantics, WKT support, dynamic reflection, and field-wise JSON/Text formatting. - Fast & Memory Efficient: Single-pass parsing with small-string optimization (SSO), zero-allocation empty collections, lazy sub-message parsing, and vectorized packed-scalar decoding.
Workspace Crates
| Crate | Description | crates.io Status |
|---|---|---|
pbrs |
The core Protocol Buffers kernel: parser, serializer, codegen (protoc-gen-pbrs), dynamic messages, WKT, and JSON/text format. |
0.1.0 (Production Ready) |
pbrs-grpc |
A standalone, pure-Rust HTTP/2 gRPC client and server kernel (no C, no tonic). Built on rustls + Graviola. |
0.1.0-alpha.1 (Pre-release / Preview) |
protobuf-tonic |
A tonic 0.14+ Codec adapter allowing tonic servers and clients to use pbrs message types. |
0.1.0-alpha.1 (Pre-release / Preview) |
examples/greeter |
A complete working example showing generated stubs, health checks, and server reflection. | Example only (publish = false) |
Installation
Add pbrs to your Cargo.toml:
[]
= "0.1"
(Until published to crates.io, you can point to the git repository:)
[]
= { = "https://github.com/mingley/pure-protobuf" }
Code Generation
protoc must be installed and available on your PATH.
Option A: Using build.rs (Recommended)
Add pbrs as a build dependency in your Cargo.toml:
[]
= "0.1"
In your build.rs:
Then include the generated code in your src/lib.rs or src/main.rs:
include!;
Option B: Using protoc-gen-pbrs Plugin
Install or build the plugin binary:
Run protoc with the --pbrs_out flag:
Or using the helper script:
Quickstart Example
Given a proto file (proto/person.proto):
syntax = "proto3";
package tutorial;
message Person {
string name = 1;
int32 id = 2;
string email = 3;
repeated string phones = 4;
}
Using the generated struct:
use *;
gRPC Integration
You can use pbrs messages with either gRPC stack:
pbrs-grpc(Pure-Rust Kernel): If you want a lightweight, pure-Rust gRPC stack withouttonic, C dependencies, orunsafein the transport layer. See the gRPC Guide andpbrs-grpc/README.md.protobuf-tonic(Tonic Adapter): If you have an existingtonic0.14+ service and want to drop inpbrsmessages instead ofprost. Seeprotobuf-tonic/README.md.
For a complete end-to-end example with service stubs, gRPC health checking (grpc.health.v1), and server reflection (grpc.reflection.v1), check out examples/greeter.
Comparison with Alternatives
| Feature | pbrs |
protobuf 4.x (upb) |
prost |
pb-rs |
|---|---|---|---|---|
| Pure Rust | Yes (No C/C++) | No (wraps C library via FFI) | Yes | Yes |
| API Shape | Google Protobuf v4 | Google Protobuf v4 | Custom Prost traits | Custom traits |
| Official Conformance | 100% (5,631 binary/JSON + 909 text) | Passes with skip list | Partial (binary only) | Partial |
| Proto Editions | proto2, proto3, Edition 2023 | proto2, proto3, Edition 2023 | proto2, proto3 | proto2, proto3 |
| Well-Known Types (WKT) | Built-in (Timestamp, Duration, Any, etc.) | Built-in | prost-types |
Minimal |
| JSON & Text Format | Field-wise & Dynamic conformance | C++ / upb implementation | Optional third-party | No |
| Dynamic Messages | Full descriptor reflection | Full reflection | None | None |
| gRPC Options | Native pbrs-grpc OR tonic |
Google gRPC | tonic-prost |
None |
Conformance & Testing
pbrs is tested against Google's official protobuf test suite:
- Official
conformance_test_runnerv35.1:- Required tests (×2): 5,631 binary + JSON, 0 unexpected failures.
- Text format tests: 909 text tests, 0 unexpected failures.
- Recommended tests (
--enforce_recommended): Passed with 0 unexpected failures. - Skip list: None. Unlike
upb, which maintains a skip list for proto2 UTF-8,pbrspasses all tests without exclusions.
Run the conformance suite locally:
Documentation
- Architecture Overview — Module organization and crate boundaries.
- Design & Internals — Memory layout, parsing strategy, and optimization techniques.
- Relative to upb — Detailed comparison with Google's C-based upb kernel.
- Benchmarks & Performance — Unary, streaming, and throughput measurements.
- Implementation Status — Supported features, conformance breakdown, and roadmap.
- Native gRPC Kernel Guide — In-depth guide to building microservices with
pbrs-grpc. - Tonic Adapter Guide — Using
pbrswith tonic 0.14+. - Release Policy & Publishing — Automated crates.io publication workflows and tag conventions.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.