dynamic_message.h

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 aMessage 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 extendee is defined.
DynamicMessageFactory(const DescriptorPool * pool)
Construct a  DynamicMessageFactory that will search for extensions in the given  DescriptorPoolmore...
~DynamicMessageFactory()
void
SetDelegateToGeneratedFactory(bool enable)
Call this to tell the  DynamicMessageFactory that if it is given a  Descriptor d for which:  more...

implements MessageFactory

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

DynamicMessageFactory::DynamicMessageFactory(
        const DescriptorPool * pool)

Construct a DynamicMessageFactory that will search for extensions in the given DescriptorPool.

DEPRECATED: Use CodedInputStream::SetExtensionRegistry() to tell the parser to look for extensions in an alternate pool. However, note that this is almost never what you want to do. Almost all users should use the zero-arg constructor.


void DynamicMessageFactory::SetDelegateToGeneratedFactory(
        bool enable)

Call this to tell the DynamicMessageFactory that if it is given a Descriptor d for which:

d->file()->pool() == DescriptorPool::generated_pool(),

then it should delegate to MessageFactory::generated_factory() instead of constructing a dynamic implementation of the message. In theory there is no down side to doing this, so it may become the default in the future.


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 destroyed before the DynamicMessageFactory is destroyed.

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

The method is thread-safe.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值