IMO you should just include a tag field which contains some unique identifier, as described in the docs you cite.
The reflection interface, if you want to use it, is documented here: http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html#Reflection On Fri, Jul 16, 2010 at 12:16 AM, Johan Philips <johanphil...@gmail.com>wrote: > Hello > > I was wondering what was the best way to parse messages with > extensions in C++. In the documentation I found this sentence: > "Note that you can use the ListFields reflection method (in C++, Java, > and Python) to get a list of all fields present in the message, > including extensions. You might use this as part of a scheme for > registering handlers for diverse message types." > > However no further information is given and I am a bit puzzled on how > to use this reflection interface. For now I just check every single > expected extension using the HasExtension but I'd like something more > generic and cleaner which does not explode whenever more message types > are added: > > if(msg.HasExtension(RobotDataProtocol::acknowledge_ext)) { > ... > } else if(msg.HasExtension(RobotDataProtocol::assistance_ext)) { > ... > } else if(msg.HasExtension(RobotDataProtocol::dynamicWindow_ext)) { > ... and so on > > Should be something like (with parsers a map with a parser for each > known extension) > Parser p = parsers.get(msg.extensionType()); > if(p != null) > p.parse(msg); > > Any other more generic solution are also highly appreciated! > > Kind regards > > Johan > > -- > 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<protobuf%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > > -- 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.