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
How to 'compare' graphs. In questions where you are asked to compare, you need to comment on both the similarities and differences. For example, to compare the graph in Figure 1 with the graph in Figure 2 you would say that as both independent variables increase so does the rate of photosynthesis.
The most common way to compare objects in C# is to use the == operator. For predefined value types, the equality operator (==) returns true if the values of its operands are equal, false otherwise. For reference types other than string, == returns true if its two operands refer to the same object.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With