I am developing a master-slave style application. The master application will send state data to the slave(s) to process and display at some constant rate. The state data is wrapped up into a single class that contains many fields. These field types consist of primitives, classes, interfaces, lists of interfaces, and so on. All the types are either BCL or custom types, so the the custom types can be modified if necessary. Both the master and and slave applications will be .NET 4.0. I am not concerned with serialization versioning as the master and slave applications will be delivered as a pair.
I need a "quick" way to serialize the state data on the master and deserialize it on the slaves. When I say "quick", I am more talking about development time (but processing time could be a factor if the solution was terrible). However, the master and slaves will be distributed over a WAN, so some level of compactness would be nice also.
For a quick solution, I am currently thinking about simply using BinaryFormatter
and then compressing the stream with GZipStream
. Is this the way to go for .NET 4.0?
BinaryFormatter uses violates 2.), which is a huge security risk because it makes possible to run any code.
Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
In SOAP and BINARY serialization technique the state of the entire object is serialized into a stream of bytes. In cases where the object contains a reference to other objects, even those are serialized. This type of serialization is known as deep serialization.
If speed-of-development is the key (especially since you have interfaces etc, which you need to configure appropriately for some serializers) then maybe. Just remember to mark any events as:
[field:NonSerialized]
On every other measure (CPU performance, bandwidth, robustness as you version, interoperability, cost of maintenance, etc) I would choose other formats :)
Here's a selection profiled:
Performance Tests of Serializations used by WCF Bindings
Perhaps not a surprise (since I wrote it), but I lean towards protobuf-net...
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