views:

128

answers:

1

I have a java backend that sends messages using protobuf, it sends delimited message objects in one big byte array blob over tib. I can deserialize them fine using the function parseDelimitedFrom(yourStreamHere) in java but on the C# side we are having some issues and I couldn't find any examples but I may just be missing something obvious here.

We are doing something in C# like this

using (MemoryStream mem = new MemoryStream()) 
{ 
    mem.Write(byteArray, 0, byteArray.Length); 
    mem.Position = 0;     
    return Serializer.Deserialize<List<OrderState>>(mem); 
}

Note: I saw an older post on this but it looked pretty dated and I think changes have occurred to protobuf-net since then but correct if I'm wrong there

+1  A: 

The developer was using tag 0 and prefix style 128 at one point yesterday like so

IEnumerable<SomeObject> list =  (Serializer.DeserializeItems<SomeObject>(memoryStream, PrefixStyle.Base128, 0));

but we were still getting an error. When we called getProto on the C# side today it appears it was converting our properties that were set to the double type to the fixed64 type, on the java side we had specified double so I think this mismatch was causing the errors we were seeing. We temporarily changed those fields to the string type and now the above snippet works. Of course ideally we don't want to send strings when we don't have to.

Jeremy T
> converting our properties that were set to the double type to the fixed64 type - do you mean when generating a .proto? or on the wire? There is a recent fix to .proto generation for this, but this doesn't change the actual serialization.
Marc Gravell
I believe when generating the .proto on the C# side, but when the requests from the java services were coming in it was giving us an exception probably because the incoming request was using a double but the C# definition had a fixed64, or are you saying this wouldn't ever occur?
Jeremy T
@Jehud - what is confusing (to me) is that on the wire both use an identical format. It was only GetProto that was affected, so I'm confused...
Marc Gravell
Yeah me too then, when we circle back in a bit to optimize the field types from string to something more specific if I see errors again I'll revisit this thread with details
Jeremy T