简体   繁体   English

不同平台上的对象序列化

[英]Object Serialization on different platform

Hi guys I'm creating a very simple socket server that lets its clients save its own object state based on Keys by sending it over the wire. 嗨,大家好,我正在创建一个非常简单的套接字服务器,该套接字服务器可以通过通过有线方式将其客户端保存为基于Key的对象状态。 I'm using a very simple protocol encoding the serialized object to base64 string and will be sent out as part of my custom xml format. 我正在使用一个非常简单的协议,将序列化的对象编码为base64字符串,并将作为我的自定义xml格式的一部分发送出去。 I wanted to know if the serialization will still be the same if the client app runs on 32-bit and 64-bit Windows and using .net Framework? 我想知道如果客户端应用程序在32位和64位Windows上运行并使用.net Framework,序列化是否仍然相同? will this also be the same if all client apps are created using c++ but runs on different platforms? 如果所有客户端应用程序均使用c ++创建但运行在不同平台上,这是否也会相同?

Serialization between 32 and 64-bit CLRs shouldn't be a problem, but if you want to be able to serialize on non-.NET platforms, you shouldn't use the default binary serialization. 在32位和64位CLR之间进行序列化应该不是问题,但是,如果您希望能够在非.NET平台上进行序列化,则不应使用默认的二进制序列化。 Personally I wouldn't use that anyway, as it can be tricky to handle in terms of versioning etc. 就个人而言,我不会使用它,因为在版本控制等方面可能很难处理。

There are plenty of other serialization options available: 还有许多其他序列化选项可用:

  • XML serialization (either the built-in or hand-rolled) XML序列化(内置或手动滚动)
  • Thrift 节约
  • YAML YAML
  • JSON JSON格式
  • Protocol Buffers (I declare an interest: I've written one of the ports of Protocol Buffers to C#) 协议缓冲区(我声明有兴趣:我已将协议缓冲区的端口之一写入C#)

All of these are likely to work better across multiple platforms. 所有这些都可能在多个平台上更好地工作。 Some are human readable as well, which can sometimes be useful. 有些也是人类可读的,有时可能有用。 (Protocol Buffers aren't human readable, but it's easy to dump a text version of a protocol buffer message.) (协议缓冲区不是人类可读的,但转储协议缓冲区消息的文本版本很容易。)

Some effectively build their own object model via a separate schema, whereas others will cope (to a greater or lesser degree) with your existing object model. 有些通过单独的模式有效地构建了自己的对象模型,而另一些则将(或多或少地)应对您现有的对象模型。

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

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