pub struct MessageDescriptor { /* private fields */ }
Expand description

A protobuf message definition.

Implementations§

source§

impl MessageDescriptor

source

pub fn parent_pool(&self) -> &DescriptorPool

Gets a reference to the DescriptorPool this message is defined in.

source

pub fn parent_file(&self) -> FileDescriptor

Gets the FileDescriptor this message is defined in.

source

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

source

pub fn name(&self) -> &str

Gets the short name of the message type, e.g. MyMessage.

source

pub fn full_name(&self) -> &str

Gets the full name of the message type, e.g. my.package.MyMessage.

source

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.

source

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.

source

pub fn parent_file_descriptor_proto(&self) -> &FileDescriptorProto

Gets a reference to the FileDescriptorProto in which this message is defined.

source

pub fn descriptor_proto(&self) -> &DescriptorProto

Gets a reference to the raw DescriptorProto wrapped by this MessageDescriptor.

source

pub fn options(&self) -> DynamicMessage

Decodes the options defined for this MessageDescriptor, including any extension options.

source

pub fn fields(&self) -> impl ExactSizeIterator<Item = FieldDescriptor> + '_

Gets an iterator yielding a FieldDescriptor for each field defined in this message.

source

pub fn oneofs(&self) -> impl ExactSizeIterator<Item = OneofDescriptor> + '_

Gets an iterator yielding a OneofDescriptor for each oneof field defined in this message.

source

pub fn child_messages( &self ) -> impl ExactSizeIterator<Item = MessageDescriptor> + '_

Gets the nested message types defined within this message.

source

pub fn child_enums(&self) -> impl ExactSizeIterator<Item = EnumDescriptor> + '_

Gets the nested enum types defined within this message.

source

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.

source

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.

source

pub fn get_field(&self, number: u32) -> Option<FieldDescriptor>

Gets a FieldDescriptor with the given number, or None if no such field exists.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn reserved_ranges(&self) -> impl ExactSizeIterator<Item = Range<u32>> + '_

Gets an iterator over reserved field number ranges in this message.

source

pub fn reserved_names(&self) -> impl ExactSizeIterator<Item = &str> + '_

Gets an iterator over reserved field names in this message.

source

pub fn extension_ranges(&self) -> impl ExactSizeIterator<Item = Range<u32>> + '_

Gets an iterator over extension field number ranges in this message.

source

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.

source

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.

source

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

source§

fn clone(&self) -> MessageDescriptor

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 MessageDescriptor

source§

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

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

impl<'de> DeserializeSeed<'de> for MessageDescriptor

Available on crate feature serde only.
source§

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

The type produced by using this seed.
source§

impl PartialEq<MessageDescriptor> for MessageDescriptor

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for MessageDescriptor

source§

impl StructuralEq for MessageDescriptor

source§

impl StructuralPartialEq for MessageDescriptor

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.