Struct prost_reflect::DynamicMessage
source · [−]pub struct DynamicMessage { /* private fields */ }Expand description
DynamicMessage provides encoding, decoding and reflection of a protobuf message.
It wraps a MessageDescriptor and the Value for each field of the message, and implements
Message.
Implementations
sourceimpl DynamicMessage
impl DynamicMessage
sourcepub fn serialize_with_options<S>(
&self,
serializer: S,
options: &SerializeOptions
) -> Result<S::Ok, S::Error> where
S: Serializer,
Available on crate feature serde only.
pub fn serialize_with_options<S>(
&self,
serializer: S,
options: &SerializeOptions
) -> Result<S::Ok, S::Error> where
S: Serializer,
serde only.Serialize this message into serializer using the encoding specified by options.
sourcepub fn deserialize<'de, D>(
desc: MessageDescriptor,
deserializer: D
) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Available on crate feature serde only.
pub fn deserialize<'de, D>(
desc: MessageDescriptor,
deserializer: D
) -> Result<Self, D::Error> where
D: Deserializer<'de>,
serde only.Deserialize an instance of the message type described by desc from deserializer.
sourcepub fn deserialize_with_options<'de, D>(
desc: MessageDescriptor,
deserializer: D,
options: &DeserializeOptions
) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Available on crate feature serde only.
pub fn deserialize_with_options<'de, D>(
desc: MessageDescriptor,
deserializer: D,
options: &DeserializeOptions
) -> Result<Self, D::Error> where
D: Deserializer<'de>,
serde only.Deserialize an instance of the message type described by desc from deserializer, using
the encoding specified by options.
sourceimpl DynamicMessage
impl DynamicMessage
sourcepub fn new(desc: MessageDescriptor) -> Self
pub fn new(desc: MessageDescriptor) -> Self
Creates a new, empty instance of DynamicMessage for the message type specified by the MessageDescriptor.
sourcepub fn decode<B>(desc: MessageDescriptor, buf: B) -> Result<Self, DecodeError> where
B: Buf,
pub fn decode<B>(desc: MessageDescriptor, buf: B) -> Result<Self, DecodeError> where
B: Buf,
Decodes an instance of the message type specified by the MessageDescriptor from the buffer and merges it into a
new instance of DynamicMessage.
sourcepub fn has_field(&self, field_desc: &FieldDescriptor) -> bool
pub fn has_field(&self, field_desc: &FieldDescriptor) -> bool
Returns true if this message has the given field set.
If the field type supports distinguishing whether a value has been set (see supports_presence),
such as for messages, then this method returns true only if a value has been set. For
other types, such as integers, it returns true if the value is set to a non-default value.
If this method returns false, then the field will not be included in the encoded bytes
of this message.
sourcepub fn get_field(&self, field_desc: &FieldDescriptor) -> Cow<'_, Value>
pub fn get_field(&self, field_desc: &FieldDescriptor) -> Cow<'_, Value>
Gets the value of the given field, or the default value if it is unset.
sourcepub fn get_field_mut(&mut self, field_desc: &FieldDescriptor) -> &mut Value
pub fn get_field_mut(&mut self, field_desc: &FieldDescriptor) -> &mut Value
Gets a mutable reference to the value ofthe given field. If the field is not set, it is inserted with its default value.
sourcepub fn set_field(&mut self, field_desc: &FieldDescriptor, value: Value)
pub fn set_field(&mut self, field_desc: &FieldDescriptor, value: Value)
Sets the value of the given field.
Panics
This method may panic if the value type is not compatible with the field type, as defined
by Value::is_valid_for_field.
sourcepub fn clear_field(&mut self, field_desc: &FieldDescriptor)
pub fn clear_field(&mut self, field_desc: &FieldDescriptor)
Clears the given field.
After calling this method, has_field will return false for the field,
and it will not be included in the encoded bytes of this message.
sourcepub fn has_field_by_number(&self, number: u32) -> bool
pub fn has_field_by_number(&self, number: u32) -> bool
Returns true if this message has a field set with the given number.
See has_field for more details.
sourcepub fn get_field_by_number(&self, number: u32) -> Option<Cow<'_, Value>>
pub fn get_field_by_number(&self, number: u32) -> Option<Cow<'_, Value>>
Gets the value of the field with the given number, or the default value if it is unset.
If the message has no field with the given number, None is returned.
See get_field for more details.
sourcepub fn get_field_by_number_mut(&mut self, number: u32) -> Option<&mut Value>
pub fn get_field_by_number_mut(&mut self, number: u32) -> Option<&mut Value>
Gets a mutable reference to the value of the field with the given number. If the field is not set, it is inserted with its default value.
If the message has no field with the given number, None is returned.
See get_field_mut for more details.
sourcepub fn set_field_by_number(&mut self, number: u32, value: Value)
pub fn set_field_by_number(&mut self, number: u32, value: Value)
Sets the value of the field with number number, or the default value if it is unset.
If no field with the given number exists, this method does nothing.
See set_field for more details.
sourcepub fn clear_field_by_number(&mut self, number: u32)
pub fn clear_field_by_number(&mut self, number: u32)
Clears the field with the given number.
If no field with the given number exists, this method does nothing.
See clear_field for more details.
sourcepub fn has_field_by_name(&self, name: &str) -> bool
pub fn has_field_by_name(&self, name: &str) -> bool
Returns true if this message has a field set with the given name.
See has_field for more details.
sourcepub fn get_field_by_name(&self, name: &str) -> Option<Cow<'_, Value>>
pub fn get_field_by_name(&self, name: &str) -> Option<Cow<'_, Value>>
Gets the value of the field with the given name, or the default value if it is unset.
If the message has no field with the given name, None is returned.
See get_field for more details.
sourcepub fn get_field_by_name_mut(&mut self, name: &str) -> Option<&mut Value>
pub fn get_field_by_name_mut(&mut self, name: &str) -> Option<&mut Value>
Gets a mutable reference to the value of the field with the given name. If the field is not set, it is inserted with its default value.
If the message has no field with the given name, None is returned.
See get_field_mut for more details.
sourcepub fn set_field_by_name(&mut self, name: &str, value: Value)
pub fn set_field_by_name(&mut self, name: &str, value: Value)
Sets the value of the field with name name.
If no field with the given name exists, this method does nothing.
See set_field for more details.
sourcepub fn clear_field_by_name(&mut self, name: &str)
pub fn clear_field_by_name(&mut self, name: &str)
Clears the field with the given name.
If no field with the given name exists, this method does nothing.
See clear_field for more details.
sourcepub fn has_extension(&self, extension_desc: &ExtensionDescriptor) -> bool
pub fn has_extension(&self, extension_desc: &ExtensionDescriptor) -> bool
Returns true if this message has the given extension field set.
See has_field for more details.
sourcepub fn get_extension(
&self,
extension_desc: &ExtensionDescriptor
) -> Cow<'_, Value>
pub fn get_extension(
&self,
extension_desc: &ExtensionDescriptor
) -> Cow<'_, Value>
Gets the value of the given extension field, or the default value if it is unset.
See get_field for more details.
sourcepub fn get_extension_mut(
&mut self,
extension_desc: &ExtensionDescriptor
) -> &mut Value
pub fn get_extension_mut(
&mut self,
extension_desc: &ExtensionDescriptor
) -> &mut Value
Gets a mutable reference to the value of the given extension field. If the field is not set, it is inserted with its default value.
See get_field_mut for more details.
sourcepub fn set_extension(
&mut self,
extension_desc: &ExtensionDescriptor,
value: Value
)
pub fn set_extension(
&mut self,
extension_desc: &ExtensionDescriptor,
value: Value
)
Sets the value of the given extension field.
See set_field for more details.
sourcepub fn clear_extension(&mut self, extension_desc: &ExtensionDescriptor)
pub fn clear_extension(&mut self, extension_desc: &ExtensionDescriptor)
Clears the given extension field.
See clear_field for more details.
sourcepub fn transcode_from<T>(&mut self, value: &T) -> Result<(), DecodeError> where
T: Message,
pub fn transcode_from<T>(&mut self, value: &T) -> Result<(), DecodeError> where
T: Message,
Merge a strongly-typed message into this one.
The message should be compatible with the type specified by
descriptor, or the merge will likely fail with
a DecodeError.
sourcepub fn transcode_to<T>(&self) -> Result<T, DecodeError> where
T: Message + Default,
pub fn transcode_to<T>(&self) -> Result<T, DecodeError> where
T: Message + Default,
Convert this dynamic message into a strongly typed value.
The message should be compatible with the type specified by
descriptor, or the conversion will likely fail with
a DecodeError.
Trait Implementations
sourceimpl Clone for DynamicMessage
impl Clone for DynamicMessage
sourcefn clone(&self) -> DynamicMessage
fn clone(&self) -> DynamicMessage
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for DynamicMessage
impl Debug for DynamicMessage
sourceimpl Message for DynamicMessage
impl Message for DynamicMessage
sourcefn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the encoded length of the message without a length delimiter.
sourcefn encode<B>(&self, buf: &mut B) -> Result<(), EncodeError> where
B: BufMut,
fn encode<B>(&self, buf: &mut B) -> Result<(), EncodeError> where
B: BufMut,
Encodes the message to a buffer. Read more
sourcefn encode_to_vec(&self) -> Vec<u8, Global>
fn encode_to_vec(&self) -> Vec<u8, Global>
Encodes the message to a newly allocated buffer.
sourcefn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), EncodeError> where
B: BufMut,
fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), EncodeError> where
B: BufMut,
Encodes the message with a length-delimiter to a buffer. Read more
sourcefn encode_length_delimited_to_vec(&self) -> Vec<u8, Global>
fn encode_length_delimited_to_vec(&self) -> Vec<u8, Global>
Encodes the message with a length-delimiter to a newly allocated buffer.
sourcefn decode<B>(buf: B) -> Result<Self, DecodeError> where
B: Buf,
Self: Default,
fn decode<B>(buf: B) -> Result<Self, DecodeError> where
B: Buf,
Self: Default,
Decodes an instance of the message from a buffer. Read more
sourcefn decode_length_delimited<B>(buf: B) -> Result<Self, DecodeError> where
B: Buf,
Self: Default,
fn decode_length_delimited<B>(buf: B) -> Result<Self, DecodeError> where
B: Buf,
Self: Default,
Decodes a length-delimited instance of the message from the buffer.
sourcefn merge<B>(&mut self, buf: B) -> Result<(), DecodeError> where
B: Buf,
fn merge<B>(&mut self, buf: B) -> Result<(), DecodeError> where
B: Buf,
Decodes an instance of the message from a buffer, and merges it into self. Read more
sourcefn merge_length_delimited<B>(&mut self, buf: B) -> Result<(), DecodeError> where
B: Buf,
fn merge_length_delimited<B>(&mut self, buf: B) -> Result<(), DecodeError> where
B: Buf,
Decodes a length-delimited instance of the message from buffer, and
merges it into self. Read more
sourceimpl PartialEq<DynamicMessage> for DynamicMessage
impl PartialEq<DynamicMessage> for DynamicMessage
sourcefn eq(&self, other: &DynamicMessage) -> bool
fn eq(&self, other: &DynamicMessage) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &DynamicMessage) -> bool
fn ne(&self, other: &DynamicMessage) -> bool
This method tests for !=.
sourceimpl ReflectMessage for DynamicMessage
impl ReflectMessage for DynamicMessage
sourcefn descriptor(&self) -> MessageDescriptor
fn descriptor(&self) -> MessageDescriptor
Gets a MessageDescriptor describing the type of this message.
sourcefn transcode_to_dynamic(&self) -> DynamicMessage where
Self: Sized,
fn transcode_to_dynamic(&self) -> DynamicMessage where
Self: Sized,
Converts this message into an instance of DynamicMessage by going
through the byte representation. Read more
sourceimpl Serialize for DynamicMessage
Available on crate feature serde only.
impl Serialize for DynamicMessage
serde only.sourcefn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
Serialize this message into serializer using the canonical JSON encoding.
impl StructuralPartialEq for DynamicMessage
Auto Trait Implementations
impl RefUnwindSafe for DynamicMessage
impl Send for DynamicMessage
impl Sync for DynamicMessage
impl Unpin for DynamicMessage
impl UnwindSafe for DynamicMessage
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more