我是否仍应使用 BinaryFormatter 在 .NET 4.0 中进行简单序列化?
我正在开发一个主从式应用程序。主应用程序将状态数据发送到从应用程序以某种恒定速率进行处理和显示。状态数据被包装到包含许多字段的单个类中。这些字段类型由基元、类、接口、接口列表等组成。所有类型都是 BCL 或自定义类型,因此可以根据需要修改自定义类型。主应用程序和从应用程序都将是.NET 4.0。我不关心序列化版本控制,因为主应用程序和从应用程序将作为一对交付。
我需要一种“快速”的方法来序列化主机上的状态数据并在从机上反序列化它。当我说“快”时,我更多地谈论开发时间(但如果解决方案很糟糕,处理时间可能是一个因素)。然而,主设备和从设备将分布在 WAN 上,因此一定程度的紧凑性也很好。
为了快速解决方案,我目前正在考虑简单地使用 BinaryFormatter
,然后使用 GZipStream
压缩流。这是 .NET 4.0 的发展方向吗?
I am developing a master-slave style application. The master application will send state data to the slave(s) to process and display at some constant rate. The state data is wrapped up into a single class that contains many fields. These field types consist of primitives, classes, interfaces, lists of interfaces, and so on. All the types are either BCL or custom types, so the the custom types can be modified if necessary. Both the master and and slave applications will be .NET 4.0. I am not concerned with serialization versioning as the master and slave applications will be delivered as a pair.
I need a "quick" way to serialize the state data on the master and deserialize it on the slaves. When I say "quick", I am more talking about development time (but processing time could be a factor if the solution was terrible). However, the master and slaves will be distributed over a WAN, so some level of compactness would be nice also.
For a quick solution, I am currently thinking about simply using BinaryFormatter
and then compressing the stream with GZipStream
. Is this the way to go for .NET 4.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果开发速度是关键(特别是因为您有接口等,您需要为某些序列化器进行适当配置),那么也许可以。只需记住将任何事件标记为:
在所有其他衡量标准(CPU 性能、带宽、版本鲁棒性、互操作性、维护成本等)中,我会选择其他格式:)
以下是一个选择:
WCF 绑定使用的序列化的性能测试
也许并不奇怪(因为我写了它),但我倾向于 protobuf-net ......
If speed-of-development is the key (especially since you have interfaces etc, which you need to configure appropriately for some serializers) then maybe. Just remember to mark any events as:
On every other measure (CPU performance, bandwidth, robustness as you version, interoperability, cost of maintenance, etc) I would choose other formats :)
Here's a selection profiled:
Performance Tests of Serializations used by WCF Bindings
Perhaps not a surprise (since I wrote it), but I lean towards protobuf-net...
在这里查看 Protocol Buffers:.NET 中的快速且紧凑的对象序列化
Have a look at Protocol Buffers here: Fast and compact object serialization in .NET