On Feb 6, 2010, at 3:11 , hap 497 wrote:
// put the serialized content to a buffer so that I can write
it to socket
char buf[128];
memset((char *) buf, 0, 128);
memcpy (buf, msgStr.c_str(), requestMessage.ByteSize());
You can use msgStr.c_str() and msgStr.data() directly: call the
write() system call without copying the data to a temporary buffer.
// pretend the receiving end get the serialized content from
// socket and try to reconstruct the message
MyMessage msg2;
if (msg2.ParseFromString(string(buf))) {
If you use that constructor, std::string assumes buf is a NULL
terminated C string. You should use the following to create the string
with a specific length:
string another_copy(buf, msgStr.size());
Evan
--
Evan Jones
http://evanjones.ca/
--
You received this message because you are subscribed to the Google Groups "Protocol
Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.