-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable type names for Protocol Buffer message types to support Any
decoding.
#262
Conversation
Any
decoding.
could you add an example in https://github.com/containerd/rust-extensions/tree/main/crates/client/examples that demonstrates this? It would also ensure we have a way to validate it. |
I think a unit test with decoding should do it ? Generally the PR is SGTM. |
I pushed both a unit test and an example of listening for and decoding event payloads. Admittedly, I have not yet tested the example. |
Alright, I ended up testing this and it seems to work, but with one caveat. You'll see in the example that I had to futz with the type URL field for the The Protocol Buffers definition for Either way, the functionality does work, so long as we adjust the type URL to make Example output:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I tried this out and it is working.
LGTM
Context
When using something like
EventsClient::subscribe
, theEnvelope
value returned provides the event data (if any) behindprost_types::Any
.This value can be fallibly decoded to the underlying type (such as
containerd_client::events::ContainerCreate
for a container create event) by usingAny::to_msg<M>
, but only ifM
implementsName
.Currently, based on how
tonic_build
is used to do the codegen, theName
trait is not implemented for any of the generated message types, making decoding much harder to do.Solution
This PR is a simple change that simply provides additional configuration in
build.rs
, enabling the generation ofName
implementations for message types.Builder::compile_with_config
simply re-applies any of its own configuration on top of the configuration value given, so we're essentially just starting with a base of "enable typeName
generation" and whatever else comes after (viatonic_build::configure()...
) gets applied on top.