On Tue, Feb 12, 2013 at 6:13 AM, Predator33 <[email protected]> wrote:

> I'm trying to store information in a protobuf structure so that I can
> serialize it and send it over a UDP connection, and deserialize it on the
> other end.
>
> The issue I'm having is if i have:
>
> message Something {
> optional string somestr = 1;
> optional int32 someint1 = 2;
> optional int32 someint2 = 3;
> }
>
> If I set any of those integers to 0, deserializing fails. I believe this
> has to do with the fact that I use SerializeToString and ParseFromString
> using std::string and stringstreams. So, I was going to try and use
> WriteRawData or something..could somebody give me a code sample of doing
> such a thing? All the examples I manage to find are with strings and/or
> file output.
>
> I believe the deserializing is failing because the string is seeing the 0
> as a NUL terminator..is trhe only conclusion I can come to.
>
Using string to hold binary data (including "\x00") is perfectly fine with
protobuf.
I think the problem is that you accidentally trimmed the data somewhere
yourself.


>
> So really I just need to know how to serialize 2 messages into binary
> data, and send it over the wire. To do two messages together, I'm just
> storing the size of the SerializeToString of the first message, then the
> data, and the same thing for the second.
>
>  --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to