Skip to content

Commit 2d47d88

Browse files
estespmxpv
authored andcommitted
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 <[email protected]>
1 parent 2cb7714 commit 2d47d88

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

crates/client/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ pub async fn connect(
119119
Ok(channel)
120120
}
121121

122+
use prost::{Message, Name};
123+
use prost_types::Any;
124+
125+
// to_any provides a helper to match the current use of the protobuf "fullname" trait
126+
// in the Go code on the gRPC server side in containerd when handling matching of Any
127+
// types to registered types on the server. Further discussion on future direction
128+
// of typeurl in this issue: https://github.com/containerd/rust-extensions/issues/362
129+
pub fn to_any<T: Message + Name>(m: &T) -> Any {
130+
let mut anyt = Any::from_msg(m).unwrap();
131+
anyt.type_url = T::full_name();
132+
anyt
133+
}
134+
122135
/// Help to inject namespace into request.
123136
///
124137
/// To use this macro, the `tonic::Request` is needed.

0 commit comments

Comments
 (0)