My problem is to serialize protobuf data in C++ and deserialize the data in Java probably.
Here is the code I use to the hints given by dcn:
With this I create the protobuf data in C++ and write it to an ostream which is send via socket.
ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&os);
CodedOutputStream *coded_output = new CodedOutputStream(raw_output);
This is the Java side where I try to parse it:
NameProtos.Name name = NameProtos.Name.parseDelimitedFrom(socket.getInputStream());
However by this I get this Exception:
**com.google.protobuf.UninitializedMessageException: Message missing required fields: name**
What am I missing?
The flawed code line is: `name.newBuilder().build().toString()`
This would have never worked, a new instance is created with uninitialized name field. Anyway the answer here solved the rest of my problem.
One last thing, which I was told in the protobuf mailinglist: In order to flush the CodedOutputStreams, the objects have to be deleted!
what does your code look like which fills the received array?
以上就是Cannot deserialize protobuf data from C++ in Java的详细内容，更多请关注web前端其它相关文章！