I have FileDescriptorProto of message and I want to get descriptor from FileDescriptorProto in python. what should I do?
Assuming that DescriptorPool
can meet this requirement. Another question is, if a message has references to other modules, should the FileDescriptorProto of other modules also be included?
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')
I have tested that DescriptorPool
can achieve this function, and you need to pass all dependencies FileDescriptorProto
into the pool.
Be careful with the order of addition, you have to add child nodes first, then add parent nodes.
The whole process can be completed by referring to the above example