Serialization Articles about
Serialization
 

Information About

Serialization




In an older Computer Science context, serialization means to force one-at-a-time access for the purposes of Concurrency Control . For example, a single-threaded ActiveX server can process only one request at a time; thus requests are queued and executed in the order made.

In a more modern Computer Science context serialization is the process of saving an Object onto a storage medium (such as a file, or a memory buffer) or to transmit it across a network connection link such as a Socket either as a series of bytes or in some human-readable format such as XML . The series of bytes or the format can be used to re-create an object that is identical in its internal state to the original object (actually a clone). This type of serialization is used mostly to transport an object across a network, to persist objects to a file or database, or to distribute identical objects to several applications or locations.

  • This process of serializing an object is also known as deflating an object or '''marshalling''' an object.

  • The opposite operation, extracting a data structure from a series of bytes, is deserialization (which is also referred to as '''unmarshalling''' or '''inflating''').



USES

Serialization has a number of advantages. Serialization provides:

For some of these features to be useful, architecture independence must be maintained. For example, for maximal use of distribution, a computer running on a different hardware architecture should be able to reliably reconstruct a serialized data stream, regardless of Endianness . This means that the simpler and faster procedure of directly copying the memory layout of the data structure cannot work reliably for all architectures. Serializing the data structure in an architecture independent format means that we do not suffer from the problems of Byte Ordering , memory layout, or simply different ways of representing data structures in different Programming Language s.

In some forms, however, serialization has the disadvantage that since the encoding of the data is serial, merely extracting one part of the data structure that is serialized means that the entire object must be reconstructed or read before this can be done. The serialization capabilities in the Cocoa framework, NSKeyedArchiver, alleviate the problem somewhat by allowing an object to be archived with each instance variable of the object accessible by using a key.

Even on a single machine, primitive Pointer objects are too fragile to save, because the objects to which they point may be reloaded to a different location in memory. To deal with this, the serialization process includes a step called '' Unswizzling '' or ''pointer unswizzling'' and the deserialization process includes a step called '' Pointer Swizzling ''.


CONSEQUENCES

Serialization, however, breaks the Opacity of an Abstract Data Type by potentially exposing private implementation details. To discourage competitors from making compatible products, publishers of Proprietary Software often keep the details of their programs' serialization formats a Trade Secret . Some deliberately Obfuscate or even Encrypt the serialized data.

Yet, interoperability requires that applications be able to understand the serialization of each other. Therefore Remote Method Call architectures such as CORBA define their serialization formats in detail and often provide methods of checking the consistency of any serialized stream when converting it back into an object.


HUMAN-READABLE SERIALIZATION

In the late 1990s , a push to redefine, or provide an alternative to the standard serialization protocol that uses XML and produces a human readable encoding started. Such an encoding could be useful for persistent objects that may be read and understood by humans, or communicated to other systems regardless of programming language, but this has the disadvantage of losing the more compact, byte stream based encoding, which is generally more practical.


PROGRAMMING LANGUAGE SUPPORT

Several Object-oriented Programming languages directly support ''object serialization'' (or ''object archival''), either by Syntactic Sugar elements or providing a standard Interface for doing so.

Some of these programming languages are Smalltalk , Python , Objective-C , Java , and the .NET family of languages.

There are also libraries available that add serialization support to languages that lack native support for it.


Objective-C

In the Objective-C programming language, serialization (most commonly known as ''archival'') is achieved by overriding the write: and read: methods in the Object root class. (NB This is in the GNU runtime variant of Objective-C. In the NeXT-style runtime, the implementation is very similar.)


Example

The following example demonstrates two independent programs, a "sender", who takes the current time (as per time in the C Standard Library ), archives it and prints the archived form to the standard output, and a "receiver" which decodes the archived form, reconstructs the time and prints it out.

When compiled, we get a sender program and a receiver program. If we just execute the sender program, we will get out a serialization that looks like:
GNU TypedStream 1D@îC¡