让 .NET Compact Framework 支持 Binnary Serialization

智能设备上的存储空间比较有限,如果能把内存中的数据保存为二进制文件,无论是执行效率还是存储空间,都比文本文件更具优势。为了更有效地利用存储空间,很多人想把对象序列化为二进制数据流并写入磁盘中,但恰恰在 .NET Compact Framework 里面就是找不到 Binnary Serialization 相关的类。
今天发现了一个叫 CompactFormatter 的组件,可以让你在 .NET CF 中实现二进制序列化。

What is the CompactFormatter?
The CompactFormatter is a generic formatter for the .NET Compact Framework. It is fully realized in .NET managed code and this means that it is able to work on every device able to support the .NET Compact Framework or every other standard-compliant CLI implementation.

Even if the CompactFormatter is able to serialize automatically the majority of objects using Reflection, it allows programmers to redefine the serialization algorithm of custom objects if this is needed ( such as, for example, if a custom serialization algorithm is more efficient than the standard one ).

The interface that the CompactFormatter class expose to the user is very similar to the BinaryFormatter ( or SOAPFormatter ) one and so using it ( or, to some extents, porting applications from .NET to it ) should be very simple for people who knows how to use standard .NET Full Formatters.

CompactFormatter is still in Beta (even if we reached 1.0.0 version) simply because it needs more testing. I hope to remove the beta status in a couple of months if no critical problems will be reported.

CompactFormatter is and will always be released under the LGPL License.

Features
·Able to serialize primitive types automatically.
·Able to serialize user-defined types automatically.
·Thanks to Surrogate and Overrider mechanism, allows a safer serialization even of framework types.
·Uses an interface very similar to standard Binary/SOAP formatters used in .NET
·Supports NotSerializable fields, that are fields which must not be serialized.
·Produces a data stream more compact than the one used by .NET BinaryFormatter.
·It is faster than BinaryFormatter and SOAPFormatter.
·Allows users to redefine serialization mechanism of their classes (Custom Serialization).
·It correctly rebuilds the object reference graph.
·Allows the use of user-defined StreamParsers, these are wrapper around serialization stream (useful to implement transformations just before sending the stream on the wire: soon available StreamParsers will allow zip compression and TEA data encryption out of the box.)
·Fully implemented in .NET managed code.

http://www.freewebs.com/compactFormatter/index.html

我还没有测试过,有需要在 .NET CF 下实现二进制序列化的朋友可以试一试:)

posted @ 2006-05-20 16:58  黎波  阅读(2762)  评论(1编辑  收藏  举报