Serialization is the process of translating a data structure or object state into a format that can be stored or transmitted across a network. In C, there is no native support for serialization, so custom serialization functions must be written. The process of serialization involves writing all the data members of a data structure one by one in serial, often in an architecture-independent format to prevent problems with byte ordering, memory layout, or different ways of representing data structures in different programming languages. The serialized data can be in XML or binary format, and variable length arrays can be handled by writing a length followed by the data or by writing the data followed by a special terminator. The receive function for deserialization is nearly identical to the send function, reading all the items one by one.
Some techniques for serialization in C include:
- Writing custom serialization functions
- Using compiler-based solutions such as the ODB ORM system for C++ and the gSOAP toolkit for C and C++
- Using X-Macros to generate serialization functions from a common definition
It is important to note that classes containing sensitive information, such as passwords, should not be serializable or externalizable.