#[non_exhaustive]pub struct Any(/* private fields */);
Expand description
Any
contains an arbitrary serialized protocol buffer message along with a
URL that describes the type of the serialized message.
§Example
let duration = Duration::clamp(123, 456);
let any = Any::from_msg(&duration)?;
let extracted = any.to_msg::<Duration>()?;
assert_eq!(extracted, duration);
let fail = any.to_msg::<Timestamp>();
assert!(matches!(fail, Err(AnyError::TypeMismatch{..})));
Protobuf library provides support to pack/unpack Any values in the form of utility functions or additional generated methods of the Any type.
§JSON
The JSON representation of an Any
value uses the regular
representation of the deserialized, embedded message, with an
additional field @type
which contains the type URL. Example:
package google.profile;
message Person {
string first_name = 1;
string last_name = 2;
}
{
"@type": "type.googleapis.com/google.profile.Person",
"firstName": <string>,
"lastName": <string>
}
If the embedded message type is well-known and has a custom JSON
representation, that representation will be embedded adding a field
value
which holds the custom JSON in addition to the @type
field. Example (for message [google.protobuf.Duration][]):
{
"@type": "type.googleapis.com/google.protobuf.Duration",
"value": "1.212s"
}
Implementations§
Source§impl Any
impl Any
Sourcepub fn type_url(&self) -> Option<&str>
pub fn type_url(&self) -> Option<&str>
Returns the name of the contained type.
§Example
use google_cloud_wkt::message::Message;
let any = Any::from_msg(&Duration::clamp(123, 456))?;
assert_eq!(any.type_url(), Some(Duration::typename()));
An Any
may contain any message type. The name of the message is a URL,
usually with the https://
scheme elided. All types in Google Cloud
APIs are of the form type.googleapis.com/${fully-qualified-name}
.
Note that this is not an available URL where you can download data (such as the message schema) from.