简体   繁体   English

使用protobuf-net反序列化邮件列表

[英]Deserializing a List of messages with protobuf-net

I have a java backend that sends messages using protobuf, it sends delimited message objects in one big byte array blob over tib. 我有一个Java后端,它使用protobuf发送消息,它通过tib在一个大字节数组blob中发送定界的消息对象。 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. 我可以使用Java中的parseDelimitedFrom(yourStreamHere)函数对它们进行反序列化,但是在C#方面,我们遇到了一些问题,我找不到任何示例,但我可能只是在这里遗漏了一些明显的东西。

We are doing something in C# like this 我们正在C#中做这样的事情

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 注意:我看到了一篇较旧的文章 ,但看起来过时了,我认为此后protobuf-net发生了变化,但如果我错了,那就可以纠正

The developer was using tag 0 and prefix style 128 at one point yesterday like so 开发人员昨天在某处使用标签0和前缀样式128

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. 今天,当我们在C#端调用getProto时,似乎是将设置为double类型的属性转换为fixed64类型,而在Java方面,我们指定了double,因此我认为这种不匹配导致了我们看到的错误。 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. 当然,理想情况下,我们不想在不需要时发送字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM