简体   繁体   中英

How does IXmlSerializable let me avoid base64's size inflation?

From MSDN :

There are two reasons to implement this interface. The first is to control how your object is serialized or deserialized by the XmlSerializer. For example, you can chunk data into bytes instead of buffering large data sets, and also avoid the inflation that occurs when the data is encoded using Base64 encoding.

How does implementing IXmlSerializable let me avoid base64's size inflation?

I mean, imagine I've implemented IXmlSerializable and I want to write a byte-array to the XmlWriter. The least inflating way to do that is XmlWriter.WriteBase64, as far as I know - since I cannot write the data directly - it would contain bytes invalid in XML.

Yes, base64 is not very efficient. The assumption here is that you could encode the byte[] yourself in a different way and save space. Maybe a run-length encoding. Maybe you can gzip the array and base64 encode the compressed data. Something like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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