Protobuf implementation in Rust.
- Written in pure rust
- Generate rust code
- Has runtime library for generated code (Coded{Input|Output}Stream impl)
There are several ways to generate rust code from .proto
files
Have a look at readme in protoc-rust crate.
Readme should be in protobuf-codegen-pure crate.
Readme is here.
Have a look at generated files, used internally in rust-protobuf:
- descriptor.rs for descriptor.proto (that is part of Google protobuf)
docs.rs hosts rustdoc for protobuf.
Rust-protobuf can be used with bytes crate.
To enable Bytes
you need to:
- Enable
with-bytes
feature in rust-protobuf:
[dependencies]
protobuf = { version = "~1.6", features = ["with-bytes"] }
- Enable bytes option
with Customize when codegen is invoked programmatically:
protoc_rust::run(protoc_rust::Args {
...
customize: Customize {
carllerche_bytes_for_bytes: Some(true),
carllerche_bytes_for_string: Some(true),
..Default::default()
},
});
or in .proto
file:
import "rustproto.proto";
option (rustproto.carllerche_bytes_for_bytes_all) = true;
option (rustproto.carllerche_bytes_for_string_all) = true;
With these options enabled, fields of type bytes
or string
are
generated as Bytes
or Chars
respectively. When CodedInputStream
is constructed
from Bytes
object, fields of these types get subslices of original Bytes
object,
instead of being allocated on heap.
- quick-protobuf — alternative protobuf implementation in Rust
- prost — another protobuf implementation in Rust
- serde-protobuf
- grpc-rust — implementation of gRPC based on this library
- grpc-rs — another gRPC implementation for Rust