From c7c3ea08d74888bf85f63b25b546f2f9e3783475 Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Tue, 14 Jan 2025 17:59:24 -0500 Subject: [PATCH] Add a to_any helper in the containerd client crate This provides a solution to Any->type matching that happens on the containerd Go-based server side where the Any types in prost use typeurl as defined in the protobuf spec and the server side is matching on the fullname property of the type. Signed-off-by: Phil Estes --- crates/client/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 452da382..72a6c4e0 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -119,6 +119,19 @@ pub async fn connect( Ok(channel) } +use prost::{Message, Name}; +use prost_types::Any; + +// to_any provides a helper to match the current use of the protobuf "fullname" trait +// in the Go code on the gRPC server side in containerd when handling matching of Any +// types to registered types on the server. Further discussion on future direction +// of typeurl in this issue: https://github.com/containerd/rust-extensions/issues/362 +pub fn to_any(m: &T) -> Any { + let mut anyt = Any::from_msg(m).unwrap(); + anyt.type_url = T::full_name(); + anyt +} + /// Help to inject namespace into request. /// /// To use this macro, the `tonic::Request` is needed.