我可以序列化一个对象(含成员:字典,列表...等)的单声道和使用protobuf网反序列化在MS.NET,反之亦然? [英] Can I serialize an object (containing members: Dictionary, List... etc) in Mono and deserialize it in MS.NET or vice versa by using protobuf-net?

查看:423
本文介绍了我可以序列化一个对象(含成员:字典,列表...等)的单声道和使用protobuf网反序列化在MS.NET,反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对MS.NET运行的服务器和单客户端(这是Unity3D引擎),当我尝试的BinaryFormatter()反序列化这样一个对象:

I have a server running on MS.NET and a client on Mono (this is a Unity3D engine) and when i try to BinaryFormatter().Deserialize an object like this:

   [Serializable]   
    public class Simulator  
    {
        public IDictionary<int, Task> tasks = new Dictionary<int, Task>(); 

客户端无法找到/负载类型:字典,列表... 同样的客户端codeMS.NET下运行的工作原理反序列化过程好即没有任何异常。

the client side cannot found/load types: Dictionary, List... The same "client code" running under MS.NET works good i.e. does not have any exceptions during deserialization.

由于我从 http://www.mono-project.com/FAQ阅读: _Technical#这种兼容性是一个普遍的问题:

As i read from http://www.mono-project.com/FAQ:_Technical#Compatibility this is a common problem:

如果你是序列化自己的类,是没有问题的,因为你必须在组件的控制和被用于序列化类。 但是,如果是从序列的框架对象,连续兼容不保证,由于这些对象的内部结构可以是不同的。这种兼容性甚至没有不同MS.NET版本或单声道版本之间的保障。

"If you are serializing your own classes, there is no problem, since you have control over the assemblies and classes being used for serialization. However, if you are serializing objects from the framework, serialization compatibility is not guaranteed, since the internal structure of those objects may be different. This compatibility is not even guaranteed between different MS.NET versions or Mono versions."

请问protobuf网的帮助,以避免/解决这个序列化/反序列化的问题?

Does ProtoBuf-Net help to avoid/resolve this serialization/deserialization problem ?

推荐答案

是的,外部串行化工具,如protobuf网将解决这个问题 - 实际上,一旦你有序列化平台之间的工作(C ++到Java到Python到.NET ),框架的版本少了关注。

Yes, an external serialization tool such as protobuf-net would solve this - indeed, once you have serialization working between platforms (C++ to java to python to .net), framework versions are less of a concern.

所以,是的:连载于protobuf网单声道/统一的数据是完全兼容当.NET加载。但是,应该指出的是,的BinaryFormatter 和protobuf网是的没有的直接1:1等值 - 每个都有稍微不同的特性和行为。例如,protobuf网不走的事件/代表,以及通常不发挥很好地与只知道对象的事情。然而,像字典和列表键/常见方案,完全支持。

So yes: data serialized in protobuf-net on mono / unity is fully compatible when loaded on .NET. However, it should be noted that BinaryFormatter and protobuf-net are not direct 1:1 equivalents - each has slightly different features and behaviors. For example, protobuf-net doesn't walk events/delegates, and doesn't usually play nicely with things known only as "object". However, key/common scenarios like dictionary and list are fully supported.

这篇关于我可以序列化一个对象(含成员:字典,列表...等)的单声道和使用protobuf网反序列化在MS.NET,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆