开发者

Deserializing a List of messages with protobuf-net

开发者 https://www.devze.com 2023-01-16 15:55 出处:网络
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(your

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 o开发者_StackOverflowlder 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消