#protobuf #codegen #serialization #pure

build protobuf-codegen-pure

Pure-rust codegen for protobuf using protobuf-parser crate WIP

66 stable releases

3.0.0-alpha.2 Nov 1, 2021
2.28.0 Sep 26, 2022
2.27.1 Feb 5, 2022
2.25.2 Oct 24, 2021
1.6.0 May 11, 2018

#1325 in Encoding

Download history 21940/week @ 2023-10-20 19797/week @ 2023-10-27 19170/week @ 2023-11-03 18272/week @ 2023-11-10 17619/week @ 2023-11-17 17922/week @ 2023-11-24 17620/week @ 2023-12-01 18636/week @ 2023-12-08 18785/week @ 2023-12-15 13082/week @ 2023-12-22 13414/week @ 2023-12-29 20115/week @ 2024-01-05 18095/week @ 2024-01-12 20067/week @ 2024-01-19 19789/week @ 2024-01-26 15484/week @ 2024-02-02

76,470 downloads per month
Used in fewer than 33 crates

MIT license

2MB
40K SLoC

API to generate .rs files

API to generate .rs files to be used e. g. from build.rs.

Example code:

With stable rust-protobuf:

extern crate protobuf_codegen_pure;

protobuf_codegen_pure::run(protobuf_codegen_pure::Args {
    out_dir: "src/protos",
    input: &["protos/a.proto", "protos/b.proto"],
    includes: &["protos"],
    customize: protobuf_codegen_pure::Customize {
      ..Default::default()
    },
}).expect("protoc");

With rust-protobuf from master:

extern crate protobuf_codegen_pure;

protobuf_codegen_pure::Args::new()
    .out_dir("src/protos")
    .inputs(&["protos/a.proto", "protos/b.proto"])
    .include("protos")
    .run()
    .expect("protoc");

And in Cargo.toml:

[build-dependencies]
protobuf-codegen-pure = "2.3"

The alternative is to use protoc-rust crate, which relies on protoc command to parse descriptors. Both crates should produce the same result, otherwise please file a bug report.

Dependencies

~2–13MB
~145K SLoC