8

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?

dewald
  • 5,133
  • 7
  • 38
  • 42
  • 2
    BinaryFormatter is fine, no need to drag around a 3rd party solution for your needs and its dead-simple to use. Don't use the GZipStream, it only adds overhead. Memory bandwidth is too high to let it pay off. – Hans Passant Mar 12 '11 at 19:17
  • @Hans: He's talking about sending the data over a WAN (which probably means bandwidth less than 10Mbps). I would think `GZipStream` is almost mandatory for this application. – Gabe Mar 12 '11 at 19:40

2 Answers2

5

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...

Community
  • 1
  • 1
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Great point on marking events with `[NonSerialized]`. I didn't think about that. – dewald Mar 12 '11 at 20:31
  • The perf tests of protobuf-net are very impressive. Will your library work for my case? I have to serialize interfaces and lists of interfaces. Some of these interfaces represent immutable objects; i.e. they only have getter properties, and the implementation classes have private setters. – dewald Mar 13 '11 at 00:06
  • @dewald until about a week ago it would have struggled with that; last weekend I added a feature that would enable that, by storing the *underlying* type's details - an ugly answer to a very common request. See my blog for more. – Marc Gravell Mar 13 '11 at 00:21
2

Have a look at Protocol Buffers here: Fast and compact object serialization in .NET

Community
  • 1
  • 1
Nariman
  • 6,368
  • 1
  • 35
  • 50