2

Supose I have a WCF service which sends List serialized with protobuf-net. That function returns byte[], application/octet-stream.

Now, in my java application I have compiled MyClass.proto into MyClass.java and get from http the data sent before.

To deserialize 1 object I shall use

MyClass MyObject = MyClass.parseFrom(http_input_stream);

But what shall I use if an array comes...?

1
  • What do you mean "if an array comes...?" ? I'm assuming your java code is based on a .proto, which presumably has that data as repeated. It should just populate into the correct data structures. Assuming you managed to get the same underlying data (the byte[]) into java that you produced in C# (check that first: all bets are off if you haven't managed to successfully transfer the byte[]) Commented Jun 11, 2012 at 19:22

2 Answers 2

2

A List<MyClass> is actually serialized as a sequence of MyClass objects, each with a standard field-header of 1. I don't know the java API backwards: if it has a "read a sequence of items" API then: use that. However, a trusty fallback is the following, entirely compatible ".proto" fragment:

message Foo {
    repeated MyClass items = 1;
}

Load the data as a Foo (you might want to rename that...) and: job done.

Sign up to request clarification or add additional context in comments.

Comments

2

Well I ended up by creating another proto message

message MyClassCollection {
    repeated MyClass = 1;
}

Then compile it into java class and deserialize the incoming array like

MyClassCollection MyObjects = MyClassCollection.parseFrom(http_input_stream);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.