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
}
I
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
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 ev...@mit.edu wrote:
Brad Lira wrote:
On Wed, Nov 10, 2010 at 08:23, Brad Lira snmp.apa...@gmail.com 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
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
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 ev...@mit.edu 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
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