android13/external/rust/crates/protobuf
liiir1985 2ce6e41ceb 补上遗漏的文件 2024-07-06 11:13:13 +08:00
..
benches initial 2024-06-22 20:45:49 +08:00
out 补上遗漏的文件 2024-07-06 11:13:13 +08:00
src initial 2024-06-22 20:45:49 +08:00
.cargo_vcs_info.json initial 2024-06-22 20:45:49 +08:00
Android.bp initial 2024-06-22 20:45:49 +08:00
Cargo.toml initial 2024-06-22 20:45:49 +08:00
Cargo.toml.orig initial 2024-06-22 20:45:49 +08:00
LICENSE initial 2024-06-22 20:45:49 +08:00
LICENSE.txt initial 2024-06-22 20:45:49 +08:00
METADATA initial 2024-06-22 20:45:49 +08:00
MODULE_LICENSE_MIT initial 2024-06-22 20:45:49 +08:00
NOTICE initial 2024-06-22 20:45:49 +08:00
OWNERS initial 2024-06-22 20:45:49 +08:00
README.md initial 2024-06-22 20:45:49 +08:00
TEST_MAPPING initial 2024-06-22 20:45:49 +08:00
build.rs initial 2024-06-22 20:45:49 +08:00
cargo2android.json initial 2024-06-22 20:45:49 +08:00
regenerate.sh initial 2024-06-22 20:45:49 +08:00

README.md

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

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