On 27 jul, 22:22, Kenton Varda <ken...@google.com> wrote: > > 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".
Ok. So my struggle to find this API is more or less justified :-) > > 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 > } > } Ok thanks! Iterating over the number of fields might be faster than iterating over the number of extensions as I did in my example. -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.