micropb
is a Rust implementation of the Protobuf format, with a focus on embedded environments. micropb
generates a Rust module from .proto
files.
Unlike other Rust Protobuf libraries, micropb
is aimed for constrained environments where no allocator is available. As such, micropb
offers a different set of tradeoffs compared to other Protobuf libraries.
- Supports no-std and no-alloc environments.
- Reduced memory usage for generated code, especially for optional fields.
- Allows both statically-allocated containers (
heapless
,arrayvec
) or dynamically-allocated containers fromalloc
. - Code generator is highly configurable.
- Fields can have custom handlers with user-defined encoding and decoding behaviour.
- Supports different data sources for encoding and decoding, abstracted behind the
PbRead
andPbWrite
traits.
- Does not support Protobuf Editions, RPC, or extensions.
- No reflection capabilities.
- No cycle detection for message fields, so users need to break cyclic references themselves by boxing the field or using a custom handler.
string
,bytes
, repeated, andmap
fields require some basic user configuration to get working.
The micropb
project consists of two crates:
-
micropb
: Encoding and decoding routines for the Protobuf wire data. The generated module will assume it's been imported as a regular dependency. -
micropb-gen
: Code generation tool that generates a Rust module from a set of.proto
files. Include this as a build dependency.
For a concrete example of micropb
on an embedded application, see arm-app
.
Documentation is at docs.rs.
The oldest version of Rust that micropb
supports is 1.83.0.
micropb
is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.