Hi,
I have C++ code:
TestMsg *pbTestMsg = new TestMsg();
pbTestMsg->set_acid("7777");
pbTestMsg->set_name("Yong");
int varIntSize =
google::protobuf::io::CodedOutputStream::VarintSize32(pbTestMsg->ByteSize());
google::protobuf::io::ArrayOutputStream
arrayOut(pbBodyBuffer, (pbTestMsg->ByteSize() + varIntSize));
google::protobuf::io::CodedOutputStream coded_output(&arrayOut);
coded_output.WriteVarint32(pbTestMsg->ByteSize());
pbTestMsg->SerializeToCodedStream(&coded_output);
//then send pbBodyBuffer over tcp/ip socket
Receiving C++ worked fine, but receiving Java give me null testMsg.
Receiving Java side code:
int totalBodyBytes =13;
byte[] bodyBytes = new byte[maxMessageSize];
//BufferedInputStream in
bytesRead = in.read(bodyBytes, 0, totalBodyBytes);
if(bytesRead == totalBodyBytes){
System.out.println("\nOK TotalBytesRead: " + bytesRead);
}else{
System.out.println("\n bytesReads != totalBodyBytes");
System.exit(0);
}
//It could read all 13 bytes
ByteArrayInputStream inStream = new ByteArrayInputStream(bodyBytes, 0,
totalBodyBytes);
Test.TestMsg testMsg = Test.TestMsg.parseDelimitedFrom(bodyBytes);
//Now I have null testMsg
Could anybody help me out?
Anthony,
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.