On Fri, Apr 15, 2011 at 2:06 AM, platzhirsch
<[email protected]>wrote:
> My problem is to serialize protobuf data in C++ and deserialize the
> data in Java probably. In fact I get **InvalidProtobufferException**
> in Java.
>
> Here is my minimal example:
>
> My protobuf file looks like this:
>
> option java_outer_classname = "NameProtos";
>
> message Name {
>
> required string name = 1;
> }
>
> Which I compile with:
>
> protoc -I=. --cpp_out=../cpp/ name.proto
>
> and
>
> protoc -I=. --java_out=../java/ name.proto
>
>
> In C++ I create the name object this way:
>
> Name name;
> name.set_name("platzhirsch");
> socket.send(name.SerializeAsString);
>
> In Java I read from the socket, until the socket is closed
> (socket.send closes the connection, after it entirely wrote the string
> passed, so I guess here is no when stop reading issue, isn't there?).
>
> In Java I make the following call in order to deserialize:
>
> `NameProtos.Name name =
> NameProtos.Name.parseFrom(ByteString.copyFromUtf8(received))`;
>
The serialized data is binary and not valid UTF8. The conversion here
corrupts the data - make sure to parse the exact bytes that are serialized.
>
> However I always get **InvalidProtocolBufferException**
>
> I have no idea, the received strings are not empty though, they look
> like this:
> [SPACE]platzhirsch[A Character which cannot be displayed probably]
>
> These character which I cannot read, I also get, when using other
> fields like int32. I guess there are just encoded into the string.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.