quick-protobuf

A pure Rust library to deserialize protobuf files.

Simple codegen. No need of protoc. Fast.

Getting started

  1. 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

    generate a /my/proto/path/my_file.rs module to import into your project

    cargo run /my/proto/path/my_file.proto ```

  2. Import quick-protobuf into you crate

    ```toml

    Cargo.toml

    [dependencies] quick-protobuf = { git = "https://github.com/tafia/quick-protobuf" } ```

  3. 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(())
    

    } ```

Objectives

This library is an alternative to the widely used rust-protobuf.

Benchmarks

The only implemented benchmarks are the adaptation from rust-protobuf perftest.