Inspirel banner

Programming Distributed Systems with YAMI4

3.11 Serialization

The parameters object can be serialized into a sequence of bytes and reconstructed from such a sequence. Both processes are precisely defined for all programing languages, which ensures data portability.

Serialization and deserialization are crucial to enable the transmission of the parameters data to other programs and in this context both are handled automatically in YAMI4, so in the majority of use-cases there will be no need to do this by hand. Still, exposing appropriate API at the user level can be useful for data persistence, for use with other transports, for computing digital signatures and so on - this section describes the serialization interface and provides examples of its use.

The parameters object can be serialized into a single continuous data buffer, which might be appropriate for small data objects, or into a set of disconnected buffers of arbitrary size - in fact, a single interface covers both scenarios. The same is true for deserialization and in general, this process is sometimes described as ``scatter-gather''.

The deserialization process is accumulative - that is, it reads the entries from the buffers and adds them the content of the parameters object, which is not forcibly cleared before that. The rules are the same as with regular, user-driven entry setting, which means that new entries overwrite existing ones with the same name. If the same parameters object is deserialized several times from buffers that were filled with serialized data of two distinct objects, the resulting content will be in essence a union of contents of both originating objects.

The accumulative property can be useful for merging several objects. Of course, if deserialization is attempted on a freshly constructed (or cleared) parameters object, the resulting content will be the same as that of the originating object.

Another important feature of the serialization mechanism is that in all programming languages the resulting sequence of bytes is fully determined by the values and order of entry insertion and removal operations. More precisely, the same sequence of such operations followed by serialization will produce the same result in all programming languages - this guarantee can be ignored for general-purpose messaging, but can be very useful in those applications that rely on deterministic serialization, for example for data hashing or signatures.

Note:

Entry ordering and serialization sequence are guaranteed in Python only for the Parameters class and not for the built-in dictionary type.

3.11.1 Ada

3.11.2 C++

3.11.3 Java

3.11.4 .NET

3.11.5 Python