Hi,

I am sending messages from a C++ client to a Java server, but I am
wondering about the length of the buffer I am using to send it over.
This is the C++ code:

CLIENT SIDE CODE:
*** the protocol buffers message is called snap1 ***

int numBytesForDelim = sizeof(int);
char *snap_buf2;
snap_buf2 = new char[snap1.ByteSize() + 100];

ZeroCopyOutputStream* raw_output = new ArrayOutputStream(snap_buf2,
snap1.ByteSize()+numBytesForDelim);
            CodedOutputStream* coded_output = new
CodedOutputStream(raw_output);

coded_output->WriteVarint32(snap1.ByteSize());
snap1.SerializeToCodedStream(coded_output);

delete coded_output;
delete raw_output;

send(socket, snap_buf2, snap1.ByteSize()+numBytesForDelim/2, 0);  //
send over a socket
delete [] snap_buf2;
snap_buf2 = NULL;

When I send this over to the Java server side, the Java code uses
"parseDelimitedFrom" to parse the data.  however, I am not sure why
when I call send, the length of the message has to be snap1.ByteSize()
+numBytesForDelim/2 rather than snap1.ByteSize()+numBytesForDelim.  I
would think that it would be the latter, but when I try it, I get
exceptions on the Java side saying that the protocol message has not
filled out all the fields.  For some reason, it is necessary for me to
cut off the last two bytes when sending over TCP.  Any ideas as to why
this is?

Thanks a lot!

Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to