Skip to content

XiangQingW/rust-protobuf

 
 

Repository files navigation

rust-protobuf

Build Status crates.io version License

Protobuf implementation in Rust.

  • Written in pure rust
  • Generate rust code
  • Has runtime library for generated code (Coded{Input|Output}Stream impl)

How to generate rust code

There are several ways to generate rust code from .proto files

Invoke protoc programmatically with protoc-rust crate (recommended)

Have a look at readme in protoc-rust crate.

Use pure rust protobuf parser and code generator (alpha)

Readme should be in protobuf-codegen-pure crate.

Use protoc-gen-rust plugin

Readme is here.

Generated code

Have a look at generated files, used internally in rust-protobuf:

Rustdoc

docs.rs hosts rustdoc for protobuf.

Copy-on-write

Rust-protobuf can be used with bytes crate.

To enable Bytes you need to:

  1. Enable with-bytes feature in rust-protobuf:
[dependencies]
protobuf = { version = "~1.6", features = ["with-bytes"] }
  1. 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.

Related projects

About

Rust implementation of Google protocol buffers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 99.4%
  • Other 0.6%