A pure Rust library to deserialize protobuf files.
Simple codegen. No need of protoc. Fast.
Convert your .proto files into rust modules using included pb-rs crate
```sh git clone https://github.com/tafia/quick-protobuf cd quick-protobuf/codegen
cargo run /my/proto/path/my_file.proto ```
Import quick-protobuf into you crate
```toml
[dependencies] quick-protobuf = { git = "https://github.com/tafia/quick-protobuf" } ```
Use the generated module
```rust // main.rs or lib.rs extern crate quick_protobuf;
mod myfile; // generated with protorustcodegen
use std::io::Write; use quickprotobuf::{MessageRead, MessageWrite, Writer, Result}; use myfile::Foo;
fn main() { run("/path/to/my/binary/file.bin").unwrap(); }
fn run(p: &str) -> Result<()> { // Foo implements Message trait, thus we can directly deserialize .bin files let mut msg = Foo::from_file(p)?; println!("Deserialized msg: {:#?}", msg);
// Make some chanegs on msg
msg.repeated_field_1.clear();
// Write down updated message using any `Write` ...
let mut buf = Vec::with_capacity(msg.get_size());
{
let mut writer = Writer::new(&mut buf);
writer.write_message(&msg)?;
}
Ok(())
} ```
This library is an alternative to the widely used rust-protobuf.
Pros
Cons
Option
s unwrapping yourselfThe only implemented benchmarks are the adaptation from rust-protobuf perftest.