class MessageFactory

Defined at line 1363 of file ../../third_party/protobuf/src/google/protobuf/message.h

Abstract interface for a factory for message objects.

The thread safety for this class is implementation dependent, see comments

around GetPrototype for details

Public Methods

void MessageFactory ()

Defined at line 1365 of file ../../third_party/protobuf/src/google/protobuf/message.h

void MessageFactory (const MessageFactory & )

Defined at line 1366 of file ../../third_party/protobuf/src/google/protobuf/message.h

MessageFactory & operator= (const MessageFactory & )

Defined at line 1367 of file ../../third_party/protobuf/src/google/protobuf/message.h

void ~MessageFactory ()
const Message * GetPrototype (const Descriptor * type)

Given a Descriptor, gets or constructs the default (prototype) Message

of that type. You can then call that message's New() method to construct

a mutable message of that type.

Calling this method twice with the same Descriptor returns the same

object. The returned object remains property of the factory. Also, any

objects created by calling the prototype's New() method share some data

with the prototype, so these must be destroyed before the MessageFactory

is destroyed.

The given descriptor must outlive the returned message, and hence must

outlive the MessageFactory.

Some implementations do not support all types. GetPrototype() will

return nullptr if the descriptor passed in is not supported.

This method may or may not be thread-safe depending on the implementation.

Each implementation should document its own degree thread-safety.

MessageFactory * generated_factory ()

Gets a MessageFactory which supports all generated, compiled-in messages.

In other words, for any compiled-in type FooMessage, the following is true:

MessageFactory::generated_factory()->GetPrototype(

FooMessage::descriptor()) == FooMessage::default_instance()

This factory supports all types which are found in

DescriptorPool::generated_pool(). If given a descriptor from any other

pool, GetPrototype() will return nullptr. (You can also check if a

descriptor is for a generated message by checking if

descriptor->file()->pool() == DescriptorPool::generated_pool().)

This factory is 100% thread-safe; calling GetPrototype() does not modify

any shared data.

This factory is a singleton. The caller must not delete the object.

void InternalRegisterGeneratedFile (const google::protobuf::internal::DescriptorTable * table)

For internal use only: Registers a .proto file at static initialization

time, to be placed in generated_factory. The first time GetPrototype()

is called with a descriptor from this file, |register_messages| will be

called, with the file name as the parameter. It must call

InternalRegisterGeneratedMessage() (below) to register each message type

in the file. This strange mechanism is necessary because descriptors are

built lazily, so we can't register types by their descriptor until we

know that the descriptor exists. |filename| must be a permanent string.

void InternalRegisterGeneratedMessage (const Descriptor * descriptor, const Message * prototype)

For internal use only: Registers a message type. Called only by the

functions which are registered with InternalRegisterGeneratedFile(),

above.

Friends

class DynamicMessageFactory