c++ - Exceptions when reading protobuf messages in Java -


i using protobuf weeks, still keep getting exceptions when parsing protobuf messages in java.

i use c++ create protobuf messages , send them boost sockets server socket java client ist listening. c++ code transmitting message this:

boost::asio::streambuf b; std::ostream os(&b);  zerocopyoutputstream *raw_output = new ostreamoutputstream(&os); codedoutputstream *coded_output = new codedoutputstream(raw_output);  coded_output->writevarint32(agentmessage.bytesize()); agentmessage.serializetocodedstream(coded_output);  delete coded_output; delete raw_output;  boost::system::error_code ignored_error;  boost::asio::async_write(socket, b.data(), boost::bind(         &messageservice::handle_write, this,         boost::asio::placeholders::error)); 

as can see write writevarint32 length of message, java side should know using parsedelimitedfrom how far should read:

agentmessage agentmessage = agentmessageprotos.agentmessage                                     .parsedelimitedfrom(socket.getinputstream()); 

but it's no help, keep getting these kind of exceptions:

protocol message contained invalid tag (zero). message missing required fields: ... protocol message tag had invalid wire type. protocol message end-group tag did not match expected tag. while parsing protocol message, input ended unexpectedly in middle of field.  mean either input has been truncated or embedded message misreported own length. 

it important know, these exceptions not thrown on every message. fraction of messages receive work out fine - still fix since not want omit messages.

i gratful if me out or spent ideas.


another interesting fact number of messages receive. total messages of 1.000 in 2 seconds program. in 20 seconds 100.000 , on. reduced messages sent artificially , when 6-8 messages transmitted, there no errors @ all. might buffering problem on java client socket side?

on, let's 60.000 messages, 5 of them corrupted on average.

i not familiar java api, wonder how java deals uint32 value denoting message length, because java has signed 32-bit integers. quick @ java api reference told me unsigned 32-bit value stored within signed 32-bit variable. how case handled unsigned 32-bit value denotes message length? also, there seems support varint signed integers in java implementation. called zigzag32/64. afaik, c++ version doesn't know such encodings. maybe cause problem might related these things?


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -