Warning
You are reading the documentation for the latest committed changes of the Protocol Buffers package for Python. Some features may not yet be released. Read the documentation for the latest released package at googleapis.dev.
google.protobuf.descriptor_pool¶
Provides DescriptorPool to use as a container for proto2 descriptors.
The DescriptorPool is used in conjection with a DescriptorDatabase to maintain a collection of protocol buffer descriptors for use when dynamically creating message types at runtime.
For most applications protocol buffers should be used via modules generated by the protocol buffer compiler tool. This should only be used when the type of protocol buffers used in an application or library cannot be predetermined.
Below is a straightforward example on how to use this class:
pool = DescriptorPool()
file_descriptor_protos = [ ... ]
for file_descriptor_proto in file_descriptor_protos:
pool.Add(file_descriptor_proto)
my_message_descriptor = pool.FindMessageTypeByName('some.package.MessageType')
The message descriptor can be used in conjunction with the message_factory module in order to create a protocol buffer class that can be encoded and decoded.
If you want to get a Python class for the specified proto, use the helper functions inside google.protobuf.message_factory directly instead of this class.
-
google.protobuf.descriptor_pool.
Default
()¶
-
class
google.protobuf.descriptor_pool.
DescriptorPool
(descriptor_db=None)¶ A collection of protobufs dynamically constructed by descriptor protos.
-
Add
(file_desc_proto)¶ Adds the FileDescriptorProto and its types to this pool.
- Parameters
file_desc_proto (FileDescriptorProto) – The file descriptor to add.
-
AddDescriptor
(**kwargs)¶
-
AddEnumDescriptor
(**kwargs)¶
-
AddExtensionDescriptor
(**kwargs)¶
-
AddFileDescriptor
(**kwargs)¶
-
AddSerializedFile
(serialized_file_desc_proto)¶ Adds the FileDescriptorProto and its types to this pool.
- Parameters
serialized_file_desc_proto (bytes) – A bytes string, serialization of the
FileDescriptorProto
to add.
-
AddServiceDescriptor
(**kwargs)¶
-
FindAllExtensions
(message_descriptor)¶ Gets all the known extensions of a given message.
Extensions have to be registered to this pool by calling
Add()
orAddExtensionDescriptor()
.- Parameters
message_descriptor (Descriptor) – Descriptor of the extended message.
- Returns
Field descriptors describing the extensions.
- Return type
-
FindEnumTypeByName
(full_name)¶ Loads the named enum descriptor from the pool.
-
FindExtensionByName
(full_name)¶ Loads the named extension descriptor from the pool.
-
FindExtensionByNumber
(message_descriptor, number)¶ Gets the extension of the specified message with the specified number.
Extensions have to be registered to this pool by calling
Add()
orAddExtensionDescriptor()
.- Parameters
message_descriptor (Descriptor) – descriptor of the extended message.
number (int) – Number of the extension field.
- Returns
The descriptor for the extension.
- Return type
- Raises
KeyError – when no extension with the given number is known for the specified message.
-
FindFieldByName
(full_name)¶ Loads the named field descriptor from the pool.
-
FindFileByName
(file_name)¶ Gets a FileDescriptor by file name.
-
FindFileContainingSymbol
(symbol)¶ Gets the FileDescriptor for the file containing the specified symbol.
-
FindMessageTypeByName
(full_name)¶ Loads the named descriptor from the pool.
-
FindMethodByName
(full_name)¶ Loads the named service method descriptor from the pool.
-
FindOneofByName
(full_name)¶ Loads the named oneof descriptor from the pool.
-