Struct protobuf_native::DescriptorPool
source · pub struct DescriptorPool { /* private fields */ }
Expand description
Used to construct descriptors.
Normally you won’t want to build your own descriptors. Message classes
constructed by the protocol compiler will provide them for you. However, if
you are implementing Message
on your own, or if you are writing a
program which can operate on totally arbitrary types and needs to load them
from some sort of database, you might need to.
Since Descriptor
s are composed of a whole lot of cross-linked bits of
data that would be a pain to put together manually, the DescriptorPool
class is provided to make the process easier. It can take a
FileDescriptorProto
(defined in descriptor.proto), validate it, and
convert it to a set of nicely cross-linked Descriptor
s.
DescriptorPool
also helps with memory management. Descriptors are
composed of many objects containing static data and pointers to each other.
In all likelihood, when it comes time to delete this data, you’ll want to
delete it all at once. In fact, it is not uncommon to have a whole pool of
descriptors all cross-linked with each other which you wish to delete all at
once. This class represents such a pool, and handles the memory management
for you.
You can also search for descriptors within a DescriptorPool
by name, and
extensions by number.
Implementations§
source§impl DescriptorPool
impl DescriptorPool
pub fn new() -> Pin<Box<DescriptorPool>>
sourcepub fn build_file(
self: Pin<&mut Self>,
proto: &FileDescriptorProto,
) -> &FileDescriptor
pub fn build_file( self: Pin<&mut Self>, proto: &FileDescriptorProto, ) -> &FileDescriptor
Converts the FileDescriptorProto
to real descriptors and places them
in this descriptor pool.
All dependencies of the file must already be in the pool. Returns the
resulting FileDescriptor
, or None
if there were problems with the
input (e.g. the message was invalid, or dependencies were missing).
Details about the errors are written to the error log.