Library to read and write protocol buffers data
Version 2 is stable
Currently developed branch of rust-protobuf is 3. It has the same spirit as version 2, but contains numerous improvements like:
- runtime reflection for mutability, not just for access
- protobuf text format and JSON parsing (which rely on reflection)
- dynamic message support: work with protobuf data without generating code from schema
Stable version of rust-protobuf will be supported until version 3 released.
How to generate rust code
There are several ways to generate rust code from
protoc programmatically with protoc-rust crate (recommended)
Have a look at readme in protoc-rust crate.
Use pure rust protobuf parser and code generator
Readme should be in protobuf-codegen-pure crate.
Use protoc-gen-rust plugin
Readme is here.
Have a look at generated files (for current development version), used internally in rust-protobuf:
- descriptor.rs for descriptor.proto (that is part of Google protobuf)
Copy on write
Rust-protobuf can be used with bytes crate.
Bytes you need to:
with-bytesfeature in rust-protobuf:
- Enable bytes option
Customize when codegen is invoked programmatically:
import "rustproto.proto"; option = true; option = true;
With these options enabled, fields of type
Chars respectively. When
CodedInputStream is constructed
Bytes object, fields of these types get subslices of original
instead of being allocated on heap.
protobuf-codegen-purecan be used to rust code from
protoccrate can be used to invoke
protoccommand packed into the crate.