12

In our Client/Server Application we've been using BinaryFormatter for the serialization process. For performance reasons we are trying to migrate to protobuf-net ( http://code.google.com/p/protobuf-net/ ).

Our software transmits huge graphs with cycles between Client and Server.

Now I am looking for a way to make sure that the data which was serialized and deserialized using protobuf is exactly the same as the one which was usually processed by BinaryFormatter.

A bit by bit comparison is simple: I serialize using BinaryFormatter to a file. Deserialize this file again using BinaryFormatter. Then I serialize using ProtoBuf into a file. Deserialize using ProtoBuf from that file. Serialize again using BinaryFormatter into a file.

Then i can simply compare that file with the original file.

However, those two files are not 100% equal. So now I need to find a way to track the differences down.

Is there maybe some tool out there which visualizes data that was serialized by BinaryFormatter? Or do you know some other helper which does a deep comparison and tells me where the differences are?

Using XMLSerializer and comparing two XML files is not possible as BinaryFormatter is able to serialize way more data than the XMLSerializer - even without marking fields explicitly.

Thank you, TH

TwinHabit
  • 753
  • 8
  • 22
  • I have plenty of code here on SO for comparing individual objects, but comparing an entire graph is... tricky. If I had to *guess*, I would wonder if there are tiny datetime precision differences. – Marc Gravell Jul 12 '11 at 08:20
  • Hey Marc. If the files were almost identical I would guess the same. However, I am lacking roughly 25% of the data. Now I am wondering if, for example, instance references got shared although they shouldn't (because the original references were not pointing to the same object) or if I just forgot to add certain fields to the TypeModel. Some tool would be great that simply plots the whole object graph to a human readable graph (similar to what http://ignatu.co.uk/ViewStateDecoder.aspx does (however that algorithm doesn't work with our huge graphs)) – TwinHabit Jul 12 '11 at 08:34

2 Answers2

6

How about using DataContractSerializer with object-tracking enabled (preserveObjectReferences in the constructor). That should allow you to serialize them to xml (of a sort, at least), where you might be able to compare the differences.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Great idea. I'll give it a shot. Btw I just found one huge difference which is a consequence of failed reference handling. The problem here is that the Object we are serializing is already a List. However I didn't find a possibility in your API to specify that reference tracking should be enabled for this top level object. I only know it's possible to enable it on Members. So one workaround would be to provide a container class for the collection and enable Reference Tracking on the contained collection. But enabling it on the top level object would be smoother. Is that already possible? – TwinHabit Jul 12 '11 at 11:20
  • @TwinHabit not without significant changes, I'm afraid - protocol buffers has absolutely no notion of *the list as an object*, which leads to a number of oddities. It *only* knows about items. Basically, on the wire you get "parent child child child child" - never "parent list child child child child" (if you see what I mean) – Marc Gravell Jul 12 '11 at 11:39
  • Maybe we could enhance the library by a feature which transparently moves objects of custom List Types to dynamically created container classes? That would solve two problems: One could easily carry fields with custom lists as well as activate Reference tracking in the top level List Object. The problem we're having now is that we will have to change the client/server interfaces because some methods only return lists.. but let's see. Maybe I can persuade them. – TwinHabit Jul 12 '11 at 11:43
5

We had the same problem. We Json serialize the two objects (with formatting, indentation, new lines etc) and then use a simple text diff. It will tell you not only that they're different, but exactly what the difference is.

nganju
  • 720
  • 6
  • 16