Extensions work analogously to the generated accessors you'd see for a
normal field of the same type.  So, for a message-typed field, there is no
"set" accessor.  Instead, there is a "mutable" accessor.  So, you want to
do:
  Request request;
  Renderer* renderer = request.MutableExtension(Renderer::Command);

This way, the ownership relation between the objects is clear.

The C++ generated code guide describes exactly what accessors are generated
for any particular field type:

http://code.google.com/apis/protocolbuffers/docs/reference/cpp-generated.html

Unfortunately, the compiler produces pretty confusing errors when extensions
are misused.  Such is the nature of C++ templates.  Sorry about that.

On an unrelated note, I notice your naming convention differs from the one
suggested in the protocol buffer style guide.  This is, of course, up to
you, but you might find the system plays nicer if you follow the guide:

  http://code.google.com/apis/protocolbuffers/docs/style.html

On Fri, Oct 10, 2008 at 8:26 AM, <[EMAIL PROTECTED]> wrote:

>
> I have a question about extensions. I have the following 2 .proto
> files:
>
> //Request.proto
> message Request
> {
>        required string Guid = 1;
>        required string Name = 2;
>        extensions 100 to 199;
> }
>
> // Rerender.proto
> import "Request.proto";
> message Rerender
> {
>        extend Request
>        {
>                optional Rerender Command = 100;
>        }
>
>        required string Data = 1;
> }
>
> When I try to do the following:
> Request request;
> Rerender rerender;
> request.SetExtension(Rerender::Command, rerender);
>
> I get the following:
> error C2039: 'Set' : is not a member of
> 'google::protobuf::internal::MessageTypeTraits<Type>'
>
> The offending method from Request.pb.h:
>
> template <typename _proto_TypeTraits>
>  inline void SetExtension(
>      const ::google::protobuf::internal::ExtensionIdentifier<
>        Request, _proto_TypeTraits>& id,
>      typename _proto_TypeTraits::ConstType value) {
>    _proto_TypeTraits::Set(id.number(), value, &_extensions_);
>  }
>
> Note that if I use a Scalar type as the datatype of my extension, it
> compiles fine. The problem appears to be limited to using message
> types as an extension.
>
> Any assistance on how to get this to work would be much appreciated!!
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to