Struct Any

Source
pub struct Any {
    pub type_url: String,
    pub value: Vec<u8>,
}
Expand description

Any contains an arbitrary serialized protocol buffer message along with a URL that describes the type of the serialized message.

Protobuf library provides support to pack/unpack Any values in the form of utility functions or additional generated methods of the Any type.

§Example

Pack and unpack a message in Rust:

let foo1 = Foo { ... };
let any = Any::from_msg(&foo1)?;
let foo2 = any.to_msg::<Foo>()?;
assert_eq!(foo1, foo2);

The pack methods provided by protobuf library will by default use ‘type.googleapis.com/full.type.name’ as the type URL and the unpack methods only use the fully qualified type name after the last ‘/’ in the type URL, for example “foo.bar.com/x/y.z” will yield type name “y.z”.

§JSON

JSON serialization of Any cannot be made compatible with the specification. See https://github.com/influxdata/pbjson/issues/2 for more information.

At the moment, an Any struct will be serialized as a JSON object with two fields:

  • typeUrl (string): the type URL of the message
  • value (string): the base64-encoded serialized message

For example:

{
   "typeUrl": "type.googleapis.com/google.protobuf.Duration",
   "value": "Cg0KB2NvcnA="
}

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.

Implementations§

Source§

impl Any

Source

pub fn from_msg<M>(msg: &M) -> Result<Any, EncodeError>
where M: Name,

Serialize the given message type M as Any.

Source

pub fn to_msg<M>(&self) -> Result<M, DecodeError>
where M: Default + Name,

Decode the given message type M from Any, validating that it has the expected type URL.

Trait Implementations§

Source§

impl BorshDeserialize for Any

Source§

fn deserialize_reader<R>(reader: &mut R) -> Result<Any, Error>
where R: Read,

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for Any

Source§

fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write,

Source§

impl Clone for Any

Source§

fn clone(&self) -> Any

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Any

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Decode for Any

Source§

fn decode<I>(input: &mut I) -> Result<Any, Error>
where I: Input,

Attempt to deserialise the value from input.
Source§

fn decode_into<I>( input: &mut I, dst: &mut MaybeUninit<Self>, ) -> Result<DecodeFinished, Error>
where I: Input,

Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
Source§

fn skip<I>(input: &mut I) -> Result<(), Error>
where I: Input,

Attempt to skip the encoded value from input. Read more
Source§

fn encoded_fixed_size() -> Option<usize>

Returns the fixed encoded size of the type. Read more
Source§

impl Default for Any

Source§

fn default() -> Any

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Any

Source§

fn deserialize<D>( deserializer: D, ) -> Result<Any, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Encode for Any

Source§

fn encode_to<T>(&self, writer: &mut T)
where T: Output + ?Sized,

Convert self to a slice and append it to the destination.
Source§

fn size_hint(&self) -> usize

If possible give a hint of expected size of the encoding. Read more
Source§

fn encode(&self) -> Vec<u8>

Convert self to an owned vector.
Source§

fn using_encoded<R, F>(&self, f: F) -> R
where F: FnOnce(&[u8]) -> R,

Convert self to a slice and then invoke the given closure with it.
Source§

fn encoded_size(&self) -> usize

Calculates the encoded size. Read more
Source§

impl From<ClientState> for Any

Source§

fn from(value: ClientState) -> Any

Converts to this type from the input type.
Source§

impl From<ConsensusState> for Any

Source§

fn from(value: ConsensusState) -> Any

Converts to this type from the input type.
Source§

impl JsonSchema for Any

Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl Message for Any

Source§

fn encoded_len(&self) -> usize

Returns the encoded length of the message without a length delimiter.
Source§

fn clear(&mut self)

Clears the message, resetting all fields to their default.
Source§

fn encode(&self, buf: &mut impl BufMut) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message to a buffer. Read more
Source§

fn encode_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message to a newly allocated buffer.
Source§

fn encode_length_delimited( &self, buf: &mut impl BufMut, ) -> Result<(), EncodeError>
where Self: Sized,

Encodes the message with a length-delimiter to a buffer. Read more
Source§

fn encode_length_delimited_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message with a length-delimiter to a newly allocated buffer.
Source§

fn decode(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes an instance of the message from a buffer. Read more
Source§

fn decode_length_delimited(buf: impl Buf) -> Result<Self, DecodeError>
where Self: Default,

Decodes a length-delimited instance of the message from the buffer.
Source§

fn merge(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes an instance of the message from a buffer, and merges it into self. Read more
Source§

fn merge_length_delimited(&mut self, buf: impl Buf) -> Result<(), DecodeError>
where Self: Sized,

Decodes a length-delimited instance of the message from buffer, and merges it into self.
Source§

impl Name for Any

Source§

const PACKAGE: &'static str = PACKAGE

Package name this message type is contained in. They are domain-like and delimited by ., e.g. google.protobuf.
Source§

const NAME: &'static str = "Any"

Simple name for this Message. This name is the same as it appears in the source .proto file, e.g. FooBar.
Source§

fn type_url() -> String

Type URL for this Message, which by default is the full name with a leading slash, but may also include a leading domain name, e.g. type.googleapis.com/google.profile.Person. This can be used when serializing into the google.protobuf.Any type.
Source§

fn full_name() -> String

Fully-qualified unique name for this Message. It’s prefixed with the package name and names of any parent messages, e.g. google.rpc.BadRequest.FieldViolation. By default, this is the package name followed by the message name. Fully-qualified names must be unique within a domain of Type URLs.
Source§

impl PartialEq for Any

Source§

fn eq(&self, other: &Any) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Protobuf<Any> for ClientState

Source§

fn encode<B>(self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode into a buffer in Protobuf format. Read more
Source§

fn encode_length_delimited<B>(self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode with a length-delimiter to a buffer in Protobuf format. Read more
Source§

fn decode<B>(buf: B) -> Result<Self, Error>
where B: Buf,

Constructor that attempts to decode an instance from a buffer. Read more
Source§

fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>
where B: Buf,

Constructor that attempts to decode a length-delimited instance from the buffer. Read more
Source§

fn encoded_len(self) -> usize

Returns the encoded length of the message without a length delimiter. Read more
Source§

fn encode_vec(self) -> Vec<u8>

Encodes into a Protobuf-encoded Vec<u8>.
Source§

fn decode_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance from a Vec<u8> (or equivalent).
Source§

fn encode_length_delimited_vec(self) -> Vec<u8>

Encode with a length-delimiter to a Vec<u8> Protobuf-encoded message.
Source§

fn decode_length_delimited_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance with a length-delimiter from a Vec<u8> or equivalent.
Source§

impl Protobuf<Any> for ConsensusState

Source§

fn encode<B>(self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode into a buffer in Protobuf format. Read more
Source§

fn encode_length_delimited<B>(self, buf: &mut B) -> Result<(), Error>
where B: BufMut,

Encode with a length-delimiter to a buffer in Protobuf format. Read more
Source§

fn decode<B>(buf: B) -> Result<Self, Error>
where B: Buf,

Constructor that attempts to decode an instance from a buffer. Read more
Source§

fn decode_length_delimited<B>(buf: B) -> Result<Self, Error>
where B: Buf,

Constructor that attempts to decode a length-delimited instance from the buffer. Read more
Source§

fn encoded_len(self) -> usize

Returns the encoded length of the message without a length delimiter. Read more
Source§

fn encode_vec(self) -> Vec<u8>

Encodes into a Protobuf-encoded Vec<u8>.
Source§

fn decode_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance from a Vec<u8> (or equivalent).
Source§

fn encode_length_delimited_vec(self) -> Vec<u8>

Encode with a length-delimiter to a Vec<u8> Protobuf-encoded message.
Source§

fn decode_length_delimited_vec(v: &[u8]) -> Result<Self, Error>

Constructor that attempts to decode a Protobuf-encoded instance with a length-delimiter from a Vec<u8> or equivalent.
Source§

impl Serialize for Any

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<Any> for MsgEnvelope

Source§

type Error = DecodingError

The type returned in the event of a conversion error.
Source§

fn try_from( any_msg: Any, ) -> Result<MsgEnvelope, <MsgEnvelope as TryFrom<Any>>::Error>

Performs the conversion.
Source§

impl TypeInfo for Any

Source§

type Identity = Any

The type identifying for which type info is provided. Read more
Source§

fn type_info() -> Type

Returns the static type identifier for Self.
Source§

impl Eq for Any

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DecodeAll for T
where T: Decode,

Source§

fn decode_all(input: &mut &[u8]) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
Source§

impl<T> DecodeLimit for T
where T: Decode,

Source§

fn decode_all_with_depth_limit( limit: u32, input: &mut &[u8], ) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
Source§

fn decode_with_depth_limit<I>(limit: u32, input: &mut I) -> Result<T, Error>
where I: Input,

Decode Self with the given maximum recursion depth and advance input by the number of bytes consumed. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> KeyedVec for T
where T: Codec,

Source§

fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8>

Return an encoding of Self prepended by given slice.
Source§

impl<M> MessageExt for M
where M: Message,

Source§

fn to_bytes(&self) -> Result<Vec<u8>, EncodeError>

Serialize this protobuf message as a byte vector.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToVec for T
where T: Message,

Source§

fn to_vec(&self) -> Vec<u8>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S> Codec for S
where S: Decode + Encode,

Source§

impl<T, C> Convertible<C> for T
where T: TryFrom<C> + Into<C>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> EncodeLike<&&T> for T
where T: Encode,

Source§

impl<T> EncodeLike<&T> for T
where T: Encode,

Source§

impl<T> EncodeLike<&mut T> for T
where T: Encode,

Source§

impl<T> EncodeLike<Arc<T>> for T
where T: Encode,

Source§

impl<T> EncodeLike<Box<T>> for T
where T: Encode,

Source§

impl<T> EncodeLike<Cow<'_, T>> for T
where T: ToOwned + Encode,

Source§

impl<T> EncodeLike<Rc<T>> for T
where T: Encode,

Source§

impl<T> JsonSchemaMaybe for T

Source§

impl<T> StaticTypeInfo for T
where T: TypeInfo + 'static,