I have a hobby project to build out a ProtoBuf mapping for the Envoy proxy service in order to make it straightforward to build a control plane for Envoy in Rust. I have been using the excellent prost
crate to do code generation from .proto
definition files provided by Envoy (and its dependencies on google/api
, etc.)
After a lot of fussing, I was able to get it working after sandboxing a lot of ProtoBuf dependencies that Envoy requires across multiple projects.
There is currently a limitation in Prost that forces codegen to use the exact same package structure scheme as the ProtoBuf package definitions specify, which limits some flexibility on packaging the types, as I don't want my crate to ship top-level packages like google
and envoy
, which are presumably taken by other crates.
Another thing not yet supported by Prost is the ProtoBuf canonical JSON mapping scheme which could be implemented fairly trivially with Serde. Most of the ProtoBuf to JSON mapping rules can already be expressed by Serde with normal Serde annotations, with the exception of the @type
field used to uniquely identify types.
The ProtoBuf canonical JSON mapping is especially interesting to me so I can more easily debug items and support Envoy's JSON REST API directly without needing to go full HTTP/2 gRPC.
I'd like to start a discussion between the Prost and Serde maintainers to try to see if there's a way for us to bridge our community efforts together. Many frameworks such as Actix like the idea of using serde::{Serialize, Deserialize}
types for returning HTTP responses without much developer overhead.
The way I see it, we'd need to do the following things:
- Build a new serializer/deserializer for ProtoBuf types for Serde.
- Add
#[protobuf]
tags to allow specifying the various ProtoBuf metadata necessary for ProtoBuf de/serialization. - Allow optionally setting the ProtoBuf package and type via a container-level attribute, e.g.
#[protobuf(package="envoy.api.v2.core")]
- Enhance and use Prost's codegen to generate code that seamlessly can serialize/deserialize JSON/YAML/ProtoBuf from the same structs.
I know that ProtoBufs kind of extend beyond the normal things that Serde has to do, but I see mainlining ProtoBufs as pretty important to enable more use-cases for Rust, especially in my case as a control plane for Envoy.
I'm not exactly sure how to contact the maintainers, but if anyone knows how to get in touch with them, please forward along this thread. I'd like to see how I and others can contribute to a more straightforward future with ProtoBufs and gRPC in Rust