Struct prost_reflect::DescriptorPool
source · pub struct DescriptorPool { /* private fields */ }
Expand description
A DescriptorPool
is a collection of related descriptors. Typically it will be created from
a FileDescriptorSet
output by the protobuf compiler
(see DescriptorPool::from_file_descriptor_set
) but it may also be built up by adding files individually.
Methods like MessageDescriptor::extensions
will be scoped to just the files contained within the parent
DescriptorPool
.
This type uses reference counting internally so it is cheap to clone. Modifying an instance of a pool will not update any existing clones of the instance.
Implementations§
source§impl DescriptorPool
impl DescriptorPool
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty DescriptorPool
.
For the common case of creating a DescriptorPool
from a single FileDescriptorSet
, see
DescriptorPool::from_file_descriptor_set
or DescriptorPool::decode
.
sourcepub fn from_file_descriptor_set(
file_descriptor_set: FileDescriptorSet
) -> Result<Self, DescriptorError>
pub fn from_file_descriptor_set( file_descriptor_set: FileDescriptorSet ) -> Result<Self, DescriptorError>
Creates a DescriptorPool
from a FileDescriptorSet
.
A file descriptor set may be generated by running the protobuf compiler with the
--descriptor_set_out
flag. If you are using prost-build
,
then Config::file_descriptor_set_path
is a convenient way to generate it as part of your build.
sourcepub fn decode<B>(bytes: B) -> Result<Self, DescriptorError>where
B: Buf,
pub fn decode<B>(bytes: B) -> Result<Self, DescriptorError>where
B: Buf,
Decodes and adds a set of file descriptors to the pool.
A file descriptor set may be generated by running the protobuf compiler with the
--descriptor_set_out
flag. If you are using prost-build
,
then Config::file_descriptor_set_path
is a convenient way to generate it as part of your build.
Unlike when using DescriptorPool::from_file_descriptor_set
, any extension options
defined in the file descriptors are preserved.
§Errors
Returns an error if the given bytes are not a valid protobuf-encoded file descriptor set, or if the descriptor set itself is invalid. When using a file descriptor set generated by the protobuf compiler, this method will always succeed.
sourcepub fn add_file_descriptor_set(
&mut self,
file_descriptor_set: FileDescriptorSet
) -> Result<(), DescriptorError>
pub fn add_file_descriptor_set( &mut self, file_descriptor_set: FileDescriptorSet ) -> Result<(), DescriptorError>
Adds a new FileDescriptorSet
to this DescriptorPool
.
A file descriptor set may be generated by running the protobuf compiler with the
--descriptor_set_out
flag. If you are using prost-build
,
then Config::file_descriptor_set_path
is a convenient way to generate it as part of your build.
Any duplicates of files already in the pool will be skipped. Note this may cause issues when trying to add two different versions of a file with the same name.
§Errors
Returns an error if the descriptor set is invalid, for example if it references types not yet added to the pool. When using a file descriptor set generated by the protobuf compiler, this method will always succeed.
sourcepub fn add_file_descriptor_protos<I>(
&mut self,
files: I
) -> Result<(), DescriptorError>where
I: IntoIterator<Item = FileDescriptorProto>,
pub fn add_file_descriptor_protos<I>(
&mut self,
files: I
) -> Result<(), DescriptorError>where
I: IntoIterator<Item = FileDescriptorProto>,
Adds a collection of file descriptors to this pool.
The file descriptors may be provided in any order, however all types referenced must be defined either in one of the files provided, or in a file previously added to the pool.
Any duplicates of files already in the pool will be skipped. Note this may cause issues when trying to add two different versions of a file with the same name.
§Errors
Returns an error if any of the given file descriptor is invalid, for example if they reference types not yet added to the pool.
sourcepub fn add_file_descriptor_proto(
&mut self,
file: FileDescriptorProto
) -> Result<(), DescriptorError>
pub fn add_file_descriptor_proto( &mut self, file: FileDescriptorProto ) -> Result<(), DescriptorError>
Add a single file descriptor to the pool.
All types referenced by the file must be defined either in the file itself, or in a file previously added to the pool.
If the file is a duplicate of a file already in the pool, it will be skipped. Note this may cause issues when trying to add two different versions of a file with the same name.
§Errors
Returns an error if the given file descriptor is invalid, for example if it references types not yet added to the pool.
sourcepub fn decode_file_descriptor_proto<B>(
&mut self,
bytes: B
) -> Result<(), DescriptorError>where
B: Buf,
pub fn decode_file_descriptor_proto<B>(
&mut self,
bytes: B
) -> Result<(), DescriptorError>where
B: Buf,
Decode and add a single file descriptor to the pool.
All types referenced by the file must be defined either in the file itself, or in a file previously added to the pool.
Unlike when using add_file_descriptor_proto()
, any extension options
defined in the file descriptor are preserved.
If the file is a duplicate of a file already in the pool, it will be skipped. Note this may cause issues when trying to add two different versions of a file with the same name.
§Errors
Returns an error if the given bytes are not a valid protobuf-encoded file descriptor, or if the file descriptor itself is invalid, for example if it references types not yet added to the pool.
sourcepub fn decode_file_descriptor_set<B>(
&mut self,
bytes: B
) -> Result<(), DescriptorError>where
B: Buf,
pub fn decode_file_descriptor_set<B>(
&mut self,
bytes: B
) -> Result<(), DescriptorError>where
B: Buf,
Decode and add a set of file descriptors to the pool.
A file descriptor set may be generated by running the protobuf compiler with the
--descriptor_set_out
flag. If you are using prost-build
,
then Config::file_descriptor_set_path
is a convenient way to generate it as part of your build.
Unlike when using add_file_descriptor_set()
, any extension options
defined in the file descriptors are preserved.
Any duplicates of files already in the pool will be skipped. Note this may cause issues when trying to add two different versions of a file with the same name.
§Errors
Returns an error if the given bytes are not a valid protobuf-encoded file descriptor set, or if the descriptor set itself is invalid. When using a file descriptor set generated by the protobuf compiler, this method will always succeed.
sourcepub fn files(&self) -> impl ExactSizeIterator<Item = FileDescriptor> + '_
pub fn files(&self) -> impl ExactSizeIterator<Item = FileDescriptor> + '_
Gets an iterator over the file descriptors added to this pool.
sourcepub fn get_file_by_name(&self, name: &str) -> Option<FileDescriptor>
pub fn get_file_by_name(&self, name: &str) -> Option<FileDescriptor>
Gets a file descriptor by its name, or None
if no such file has been added.
sourcepub fn file_descriptor_protos(
&self
) -> impl ExactSizeIterator<Item = &FileDescriptorProto> + '_
pub fn file_descriptor_protos( &self ) -> impl ExactSizeIterator<Item = &FileDescriptorProto> + '_
Gets a iterator over the raw FileDescriptorProto
instances wrapped by this DescriptorPool
.
sourcepub fn encode<B>(&self, buf: B) -> Result<(), EncodeError>where
B: BufMut,
pub fn encode<B>(&self, buf: B) -> Result<(), EncodeError>where
B: BufMut,
Encodes the files contained within this DescriptorPool
to their byte representation.
The encoded message is equivalent to a FileDescriptorSet
, however also includes
any extension options that were defined.
sourcepub fn encode_to_vec(&self) -> Vec<u8>
pub fn encode_to_vec(&self) -> Vec<u8>
Encodes the files contained within this DescriptorPool
to a newly allocated buffer.
The encoded message is equivalent to a FileDescriptorSet
, however also includes
any extension options that were defined.
sourcepub fn services(&self) -> impl ExactSizeIterator<Item = ServiceDescriptor> + '_
pub fn services(&self) -> impl ExactSizeIterator<Item = ServiceDescriptor> + '_
Gets an iterator over the services defined in these protobuf files.
sourcepub fn all_messages(
&self
) -> impl ExactSizeIterator<Item = MessageDescriptor> + '_
pub fn all_messages( &self ) -> impl ExactSizeIterator<Item = MessageDescriptor> + '_
Gets an iterator over all message types defined in these protobuf files.
The iterator includes nested messages defined in another message.
sourcepub fn all_enums(&self) -> impl ExactSizeIterator<Item = EnumDescriptor> + '_
pub fn all_enums(&self) -> impl ExactSizeIterator<Item = EnumDescriptor> + '_
Gets an iterator over all enum types defined in these protobuf files.
The iterator includes nested enums defined in another message.
sourcepub fn all_extensions(
&self
) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
pub fn all_extensions( &self ) -> impl ExactSizeIterator<Item = ExtensionDescriptor> + '_
Gets an iterator over all extension fields defined in these protobuf files.
The iterator includes nested extension fields defined in another message.
sourcepub fn get_message_by_name(&self, name: &str) -> Option<MessageDescriptor>
pub fn get_message_by_name(&self, name: &str) -> Option<MessageDescriptor>
Gets a MessageDescriptor
by its fully qualified name, for example my.package.MessageName
.
sourcepub fn get_enum_by_name(&self, name: &str) -> Option<EnumDescriptor>
pub fn get_enum_by_name(&self, name: &str) -> Option<EnumDescriptor>
Gets an EnumDescriptor
by its fully qualified name, for example my.package.EnumName
.
sourcepub fn get_extension_by_name(&self, name: &str) -> Option<ExtensionDescriptor>
pub fn get_extension_by_name(&self, name: &str) -> Option<ExtensionDescriptor>
Gets an ExtensionDescriptor
by its fully qualified name, for example my.package.my_extension
.
sourcepub fn get_service_by_name(&self, name: &str) -> Option<ServiceDescriptor>
pub fn get_service_by_name(&self, name: &str) -> Option<ServiceDescriptor>
Gets an ServiceDescriptor
by its fully qualified name, for example my.package.MyService
.
source§impl DescriptorPool
impl DescriptorPool
sourcepub fn global() -> DescriptorPool
pub fn global() -> DescriptorPool
Gets a copy of the global descriptor pool. By default, this just contains the google well-known types.
The global descriptor pool is typically used as a convenient place to store descriptors for ReflectMessage
implementations.
Note that modifications to the returned pool won’t affect the global pool - use
decode_global_file_descriptor_set
or
add_global_file_descriptor_proto
to modify the global pool.
sourcepub fn decode_global_file_descriptor_set<B>(
bytes: B
) -> Result<(), DescriptorError>where
B: Buf,
pub fn decode_global_file_descriptor_set<B>(
bytes: B
) -> Result<(), DescriptorError>where
B: Buf,
Decodes and adds a set of file descriptors to the global pool.
See DescriptorPool::decode_file_descriptor_set
for more details.
sourcepub fn add_global_file_descriptor_proto<B>(
file: FileDescriptorProto
) -> Result<(), DescriptorError>where
B: Buf,
pub fn add_global_file_descriptor_proto<B>(
file: FileDescriptorProto
) -> Result<(), DescriptorError>where
B: Buf,
Adds a single file descriptor to the global pool.
See DescriptorPool::add_file_descriptor_proto
for more details.
Trait Implementations§
source§impl Clone for DescriptorPool
impl Clone for DescriptorPool
source§fn clone(&self) -> DescriptorPool
fn clone(&self) -> DescriptorPool
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more