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§
source§impl 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§
source§impl Message for Any
impl Message for Any
source§fn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
true
for protobuf 3.source§fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
source§fn compute_size(&self) -> u64
fn compute_size(&self) -> u64
source§fn write_to_with_cached_sizes(
&self,
os: &mut CodedOutputStream<'_>,
) -> Result<()>
fn write_to_with_cached_sizes( &self, os: &mut CodedOutputStream<'_>, ) -> Result<()>
source§fn special_fields(&self) -> &SpecialFields
fn special_fields(&self) -> &SpecialFields
source§fn mut_special_fields(&mut self) -> &mut SpecialFields
fn mut_special_fields(&mut self) -> &mut SpecialFields
source§fn default_instance() -> &'static Any
fn default_instance() -> &'static Any
source§fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self>
source§fn cached_size(&self) -> u32
fn cached_size(&self) -> u32
compute_size
. Read moresource§fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<()>
source§fn write_length_delimited_to(
&self,
os: &mut CodedOutputStream<'_>,
) -> Result<()>
fn write_length_delimited_to( &self, os: &mut CodedOutputStream<'_>, ) -> Result<()>
source§fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<()>
fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<()>
source§fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()>
fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<()>
source§fn parse_from_reader(reader: &mut dyn Read) -> Result<Self>
fn parse_from_reader(reader: &mut dyn Read) -> Result<Self>
source§fn parse_from_bytes(bytes: &[u8]) -> Result<Self>
fn parse_from_bytes(bytes: &[u8]) -> Result<Self>
source§fn 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.source§fn check_initialized(&self) -> Result<()>
fn check_initialized(&self) -> Result<()>
source§fn write_length_delimited_to_writer(&self, w: &mut dyn Write) -> Result<()>
fn write_length_delimited_to_writer(&self, w: &mut dyn Write) -> Result<()>
source§fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>>
fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>>
source§fn unknown_fields(&self) -> &UnknownFields
fn unknown_fields(&self) -> &UnknownFields
source§fn mut_unknown_fields(&mut self) -> &mut UnknownFields
fn mut_unknown_fields(&mut self) -> &mut UnknownFields
source§impl MessageFull for Any
impl MessageFull for Any
source§fn descriptor() -> MessageDescriptor
fn descriptor() -> MessageDescriptor
source§fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool
fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool
source§impl ProtobufValue for Any
impl ProtobufValue for Any
source§type RuntimeType = RuntimeTypeMessage<Any>
type RuntimeType = RuntimeTypeMessage<Any>
impl StructuralPartialEq for Any
Auto Trait Implementations§
impl !Freeze for Any
impl RefUnwindSafe for Any
impl Send for Any
impl Sync for Any
impl Unpin for Any
impl UnwindSafe for Any
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<M> MessageDyn for Mwhere
M: MessageFull,
impl<M> MessageDyn for Mwhere
M: MessageFull,
source§fn descriptor_dyn(&self) -> MessageDescriptor
fn descriptor_dyn(&self) -> MessageDescriptor
source§fn merge_from_dyn(&mut self, is: &mut CodedInputStream<'_>) -> Result<(), Error>
fn merge_from_dyn(&mut self, is: &mut CodedInputStream<'_>) -> Result<(), Error>
source§fn write_to_with_cached_sizes_dyn(
&self,
os: &mut CodedOutputStream<'_>,
) -> Result<(), Error>
fn write_to_with_cached_sizes_dyn( &self, os: &mut CodedOutputStream<'_>, ) -> Result<(), Error>
source§fn compute_size_dyn(&self) -> u64
fn compute_size_dyn(&self) -> u64
source§fn is_initialized_dyn(&self) -> bool
fn is_initialized_dyn(&self) -> bool
true
for protobuf 3.