On Tue, Jun 16, 2009 at 7:48 PM,
sksh...@gmail.com<
sksh...@gmail.com> wrote:
>
> I am experimenting with "repeated" fields my dot-proto is as follows:
>
> message Foo {
> required string name = 1;
> optional int32 id = 2;
> optional int32 num = 3;
> repeated string sbr = 4;
> repeated int32 wrk = 5;
> }
>
> I build the msg and use foo.SerializeToString(&str) and then sending
> the retult str.c_str() over a socket;
So how do you determine the length of the data you transmit ? c_str()
returns a NUL terminated string. The serialized data might contain a
NUL character somewhere inbetween. If you use use the result of
c_str() to determine the length (like with strlen()), your message
might get truncated. Always use the size() call of the std::string to
determine the size, never something like strlen() or printf("%s") or
something.
Note as well, that a write() might only write the data partially (in
particular to a socket); its return value tells you how much it
actually has written; so write() calls you always need to encapsulate
in a loop.
So your problem is probably not related to repeated fields, but might
be related to how you do the transport; the repeated fields might just
have triggered it if they contain a NUL terminated string.
-h