Struct prost_reflect::MessageDescriptor
source · pub struct MessageDescriptor { /* private fields */ }
Expand description
A protobuf message definition.
Implementations§
source§impl MessageDescriptor
impl MessageDescriptor
sourcepub fn parent_pool(&self) -> &DescriptorPool
pub fn parent_pool(&self) -> &DescriptorPool
Gets a reference to the DescriptorPool
this message is defined in.
sourcepub fn parent_file(&self) -> FileDescriptor
pub fn parent_file(&self) -> FileDescriptor
Gets the FileDescriptor
this message is defined in.
sourcepub fn parent_message(&self) -> Option<MessageDescriptor>
pub fn parent_message(&self) -> Option<MessageDescriptor>
Gets the parent message type if this message type is nested inside a another message, or None
otherwise
sourcepub fn full_name(&self) -> &str
pub fn full_name(&self) -> &str
Gets the full name of the message type, e.g. my.package.MyMessage
.
sourcepub fn package_name(&self) -> &str
pub fn package_name(&self) -> &str
Gets the name of the package this message type is defined in, e.g. my.package
.
If no package name is set, an empty string is returned.
sourcepub fn path(&self) -> &[i32]
pub fn path(&self) -> &[i32]
Gets the path where this message is defined within the FileDescriptorProto
, e.g. [4, 0]
.
See path
for more details on the structure of the path.
sourcepub fn parent_file_descriptor_proto(&self) -> &FileDescriptorProto
pub fn parent_file_descriptor_proto(&self) -> &FileDescriptorProto
Gets a reference to the FileDescriptorProto
in which this message is defined.
sourcepub fn descriptor_proto(&self) -> &DescriptorProto
pub fn descriptor_proto(&self) -> &DescriptorProto
Gets a reference to the raw DescriptorProto
wrapped by this MessageDescriptor
.
sourcepub fn options(&self) -> DynamicMessage
pub fn options(&self) -> DynamicMessage
Decodes the options defined for this MessageDescriptor
, including any extension options.
sourcepub fn fields(&self) -> impl ExactSizeIterator<Item = FieldDescriptor> + '_
pub fn fields(&self) -> impl ExactSizeIterator<Item = FieldDescriptor> + '_
Gets an iterator yielding a FieldDescriptor
for each field defined in this message.
sourcepub fn oneofs(&self) -> impl ExactSizeIterator<Item = OneofDescriptor> + '_
pub fn oneofs(&self) -> impl ExactSizeIterator<Item = OneofDescriptor> + '_
Gets an iterator yielding a OneofDescriptor
for each oneof field defined in this message.
sourcepub fn child_messages(
&self
) -> impl ExactSizeIterator<Item = MessageDescriptor> + '_
pub fn child_messages( &self ) -> impl ExactSizeIterator<Item = MessageDescriptor> + '_
Gets the nested message types defined within this message.
sourcepub fn child_enums(&self) -> impl ExactSizeIterator<Item = EnumDescriptor> + '_
pub fn child_enums(&self) -> impl ExactSizeIterator<Item = EnumDescriptor> + '_
Gets the nested enum types defined within this message.
sourcepub fn child_extensions(
&self
) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
pub fn child_extensions( &self ) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
Gets the nested extension fields defined within this message.
Note this only returns extensions defined nested within this message. See
MessageDescriptor::extensions
to get fields defined anywhere that extend this message.
sourcepub fn extensions(
&self
) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
pub fn extensions( &self ) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
Gets an iterator over all extensions to this message defined in the parent DescriptorPool
.
Note this iterates over extension fields defined anywhere which extend this message. See
MessageDescriptor::child_extensions
to just get extensions defined nested within this message.
sourcepub fn get_field(&self, number: u32) -> Option<FieldDescriptor>
pub fn get_field(&self, number: u32) -> Option<FieldDescriptor>
Gets a FieldDescriptor
with the given number, or None
if no such field exists.
sourcepub fn get_field_by_name(&self, name: &str) -> Option<FieldDescriptor>
pub fn get_field_by_name(&self, name: &str) -> Option<FieldDescriptor>
Gets a FieldDescriptor
with the given name, or None
if no such field exists.
sourcepub fn get_field_by_json_name(&self, json_name: &str) -> Option<FieldDescriptor>
pub fn get_field_by_json_name(&self, json_name: &str) -> Option<FieldDescriptor>
Gets a FieldDescriptor
with the given JSON name, or None
if no such field exists.
sourcepub fn is_map_entry(&self) -> bool
pub fn is_map_entry(&self) -> bool
Returns true
if this is an auto-generated message type to
represent the entry type for a map field.
If this method returns true
, fields
is guaranteed to
yield the following two fields:
- A “key” field with a field number of 1
- A “value” field with a field number of 2
See map_entry_key_field
and
map_entry_value_field
for more a convenient way
to get these fields.
sourcepub fn map_entry_key_field(&self) -> FieldDescriptor
pub fn map_entry_key_field(&self) -> FieldDescriptor
If this is a map entry, returns a FieldDescriptor
for the key.
Panics
This method may panic if is_map_entry
returns false
.
sourcepub fn map_entry_value_field(&self) -> FieldDescriptor
pub fn map_entry_value_field(&self) -> FieldDescriptor
If this is a map entry, returns a FieldDescriptor
for the value.
Panics
This method may panic if is_map_entry
returns false
.
sourcepub fn reserved_ranges(&self) -> impl ExactSizeIterator<Item = Range<u32>> + '_
pub fn reserved_ranges(&self) -> impl ExactSizeIterator<Item = Range<u32>> + '_
Gets an iterator over reserved field number ranges in this message.
sourcepub fn reserved_names(&self) -> impl ExactSizeIterator<Item = &str> + '_
pub fn reserved_names(&self) -> impl ExactSizeIterator<Item = &str> + '_
Gets an iterator over reserved field names in this message.
sourcepub fn extension_ranges(&self) -> impl ExactSizeIterator<Item = Range<u32>> + '_
pub fn extension_ranges(&self) -> impl ExactSizeIterator<Item = Range<u32>> + '_
Gets an iterator over extension field number ranges in this message.
sourcepub fn get_extension(&self, number: u32) -> Option<ExtensionDescriptor>
pub fn get_extension(&self, number: u32) -> Option<ExtensionDescriptor>
Gets an extension to this message by its number, or None
if no such extension exists.
sourcepub fn get_extension_by_full_name(
&self,
name: &str
) -> Option<ExtensionDescriptor>
pub fn get_extension_by_full_name( &self, name: &str ) -> Option<ExtensionDescriptor>
Gets an extension to this message by its full name (e.g. my.package.my_extension
), or None
if no such extension exists.
sourcepub fn get_extension_by_json_name(
&self,
name: &str
) -> Option<ExtensionDescriptor>
pub fn get_extension_by_json_name( &self, name: &str ) -> Option<ExtensionDescriptor>
Gets an extension to this message by its JSON name (e.g. [my.package.my_extension]
), or None
if no such extension exists.
Trait Implementations§
source§impl Clone for MessageDescriptor
impl Clone for MessageDescriptor
source§fn clone(&self) -> MessageDescriptor
fn clone(&self) -> MessageDescriptor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MessageDescriptor
impl Debug for MessageDescriptor
source§impl<'de> DeserializeSeed<'de> for MessageDescriptor
Available on crate feature serde
only.
impl<'de> DeserializeSeed<'de> for MessageDescriptor
serde
only.source§fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error>where D: Deserializer<'de>,
Deserialize a DynamicMessage
from deserializer
using the canonical JSON encoding.
Examples
use serde::de::DeserializeSeed;
let json = r#"{ "foo": 150 }"#;
let mut deserializer = serde_json::de::Deserializer::from_str(json);
let dynamic_message = message_descriptor.deserialize(&mut deserializer).unwrap();
deserializer.end().unwrap();
assert_eq!(dynamic_message.get_field_by_name("foo").unwrap().as_ref(), &Value::I32(150));
§type Value = DynamicMessage
type Value = DynamicMessage
source§impl PartialEq<MessageDescriptor> for MessageDescriptor
impl PartialEq<MessageDescriptor> for MessageDescriptor
source§fn eq(&self, other: &MessageDescriptor) -> bool
fn eq(&self, other: &MessageDescriptor) -> bool
self
and other
values to be equal, and is used
by ==
.