Advanced Tools Module User’s Guide : PART II Advanced Tools Module Packages : Chapter 5 The Serialization Package : Supported Streaming Formats
Supported Streaming Formats
The form of a serialized object is controlled by the object stream. The Serialization package provides a compact format, either annotated or non-annotated, that provides a choice of representations for primitive data elements
An object stream recursively deconstructs an object graph into pieces of some primitive (built-in) C++ data type. The representation of the data depends on the object stream implementation. If you are using object serialization only to serialize objects and then recreate them with Serialization object streams, the intermediate format is completely transparent to your application. Your choice of formats depends only on considerations of size, speed, and portability. On the other hand, if you plan to do any explicit processing of the object stream contents, the format is an important consideration.
The Compact Object Stream Format
Compact object streams give you flexibility. When this kind of object stream is created, it is chained to a concrete data stream that, in turn, implements the input and output of primitive types. This means that the same object stream can be used to read or write data in many formats, such as ASCII and native binary, on many types of media, such as files, strings, and XDR. This format is not self-describing; it passes information about the object’s state only. Compact object streams can interoperate with virtual streams and collectable objects.
Object Streams With Data Streams
Compact object streams work with any stream of type RWDataOutputStream or RWDataInputStream. You can choose a data stream from the Streams package, such as the RWDataToByteOutputStreamImp and RWDataFromByteInputStreamImp classes. For the full selection of streams, see “The Data Streams.”
You can also use the data stream in the Serialization package, which is an adapter to the Essential Tools Module virtual streams.
Object Streams With Virtual Streams
Object streams work with virtual streams through adapters. If a serializable object needs to be saved or restored from a virtual stream, then an object stream can be constructed from the virtual stream using the RWDataFromVirtualInputStreamImp and RWDataToVirtualOutputStreamImp adapter classes. (See “Writing to and Reading from Compact Object Streams With Virtual Streams.”)
The adapter enables you to format the primitive types in any way virtual streams can:
portable ascii, RWpistream/RWpostream. This format is human-readable (to a point), but it is bigger and slower than the other options.
portable binary, RWeistream/RWeostream. This format is smaller and faster than ascii, but it is not human-readable.
native binary, RWbistream/RWbostream.This format is slightly smaller and faster than portable binary, but it is non-portable and not human-readable.
Object Streams With Collectable Objects
Collectable objects can also be saved and restored to object streams using the adapter classes RWvistreamFromDataInputStream and RWvostreamToDataOutputStream in the Streams package. Operators are included to handle this process automatically. See “The RWvistreamFromDataInputStream Class” and “The RWvostreamToDataOutputStream Class” for instructions.
NOTE >> The Persistence facility in the Essential Tools Module and the Serialization package operate together and can be freely mixed in applications.