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.
精彩评论