Re: [protobuf] fails to parse from string

2010-11-10 Thread Brad Lira
hmmm, i have to use UDP in my case, TCP is not an option. On Wed, Nov 10, 2010 at 2:40 PM, Evan Jones wrote: > On Nov 10, 2010, at 14:13 , Brad Lira wrote: >> >> yes it was the null character, on the server side when copying buffer >> into string, i had add 1 to the >> size of the buffer (i gues

Re: [protobuf] fails to parse from string

2010-11-10 Thread Evan Jones
On Nov 10, 2010, at 14:13 , Brad Lira wrote: yes it was the null character, on the server side when copying buffer into string, i had add 1 to the size of the buffer (i guess for the null), then the parsing was ok with no error. Just adding 1 is still probably not correct. You have similar in

Re: [protobuf] fails to parse from string

2010-11-10 Thread Henner Zeller
On Wed, Nov 10, 2010 at 08:23, Brad Lira wrote: > client side: > > address_book.SerializeToString(&mystr) > strncpy(buf, mystr.c_str(), strlen(mystr.c_str())); This is an error - you only copy to the first \0 byte (strlen looks for a nul-terminated string) -- however, the string contains binary d

Re: [protobuf] fails to parse from string

2010-11-10 Thread Brad Lira
thanks, yes it was the null character, on the server side when copying buffer into string, i had add 1 to the size of the buffer (i guess for the null), then the parsing was ok with no error. On Wed, Nov 10, 2010 at 1:42 PM, Evan Jones wrote: > Brad Lira wrote: >> >> address_book.SerializeToSt

Re: [protobuf] fails to parse from string

2010-11-10 Thread Evan Jones
Brad Lira wrote: address_book.SerializeToString(&mystr) strncpy(buf, mystr.c_str(), strlen(mystr.c_str())); strlen will return a shorter length than the real length, due to null characters. Use mystr.size() Maybe this method is not the right way to send string across socket. I tried using

Re: [protobuf] fails to parse from string

2010-11-10 Thread Brad Lira
client side: address_book.SerializeToString(&mystr) strncpy(buf, mystr.c_str(), strlen(mystr.c_str())); sendto(socket, buf, ) server side: recvfrom(socket, buf, ) mystr.assign(buf, strlen(buf)); if (address_book.ParseFromString(mystr) == false) { print "deserialization failed" }

Re: [protobuf] fails to parse from string

2010-11-09 Thread Kenton Varda
It sounds like you probably have extra bytes at the end of mystr which are not part of the protobuf. The parser parses everything before those bytes just fine, but then chokes when it gets to the bytes it doesn't recognize. Please make sure you only pass in the exact bytes which came out of the s

Re: [protobuf] fails to parse from string

2010-11-09 Thread Evan Jones
On Nov 9, 2010, at 16:11 , Brad Lira wrote: it returns false, but it actually gets the message correctly from client side, so i am not sure why it thinks that parsing has failed. any ideas? How are you putting data into mystr? Protocol buffers contain null bytes, so you must pass both a char*

[protobuf] fails to parse from string

2010-11-09 Thread Brad Lira
I have a c++ client/server application that sends messages using protocol buffers, however, at the server side, when i call address_book.ParseFromString(mystr) it returns false, but it actually gets the message correctly from client side, so i am not sure why it thinks that parsing has failed. an