Skip to content

Commit

Permalink
Add a to_any helper in the containerd client crate
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
estesp authored and mxpv committed Jan 16, 2025
1 parent 2cb7714 commit 2d47d88
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Message + Name>(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.
Expand Down

0 comments on commit 2d47d88

Please sign in to comment.