protobuf3

Crates.ioprotobuf3
lib.rsprotobuf3
version2.27.2
sourcesrc
created_at2022-09-07 09:42:44.504961
updated_at2022-09-07 09:42:44.504961
descriptionRust implementation of Google protocol buffers
homepagehttps://github.com/Tim-Zhang/rust-protobuf/blob/protobuf3/README.md
repositoryhttps://github.com/Tim-Zhang/rust-protobuf/blob/protobuf3
max_upload_size
id660263
size1,173,967
Tim Zhang (Tim-Zhang)

documentation

https://github.com/Tim-Zhang/rust-protobuf/blob/protobuf3/README.md

README

It's a modification version based on rust-protobuf@2.27

Changes

  • proto3 optional support

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.

Tracking issue for version 3.

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

Readme should be in protobuf-codegen-pure crate.

Use protoc-gen-rust plugin

Readme is here.

Generated code

Have a look at generated files (for current development version), used internally in rust-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 = "~2.0", 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.

Accompanying crates

Commit count: 0

cargo fmt