protoc-gen-prost-serde

A protoc plugin that generates [serde] serialization implementations that follow the conventions of protobuf-JSON.

When used in projects that use only Rust code, the preferred mechanism for generating protobuf definitions with Prost! is to use [prost-build] from within a build.rs file and then generate serde implementations using [pbjson-build]. However, when working in polyglot environments, it can be advantageous to utilize common tooling in the Protocol Buffers ecosystem. One common tool used for this purpose is [buf], which simplifies the code generation process and includes several useful features, including linting, package management, and breaking change detection.

Usage

Ensure that protoc-gen-prost-serde has been installed within a directory on your $PATH. Then invoke protoc from the command line as follows:

shell protoc --prost-serde_out=proto/gen -I proto proto/greeter/v1/greeter.proto

Options

This tool supports all the same options from pbjson-build. For more information on the effects of these settings, see the related documentation from that crate:

A note on parameter values:

Usage with buf

When used with buf, options can be specified in the buf.gen.yaml file. protoc-gen-prost-serde should appear as a plugin step after any protoc-gen-prost steps. In addition, the compile_well_known_types and extern_path=.google.protobuf=::pbjson_types options should be specified.

yaml version: v1 plugins: - name: prost out: gen opt: - compile_well_known_types - extern_path=.google.protobuf=::pbjson_types - name: prost-serde out: gen

protoc-gen-prost-serde is also compatible with the protoc-gen-prost-crate plugin:

yaml version: v1 plugins: - name: prost out: gen opt: - compile_well_known_types - extern_path=.google.protobuf=::pbjson_types - name: prost-serde out: gen - name: prost-crate strategy: all out: gen opt: - no_features