pub struct Any {
pub type_url: String,
pub value: Vec<u8>,
pub special_fields: SpecialFields,
}
Fields
type_url: String
A URL/resource name that uniquely identifies the type of the serialized
protocol buffer message. This string must contain at least
one “/” character. The last segment of the URL’s path must represent
the fully qualified name of the type (as in
path/google.protobuf.Duration
). The name should be in a canonical form
(e.g., leading “.” is not accepted).
In practice, teams usually precompile into the binary all types that they
expect it to use in the context of Any. However, for URLs which use the
scheme http
, https
, or no scheme, one can optionally set up a type
server that maps type URLs to message definitions as follows:
- If no scheme is provided,
https
is assumed. - An HTTP GET on the URL must yield a [google.protobuf.Type][] value in binary format, or produce an error.
- Applications are allowed to cache lookup results based on the URL, or have them precompiled into a binary to avoid any lookup. Therefore, binary compatibility needs to be preserved on changes to types. (Use versioned type names to manage breaking changes.)
Note: this functionality is not currently available in the official protobuf release, and it is not used for type URLs beginning with type.googleapis.com.
Schemes other than http
, https
(or the empty scheme) might be
used with implementation specific semantics.
value: Vec<u8>
Must be a valid serialized protocol buffer of the above specified type.
special_fields: SpecialFields
Implementations
sourceimpl Any
impl Any
sourcepub fn pack<M: MessageFull>(message: &M) -> Result<Any>
pub fn pack<M: MessageFull>(message: &M) -> Result<Any>
Pack any message into well_known_types::Any
value.
Examples
use protobuf::well_known_types::any::Any;
let message: &MyMessage = message;
let any = Any::pack(message)?;
assert!(any.is::<MyMessage>());
sourcepub fn pack_dyn(message: &dyn MessageDyn) -> Result<Any>
pub fn pack_dyn(message: &dyn MessageDyn) -> Result<Any>
Pack any message into well_known_types::Any
value.
Examples
use protobuf::{MessageFull, MessageDyn};
use protobuf::well_known_types::any::Any;
let message: &dyn MessageDyn = message;
let any = Any::pack_dyn(message)?;
assert!(any.is_dyn(&message.descriptor_dyn()));
sourcepub fn is<M: MessageFull>(&self) -> bool
pub fn is<M: MessageFull>(&self) -> bool
Check if Any
contains a message of given type.
sourcepub fn is_dyn(&self, descriptor: &MessageDescriptor) -> bool
pub fn is_dyn(&self, descriptor: &MessageDescriptor) -> bool
Check if Any
contains a message of given type.
sourcepub fn unpack<M: MessageFull>(&self) -> Result<Option<M>>
pub fn unpack<M: MessageFull>(&self) -> Result<Option<M>>
sourcepub fn unpack_dyn(
&self,
descriptor: &MessageDescriptor
) -> Result<Option<Box<dyn MessageDyn>>>
pub fn unpack_dyn(
&self,
descriptor: &MessageDescriptor
) -> Result<Option<Box<dyn MessageDyn>>>
Trait Implementations
sourceimpl Message for Any
impl Message for Any
sourcefn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
true
for protobuf 3. Read moresourcefn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
sourcefn compute_size(&self) -> u64
fn compute_size(&self) -> u64
sourcefn write_to_with_cached_sizes(
&self,
os: &mut CodedOutputStream<'_>
) -> Result<()>
fn write_to_with_cached_sizes(
&self,
os: &mut CodedOutputStream<'_>
) -> Result<()>
sourcefn special_fields(&self) -> &SpecialFields
fn special_fields(&self) -> &SpecialFields
sourcefn mut_special_fields(&mut self) -> &mut SpecialFields
fn mut_special_fields(&mut self) -> &mut SpecialFields
sourcefn default_instance() -> &'static Any
fn default_instance() -> &'static Any
sourcefn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
sourcefn cached_size(&self) -> u32
fn cached_size(&self) -> u32
compute_size
. Read moresourcefn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
sourcefn write_length_delimited_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
fn write_length_delimited_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
sourcefn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<()>
fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<()>
sourcefn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()>
fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()>
sourcefn parse_from_reader(reader: &mut dyn Read) -> Result<Self>
fn parse_from_reader(reader: &mut dyn Read) -> Result<Self>
sourcefn parse_from_bytes(bytes: &[u8]) -> Result<Self>
fn parse_from_bytes(bytes: &[u8]) -> Result<Self>
sourcefn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self>
fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self>
Bytes
object.
Resulting message may share references to the passed bytes object. Read more