On Tue, Jul 20, 2010 at 11:10 PM, Johan Philips <[email protected]>wrote:
> > > On 21 jul, 00:22, Kenton Varda <[email protected]> wrote: > > IMO you should just include a tag field which contains some unique > > identifier, as described in the docs you cite. > > So I just shouldn't have used your extensions mechanism but rather > added to each message a unique id? Adding it now seems duplicate work > since the extension, in my opinion, already make the distinction > between messages. I agree, but we don't have a good API for querying which extension is set. We might fix that someday by introducing language-level support for "unions". > I am just not able to figure out how to query a > message about its extension without knowing all possibilities up > front... > > Using the Reflection API could I do something like this? > > for each defined extension: > > fdExtensions.push_back(msgReflection.findKnownExtensionByName(extensionName)); > > and then in the parse method > > for(int i;i< fdExtensions; i++) > if(msgReflection.HasField(msg,fdExtensions[i]) { > Parser p = parsers.get(fdExtensions[i]); > if(p != null) p.parse() > } > Just use: vector<FieldDescriptor*> fields; msgReflection->ListFields(msg, &fields); for (int i = 0; i < fields.size(); i++) { if (field[i]->is_extension()) { // handle extension } } -- 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.
