Everybody wants their game to be optimized as much as possible. While developing a game I’ve faced with an issue when I had to synchronize something very large (let’s assume a List of Entity classes which have their own parameters inside, such as Age, BirthDate, Name, etc.); or I had to write save and load system. Of course you can say, why do I need to serialize that, if I just can pass the raw data of Entity. Well, theoretically you can, but what if Entity class has 10+ parameters and it is not just a single Entity but a bunch of them, would you write something similar to ” void SendEntityData(par1, par2, par3, par4, par5, par6, par7, par8, par9, par10, entity2par1, entity2par2 …) ” ? Apparently, not.
So what’s Serialization? It is the method of compressing your data into the smaller data which is nothing more than byte data. That byte array can be deserialized into the original data which has been compressed previously. There are a lot of serializators, you probably know some of them: JSON, BinaryFormatter, MessagePack, ProtoBuf etc.
Before choosing a serialization method you have to determine you needs, in case if you need human-readability of data; I suggest to use JSON or XML, but be careful with data size and perfomance do not pass this stuff through the network, especially in a Fast-paced multiplayer games =). If human-readability is not the factor and you the data to be encrypted and you need high performance and smallest data size; I suggest ProtoBuf-net. You can and read more about it at: https://github.com/mgravell/protobuf-net
If you previously use the BinaryFormatter then I want to show you a little difference between it and ProtoBuf-net. In the following example List of Entities has been written into the two different files over 1000+ times.
As you can see, protobuf-net is 5x times faster and its file size 10x times less than BinaryFormatter.