google.protobuf.message_factory

Provides a factory class for generating dynamic messages.

The easiest way to use this class is if you have access to the FileDescriptor protos containing the messages you want to create you can just do the following:

message_classes = message_factory.GetMessages(iterable_of_file_descriptors) my_proto_instance = message_classes[‘some.proto.package.MessageName’]()

google.protobuf.message_factory.GetMessages(file_protos)

Builds a dictionary of all the messages available in a set of files.

Parameters:

file_protos – Iterable of FileDescriptorProto to build messages out of.

Returns:

A dictionary mapping proto names to the message classes. This will include any dependent messages as well as any messages defined in the same file as a specified message.

class google.protobuf.message_factory.MessageFactory(pool=None)

Factory for creating Proto2 messages from descriptors in a pool.

CreatePrototype(descriptor)

Builds a proto2 message class based on the passed in descriptor.

Don’t call this function directly, it always creates a new class. Call GetPrototype() instead. This method is meant to be overridden in subblasses to perform additional operations on the newly constructed class.

Parameters:

descriptor – The descriptor to build from.

Returns:

A class describing the passed in descriptor.

GetMessages(files)

Gets all the messages from a specified file.

This will find and resolve dependencies, failing if the descriptor pool cannot satisfy them.

Parameters:

files – The file names to extract messages from.

Returns:

A dictionary mapping proto names to the message classes. This will include any dependent messages as well as any messages defined in the same file as a specified message.

GetPrototype(descriptor)

Obtains a proto2 message class based on the passed in descriptor.

Passing a descriptor with a fully qualified name matching a previous invocation will cause the same class to be returned.

Parameters:

descriptor – The descriptor to build from.

Returns:

A class describing the passed in descriptor.