IXmlSerialized 如何让我避免 base64 的大小膨胀?
来自 MSDN:
实现这个接口有两个原因。第一个是控制 XmlSerializer 序列化或反序列化对象的方式。例如,您可以将数据分块为字节,而不是缓冲大型数据集,还可以避免使用 Base64 编码对数据进行编码时出现的膨胀。
实现 IXmlSerialized 如何让我避免 base64 的大小膨胀?
我的意思是,假设我已经实现了 IXmlSerialized 并且我想将一个字节数组写入 XmlWriter。据我所知,最不膨胀的方法是 XmlWriter.WriteBase64 - 因为我无法直接写入数据 - 它会包含 XML 中无效的字节。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,base64 效率不是很高。这里的假设是您可以自己以不同的方式对 byte[] 进行编码并节省空间。也许是游程编码。也许您可以对数组进行 gzip 压缩并对压缩数据进行 base64 编码。类似的事情。
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.