Struct protobuf::well_known_types::Any [−][src]
pub struct Any {
pub type_url: String,
pub value: Vec<u8>,
pub unknown_fields: UnknownFields,
pub cached_size: CachedSize,
}
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.
unknown_fields: UnknownFields
cached_size: CachedSize
Implementations
Pack any message into well_known_types::Any
value.
Examples
use protobuf::well_known_types::Any;
let message: &MyMessage = message;
let any = Any::pack(message)?;
assert!(any.is::<MyMessage>());
Pack any message into well_known_types::Any
value.
Examples
use protobuf::{Message, MessageDyn};
use protobuf::well_known_types::Any;
let message: &dyn MessageDyn = message;
let any = Any::pack_dyn(message)?;
assert!(any.is_dyn(&message.descriptor_dyn()));
Check if Any
contains a message of given type.
pub fn unpack_dyn(
&self,
descriptor: &MessageDescriptor
) -> ProtobufResult<Option<Box<dyn MessageDyn>>>
pub fn unpack_dyn(
&self,
descriptor: &MessageDescriptor
) -> ProtobufResult<Option<Box<dyn MessageDyn>>>
Trait Implementations
True iff all required fields are initialized.
Always returns true
for protobuf 3. Read more
Update this message object with fields read from given stream.
Compute and cache size of this message and all nested messages
Write message to the stream. Read more
Get size previously computed by compute_size
.
Get a reference to unknown fields.
Get a mutable reference to unknown fields.
Get message descriptor for message type. Read more
Return a pointer to default immutable message with static lifetime. Read more
Message descriptor for this message, used for reflection. Read more
Parse message from stream.
Write the message to the stream. Read more
Write the message to the stream prepending the message with message length encoded as varint. Read more
Write the message to the vec, prepend the message with message length encoded as varint. Read more
Update this message object with fields read from given stream.
Parse message from reader. Parse stops on EOF or when error encountered. Read more
Parse message from byte array.
Check if all required fields of this object are initialized.
Write the message to the writer.
Write the message to bytes vec.
Write the message to bytes vec. Read more
Write the message to the writer, prepend the message with message length encoded as varint. Read more
Write the message to the bytes vec, prepend the message with message length encoded as varint. Read more
Reflective equality. Read more
type RuntimeType = RuntimeTypeMessage<Self>
type RuntimeType = RuntimeTypeMessage<Self>
Actual implementation of type properties.
Dynamic version of the type.
Pointer to a dynamic reference.
Mutable pointer to a dynamic mutable reference.
Construct a value from given reflective value. Read more
Write the value.
Default value for this type.
Convert a value into a ref value if possible. Read more
Value is non-default?
Auto Trait Implementations
impl RefUnwindSafe for Any
impl UnwindSafe for Any
Blanket Implementations
Mutably borrows from an owned value. Read more