Be the first to write a review
Free! - CompactFormatterPlus: Generic Serializer
Extreme performance and Serialization Studio
Original CompactFormatter uses surrogates, overrides and custom serialization for the better performance. This certainly works; however writing the surrogate is always tricky and tedious business even for the experienced programmer. To make this task easier, custom serialization and surrogates were removed.
Instead now there is just one custom serialization – an override.
Override (in Angello's Scotto terms) is the original mechanism that allows for injecting custom serialization modules for the specific class. Also CompactFormatter has been redesigned for including automatically generated binary serializers. Serialization Studio is the tool that generates binary super fast serializers (10-60 times faster than BinaryFormatter).
The tool is free and can be downloaded from www.dotnetremoting.com. This tool is specifically tuned to generate the surrogate for CompactFormatterPlus.
Adding the fast serializer to CompactFormatterPlus:
CompactFormatterPlus cfp = new
CompactFormatterPlus();
MyFastSerializer mfs = new MyFastSerializer();
cfp.addFastSerializer(mfs);
What if the Fast Serializer can not serialize the object? The example of this situation can be illustrated by the code below:
public class MyClass1
{
public int SomeInteger;
public object UnknownObject;
}
If the fast serializer is generated for this class, UnknownObject has to be serialized at the runtime because its type is not known at the compilation time. If this happens, the generic serializer takes over the control and continues the serialization. In turn, if the CompactFormatterPlus detects the field (class) that can be serialized by the fast serializer, the control returns recursively back to the fast serializer. Actually the programmer does not have to know such intricacies of the serialization. The fast serializer (if any) only has to be added to CompactFormatterPlus. The runtime of the fast serializer consists of FSWriter and FSReader. It has some extra methods against the original Binary reader and Writer. It looks a bit ugly because instead of inheriting everything from Binary reader (Writer) it has its own implementation of all overloads. The reason for that is: CF compiler apparently has a bug. Overloaded Write (byte) evaluates to [presumably] Write (double). [8 bytes instead of 1]
Using the code
On PC side the classes that have to be serialized should be included in the solution as the source code or the library. In the case of library, it has to be referenced in the PC project. Your class must have the same namespace name and the class name as the namespace and the class name on PDA. All the above is true for PDA.
The solutions are separate. PC files should not be used or referenced on the PDA side and visa versa. Common are just the names.
Sometimes it is possible to use CF files (EXE and DLLs) on PC and PC files on PDA. But that is a bad practice. It may work or may fail with a weird and irrelevant message.
Typical scenario: during the debugging session if you have PC generated assembly in your mobile solution, this file will drag all referenced assemblies to your PDA from PC and you will run out of memory.
CompactFormatterPlus serializable types
All primitive types
Arrays of primitive types
DateTime
ArrayList
Hashtable
List<T>
Dictionary<T Key, T1 Value>
DataSet
DataTable
Complex objects composed of the above types
Credits
The user by the name Fabien Castell has improved the typed dataset serialization and the instantiation of the objects if they are defined in different assemblies. The code can be downloaded from the original website
Download CompactFormatterPlusSolution.zip - 1,685.7 KB
New version
If newer version is released, it can be downloaded here.