如何分析二进制序列化流的内容是什么? [英] How to analyse contents of binary serialization stream?

查看:160
本文介绍了如何分析二进制序列化流的内容是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是二进制序列(的BinaryFormatter)作为临时机制来存储在一个相对复杂的(游戏)对象结构的文件状态信息;这些文件现身比我预期的大,我的数据结构包括递归引用 - 所以我想知道的BinaryFormatter是否实际存储相同对象的多个副本,还是我的基本号对象和我应该有值arithmentic是遥远基地,或别的地方的尺寸过大的来源。

I'm using binary serialization (BinaryFormatter) as a temporary mechanism to store state information in a file for a relatively complex (game) object structure; the files are coming out much larger than I expect, and my data structure includes recursive references - so I'm wondering whether the BinaryFormatter is actually storing multiple copies of the same objects, or whether my basic "number of objects and values I should have" arithmentic is way off-base, or where else the excessive size is coming from.

搜索上的堆栈溢出我能找到规范微软二进制格式远程:
http://msdn.microsoft。 COM / EN-US /库/ cc236844(PROT.10)的.aspx

Searching on stack overflow I was able to find the specification for Microsoft's binary remoting format: http://msdn.microsoft.com/en-us/library/cc236844(PROT.10).aspx

我找不到任何现有的浏览器,使您能够偷看插入的BinaryFormatter输出文件的内容 - 获取对象计数和总字节的文件等在不同的对象类型;

What I can't find is any existing viewer that enables you to "peek" into the contents of a binaryformatter output file - get object counts and total bytes for different object types in the file, etc;

我觉得这一定是我的谷歌赋没有我(我有什么小) - 谁能帮助?这的必须的都做过吧?

I feel like this must be my "google-fu" failing me (what little I have) - can anyone help? This must have been done before, right??

更新:我无法找到它,并没有得到回应,所以我把东西比较快在一起(链接到下载以下项目);我可以确认的BinaryFormatter不存储相同的对象的多个拷贝,但它并打印相当多的元数据流中。如果你需要高效的存储,构建自己的自定义序列的方法。

UPDATE: I could not find it and got no answers so I put something relatively quick together (link to downloadable project below); I can confirm the BinaryFormatter does not store multiple copies of the same object but it does print quite a lot of metadata to the stream. If you need efficient storage, build your own custom serialization methods.

推荐答案

瓦西里是正确的,我将最终需要实现我的自己的格式/序列化进程,以更好地处理版本并输出更加紧凑流(压缩前)。

Vasiliy is right in that I will ultimately need to implement my own formatter/serialization process to better handle versioning and to output a much more compact stream (before compression).

我也想明白了什么流中发生的事情,然而, ,所以我写了一个(相对)快班做什么,我想要的是:

I did want to understand what was happening in the stream, however, so I wrote up a (relatively) quick class that does what I wanted:


  • 通过流解析的方式,建立一个集合对象名称,数量和大小

  • 完成一次,输出的是什么发现了一个快速的总结 - 类,数量和总大小的流

这是不够有用,我把它像CodeProject上显眼的地方,所以我只是把这个项目中的zip文件在我的网站:http://www.architectshack.com/BinarySerializationAnalysis.ashx

It's not useful enough for me to put it somewhere visible like codeproject, so I just dumped the project in a zip file on my website: http://www.architectshack.com/BinarySerializationAnalysis.ashx

在我的特定情况下,它原来,问题是双重的:

In my specific case it turns out that the problem was twofold:


  • 的BinaryFormatter的是非常详细(这是已知的,我只是没有意识到的程度)

  • 我也有我的阶级问题,原来我被存储,我不希望对象

!希望这可以帮助别人在某些时候

Hope this helps someone at some point!

更新:伊恩·赖特和我联系了一个问题与原来的代码,它时坠毁源对象(S)载十进制的价值观。这是现予以更正,我也利用这个机会的代码移到GitHub上,并给它一个(许可,BSD)许可证。

Update: Ian Wright contacted me with a problem with the original code, where it crashed when the source object(s) contained "decimal" values. This is now corrected, and I've used the occasion to move the code to GitHub and give it a (permissive, BSD) license.

这篇关于如何分析二进制序列化流的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆