pub struct Any {
pub type_url: String,
pub value: Vec<u8>,
/* private fields */
}Fields§
§type_url: StringField 1: type_url
value: Vec<u8>Field 2: value
Implementations§
Source§impl Any
impl Any
Sourcepub fn pack(msg: &impl Message, type_url: impl Into<String>) -> Self
pub fn pack(msg: &impl Message, type_url: impl Into<String>) -> Self
Pack a message into an Any with the given type URL.
The type URL is conventionally of the form
type.googleapis.com/fully.qualified.TypeName, but this method does
not enforce that convention — any string is accepted.
Sourcepub fn unpack_unchecked<T: Message>(&self) -> Result<T, DecodeError>
pub fn unpack_unchecked<T: Message>(&self) -> Result<T, DecodeError>
Unpack the contained message, decoding its bytes as T, without
checking the type_url.
This method always attempts to decode the payload as T regardless
of whether type_url actually identifies T. Use Any::unpack_if
when you need to verify the stored type before decoding.
§Errors
Returns a buffa::DecodeError if the bytes cannot be decoded as T.
Sourcepub fn unpack_if<T: Message>(
&self,
expected_type_url: &str,
) -> Result<Option<T>, DecodeError>
pub fn unpack_if<T: Message>( &self, expected_type_url: &str, ) -> Result<Option<T>, DecodeError>
Unpack the contained message as T, but only if the type_url
matches expected_type_url.
Returns Ok(None) when the type URL does not match.
§Errors
Returns a buffa::DecodeError if the type URL matches but the bytes
cannot be decoded as T.
Trait Implementations§
Source§impl<'arbitrary> Arbitrary<'arbitrary> for Any
impl<'arbitrary> Arbitrary<'arbitrary> for Any
Source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl DefaultInstance for Any
impl DefaultInstance for Any
Source§fn default_instance() -> &'static Self
fn default_instance() -> &'static Self
Source§impl<'de> Deserialize<'de> for Any
Available on crate feature json only.
impl<'de> Deserialize<'de> for Any
json only.Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl Message for Any
impl Message for Any
Source§fn compute_size(&self) -> u32
fn compute_size(&self) -> u32
Returns the total encoded size in bytes.
The result is a u32; the protobuf specification requires all
messages to fit within 2 GiB (2,147,483,647 bytes), so a
compliant message will never overflow this type.
Source§fn write_to(&self, buf: &mut impl BufMut)
fn write_to(&self, buf: &mut impl BufMut)
Source§fn merge_field(
&mut self,
tag: Tag,
buf: &mut impl Buf,
depth: u32,
) -> Result<(), DecodeError>
fn merge_field( &mut self, tag: Tag, buf: &mut impl Buf, depth: u32, ) -> Result<(), DecodeError>
buf. Read moreSource§fn cached_size(&self) -> u32
fn cached_size(&self) -> u32
compute_size() call. Read moreSource§fn encode(&self, buf: &mut impl BufMut)
fn encode(&self, buf: &mut impl BufMut)
Source§fn encode_length_delimited(&self, buf: &mut impl BufMut)
fn encode_length_delimited(&self, buf: &mut impl BufMut)
Source§fn encode_to_bytes(&self) -> Bytes
fn encode_to_bytes(&self) -> Bytes
bytes::Bytes. Read moreSource§fn decode(buf: &mut impl Buf) -> Result<Self, DecodeError>where
Self: Sized,
fn decode(buf: &mut impl Buf) -> Result<Self, DecodeError>where
Self: Sized,
Source§fn decode_from_slice(data: &[u8]) -> Result<Self, DecodeError>where
Self: Sized,
fn decode_from_slice(data: &[u8]) -> Result<Self, DecodeError>where
Self: Sized,
Source§fn decode_length_delimited(buf: &mut impl Buf) -> Result<Self, DecodeError>where
Self: Sized,
fn decode_length_delimited(buf: &mut impl Buf) -> Result<Self, DecodeError>where
Self: Sized,
Source§fn merge_to_limit(
&mut self,
buf: &mut impl Buf,
depth: u32,
limit: usize,
) -> Result<(), DecodeError>
fn merge_to_limit( &mut self, buf: &mut impl Buf, depth: u32, limit: usize, ) -> Result<(), DecodeError>
Source§fn merge_group(
&mut self,
buf: &mut impl Buf,
depth: u32,
field_number: u32,
) -> Result<(), DecodeError>
fn merge_group( &mut self, buf: &mut impl Buf, depth: u32, field_number: u32, ) -> Result<(), DecodeError>
buf, reading fields until an
EndGroup tag with the given field_number is encountered. Read more