开发者

"Formatter" and "Serializer" - any difference between the terms?

开发者 https://www.devze.com 2023-01-15 17:41 出处:网络
Some things in .NET are called \"formatters\" - 开发者_JAVA技巧BinaryFormatter, SoapFormatter. Others are called \"serializers\" - XmlSerializer, DataContractSerializer.

Some things in .NET are called "formatters" - 开发者_JAVA技巧BinaryFormatter, SoapFormatter.

Others are called "serializers" - XmlSerializer, DataContractSerializer.

Why the difference?


A bit tenuous, but there is a subtle difference. There are 17 concrete classes in the .NET framework that format XML. These formatters are all hidden, you get an instance to them with a method like XmlWriter.Create(). Same for DataContractSerializer, the actual formatting is done by, say, an XmlDictionaryWriter instance.

No such indirection for BinaryFormatter or SoapFormatter, they take care of the formatting themselves. In other words, a Formatter formats, a Serializer uses a formatter.


No, they are synonyms. They do the same: convert CLR object to transferable sequence of bytes.


The differences in the formatters is crucial - BinaryFormatter as it suggests, the data are in native binary fashion, whereas SoapFormatter is in Xml text fashion, throw in the different ways of serializing is actually dependent on the type of formatters, binary data using BinaryFormatter tend to be a lot smaller and faster than soap formatters.

It is for that reason, if you want to take a "memory dump" it is better to use BinaryFormatter and serialize/deserialize away, at the cost of data interoperability between different architectures - meaning it may not be compatible if exchanging data between different platforms BUT faster processing...

Whereas with SoapFormatter it is protected from such binary incompatibilities as it is text based on either Unicode or ASCII, but much slower!

0

精彩评论

暂无评论...
验证码 换一张
取 消