我仍应在.NET 4.0中使用BinaryFormatter进行简单序列化吗? [英] Should I Still Use BinaryFormatter for Simple Serialization in .NET 4.0?

查看:84
本文介绍了我仍应在.NET 4.0中使用BinaryFormatter进行简单序列化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个主从样式的应用程序.主应用程序将状态数据发送到从属设备,以一定的速率进行处理和显示.状态数据被包装到一个包含多个字段的类中.这些字段类型由基元,类,接口,接口列表等组成.所有类型都是BCL或自定义类型,因此可以根据需要修改自定义类型.主应用程序和从应用程序都将是.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.

我需要一种快速"的方法来序列化主机上的状态数据,并在从机上反序列化它.当我说快速"时,我更多地是在谈论开发时间(但是,如果解决方案很糟糕,则处理时间可能是一个因素).但是,主从服务器将分布在WAN上,因此某种程度的紧凑性也很不错.

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.

为了快速解决方案,我目前正在考虑仅使用 BinaryFormatter ,然后使用 GZipStream 压缩流.这是.NET 4.0的方法吗?

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?

推荐答案

如果开发速度是关键(特别是因为您有接口等,则需要为某些序列化程序进行适当配置),则也许可以.只要记住将任何事件标记为:

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:

[field:NonSerialized]

其他所有措施上(CPU性能,带宽,版本的健壮性,互操作性,维护成本等),我会选择其他格式:)

On every other measure (CPU performance, bandwidth, robustness as you version, interoperability, cost of maintenance, etc) I would choose other formats :)

以下是个人简介:

WCF绑定使用的序列化性能测试

也许(自从我写了)就不足为奇了,但是我倾向于protobuf-net ...

Perhaps not a surprise (since I wrote it), but I lean towards protobuf-net...

这篇关于我仍应在.NET 4.0中使用BinaryFormatter进行简单序列化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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