Re: [protobuf] Re: Cannot deserialize protobuf data from C++ in Java
Oh, of course, glad it worked. Also I realized I was mistaken about CodedOutputStream: it doesn't do any internal buffering; it's OstreamOutputStream that does (some other ZeroCopyOutputStream implementations do as well). In any event, keep destroying the streams before you send. On Fri, Apr 15, 2011 at 10:23 AM, platzhirsch wrote: > Oh, maybe this line was flawed after all: > > System.out.println(name.newBuilder().build().toString()); > > Which cannot work, can it? ;-) > > I changed it to name.getName() > > and there it is, the data I've sent, thank you! > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to protobuf@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. > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@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.
Re: [protobuf] Re: Cannot deserialize protobuf data from C++ in Java
yup, that's what I meant. Can you check that you are writing data to the stream? Also, I didn't notice that you are writing the message length as a header. Did you read that value from the socket prior to calling parse? The Java-side parseFrom call should only be reading the data read by SerializeToCodedStream(); you need to consume the WriteLittleEndian32 data separately. On Fri, Apr 15, 2011 at 10:01 AM, platzhirsch wrote: > I am sorry, could you clarify this? With destroy you mean call the > delete operator? The changes: > > boost::asio::streambuf b; > std::ostream os(&b); > > ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&os); > CodedOutputStream *coded_output = new CodedOutputStream(raw_output); > > coded_output->WriteLittleEndian32(name.ByteSize()); > name.SerializeToCodedStream(coded_output); > > delete coded_output; > delete raw_output; > > socket.send(b); > > --- > > This changes nothing, sadly. > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to protobuf@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. > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@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.
Re: [protobuf] Re: Cannot deserialize protobuf data from C++ in Java
On Fri, Apr 15, 2011 at 9:48 AM, platzhirsch wrote: > Right! I think I refactored the whole writing and reading, still I am > stuck. However by this I get this Exception: > com.google.protobuf.UninitializedMessageException: Message missing > required fields: name > > In C++: > > Name name; > name.set_name("platzhirsch"); > > boost::asio::streambuf b; > std::ostream os(&b); > > ZeroCopyOutputStream *raw_output = new OstreamOutputStream(&os); > CodedOutputStream *coded_output = new CodedOutputStream(raw_output); > > coded_output->WriteLittleEndian32(name.ByteSize()); > name.SerializeToCodedStream(coded_output); > You'll need to destroy the CodedOutputStream, which will flush data that's been buffered internally. We should probably make this clearer in the docs. socket.send(b); > > In Java: > > NameProtos.Name name = > NameProtos.Name.parseDelimitedFrom(socket.getInputStream()); > System.out.println(name.newBuilder().build().toString()); > > > --- > > I can't find out where the problem might be. > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To post to this group, send email to protobuf@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. > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to protobuf@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.