[protobuf] Encode arbitrary messages which are unknown at compile time

Hello community!

The most famous protobuf crates in rust (prost an rust-protobuf) generate rust code from proto files before compiling. This allows us to decode / encode the messages listed there at runtime.

But sometimes it is useful to handle messages which types are unknown at compile time.
An example implementation in c++ dynamic_message.h  |  Protocol Buffers  |  Google Developers.
I see reported issues in rust projects like Adding Reflection and DynamicMessge Support · Issue #301 · tokio-rs/prost · GitHub, so it hasn't been implemented there yet.

But maybe you've faced an implementation in rust that allows to de(en)encode messages just consuming the proto descriptor and the message itself at runtime?
I've found a protofish which should do this, but It would be interesting to find something based on prost or rust-protobuf crates.

Thank you in advance!

UPD

protofish:

  • does both encoding and decoding
  • doesn't cover the serialization/deserialization of JSON string

serde-protobuf

  • does only decoding but support
  • covers JSON deserialization

something ideal

  • does both encoding and decoding
  • covers both serialization and deserialization of JSON string
  • Note: good to base on serde for JSON ser/deser and rust-protobuf for encoding/decoding

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.