My favorites | English | Sign in

More personalization in Google Friend Connect New!

Protocol Buffers

dynamic_message.h

#include <google/protobuf/dynamic_message.h>
namespace google::protobuf

Defines an implementation of Message which can emulate types which are not known at compile-time.

Classes in this file

Constructs implementations of Message which can emulate types which are not known at compile-time.

class DynamicMessageFactory: public MessageFactory

#include <google/protobuf/dynamic_message.h>
namespace google::protobuf

Constructs implementations of Message which can emulate types which are not known at compile-time.

Sometimes you want to be able to manipulate protocol types that you don't know about at compile time. It would be nice to be able to construct a Message object which implements the message type given by any arbitrary Descriptor. DynamicMessage provides this.

As it turns out, a DynamicMessage needs to construct extra information about its type in order to operate. Most of this information can be shared between all DynamicMessages of the same type. But, caching this information in some sort of global map would be a bad idea, since the cached information for a particular descriptor could outlive the descriptor itself. To avoid this problem, DynamicMessageFactory encapsulates this "cache". All DynamicMessages of the same type created from the same factory will share the same support data. Any Descriptors used with a particular factory must outlive the factory.

Members

DynamicMessageFactory()
Construct a DynamicMessageFactory that will search for extensions in the DescriptorPool in which the exendee is defined.
DynamicMessageFactory(const DescriptorPool * pool)
Construct a DynamicMessageFactory that will search for extensions in the given DescriptorPool.
~DynamicMessageFactory()

implements MessageFactory

virtual const Message *
GetPrototype(const Descriptor * type)
Given a Descriptor, constructs the default (prototype) Message of that type. more...

virtual const Message * DynamicMessageFactory::GetPrototype(
        const Descriptor * type)

Given a Descriptor, 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 and will be destroyed when the factory is destroyed. Also, any objects created by calling the prototype's New() method share some data with the prototype, so these must be destoyed before the DynamicMessageFactory is destroyed.

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

Note that while GetPrototype() is idempotent, it is not const. This implies that it is not thread-safe to call GetPrototype() on the same DynamicMessageFactory in two different threads simultaneously. However, the returned objects are just as thread-safe as any other Message.