Hi all,

I'm just getting to grips with protobuf and, having read through the 
documentation, I'm struggling to find what I'm after.

Basically I'm trying to work out how to deserialize a protobuf message 
without using the generated headers, as we're likely to get messages that 
weren't generated at compile time. I've looked through the documentation, 
but I only seem to be able to find ones that use generated classes to 
deserialize, or that use a Descriptor from a generated class to create a 
DynamicMessage, which I can't seem to work out how to do when we don't have 
the proto.

Here's a very simple example of what I mean, where Message* is set to some 
base type that allows deserialization, and then can use the reflection API 
(or some factory) to correctly deal with the message:

#include <sstream>

#include "google/protobuf/message.h"
 int main(int argc, char **argv)
{
  if( argc > 1)
  {
    // This will fail to compile, as Message is pure abstract
    google::protobuf::Message* message = NULL; //new 
google::protobuf::Message();
    std::istringstream ss(std::string(argv[1],strlen(argv[1])));
 
    message->ParseFromIstream(&ss);
 
    // do something with the message
    // ...
  }
 
  return 0;
}


Apologies in advance if this has already been answered...

Thanks

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to