Dear Kenton, thanks for prompt reply and deep explaination.
The descriptor->file()->pool()->FindAllExtensions(...) was exactly what we've been looking for, in order to enumerate all available extensions of an extendee message. Now everything works fine. Thanks again for precious work. On 1 Ott, 13:05, Kenton Varda <[email protected]> wrote: > On Thu, Oct 1, 2009 at 3:39 AM, Carlo Medas <[email protected]> wrote: > > I would like to manually enumerate the available extensions to my > > RpcMessage. This is easily done by using an ExtensionFactory in Java > > code. > > What's ExtensionFactory? Do you mean ExtensionRegistry? But it doesn't > allow you to enumerate extensions, only search for specific ones. > > > In C++ it's not there, so we tried to use the > > google::protobuf::Descriptor, but neither the extension_count and > > field_count keep track of the created extensions. > > extension_count keeps track of extensions declared within the message's > scope. E.g. I can do: > > message Foo { > extend Bar { > optional int32 baz = 1; > } > } > > Here, "baz" is declared within Foo's scope, even though it is extending Bar. > > My guess is that you want to know all the extensions which are extending > your Descriptor, not all of the extensions declared within the scope of your > Descriptor. In that case, you have two options: > > 1) DescriptorPool (which you can get using descriptor->file()->pool()) has > methods for searching for extensions. > > 2) The Reflection interface for a particular message (returned by > message.GetReflection()) has methods for searching for extensions. > > However, like in Java, you can not iterate over all known extensions. You > can only search for particular ones. > > > Pretending that I managed to know the field assigned to that > > extension, the following code is going to work in order to assing the > > value to that extension field by using reflection? > > > const google::protobuf::Reflection* reflection = > > rpcMessage.GetReflection(); > > google::protobuf::Message* msg = reflection->MutableMessage > > (&rpcMessage, field); > > msg->CopyFrom(*response); > > Yes. The reflection interface treats regular fields and extensions exactly > the same. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
