How to analyse contents of binary serialization stream?

前端 未结 4 483
陌清茗
陌清茗 2020-12-02 08:27

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 a

4条回答
  •  甜味超标
    2020-12-02 09:02

    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:

    • parses its way through the stream, building a collections of object names, counts and sizes
    • once done, outputs a quick summary of what it found - classes, counts and total sizes in the stream

    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:

    • The BinaryFormatter is VERY verbose (this is known, I just didn't realize the extent)
    • I did have issues in my class, it turned out I was storing objects that I didn't want

    Hope this helps someone at some point!


    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.

提交回复
热议问题