On Thu, Sep 22, 2011 at 03:32, Suraj <surajn.v...@gmail.com> wrote: > Hi, > > Say I have two messages a and b of types A and B respectively. > > Can I serialize them to the same string? > Something like.. > a.SerializeToString(&str); > b.SerializeTostring(&str_new); > str.append(str_new); > > Then while parsing, I will do, > a.ParseFromString(str) > and b.ParseFromString(str). > > I have tried this and it is working. But want to confirm whether it's > a correct thing to do or not?
What you get is that message a and b both have the same content, more precisely, the merged content of both the original messages ( see http://code.google.com/apis/protocolbuffers/docs/encoding.html#optional for merging ). Not sure if this is what you want. If you want to serialize multiple different messages in one string, you need to put them in some kind of container format, e.g. <length1><message1><length2><message2> .... this has been discussed on this list several times. You also find documentation in 'Techniques' http://code.google.com/apis/protocolbuffers/docs/techniques.html -h -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to email@example.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.