ACF $AcfVersion:0$
iser - Serialization Framework

Introduction

The iser library provides a comprehensive serialization framework for persisting and loading objects. It supports multiple archive formats including binary, XML, and compact XML, with automatic version handling and type identification.

Key Features

  • Archive-Based Serialization: Read and write archives with consistent interface
  • Multiple Formats: Binary, XML, and compact XML archive support
  • Version Management: Automatic version tracking and compatibility checking
  • Type Safety: Object type identification and validation
  • Memory and File: Support for both memory-based and file-based archives
  • Compression: Optional bit-level compression for compact storage

Architecture

The iser library is organized into several key components:

Archive Types

Core Interfaces

  • iser::ISerializable: Interface for serializable objects
  • iser::IReadArchive: Interface for reading archives
  • iser::IWriteArchive: Interface for writing archives
  • iser::IObject: Extended serializable interface with type information
  • iser::IVersionInfo: Version information for compatibility

Utilities

Usage Examples

Writing to Archive

class MyData : public iser::ISerializable
{
public:
virtual void Serialize(iser::IArchive& archive) override
{
archive.Process(m_value, "value");
archive.Process(m_name, "name");
}
private:
int m_value = 42;
QString m_name = "Example";
};
// Write to memory
MyData data;
data.Serialize(writeArchive);
// Get serialized data
QByteArray serialized = writeArchive.GetData();
Implementation of archive using memory buffer to store the persistent objects.
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
virtual bool Process(bool &value)=0
Processes (reads or writes) a boolean value.
Common class for all classes which objects can be archived or restored from archive.
virtual bool Serialize(IArchive &archive)=0
Load or store state of this object as a archive stream.

Reading from Archive

// Read from memory
iser::CMemoryReadArchive readArchive(serialized);
MyData loadedData;
loadedData.Serialize(readArchive);
// Data is now restored
Implementation of archive using memory buffer to read the persistent objects.

File-Based Serialization

#include <iser/CFileWriteArchive.h>
#include <iser/CFileReadArchive.h>
// Write to file
iser::CFileWriteArchive fileWrite("data.bin");
data.Serialize(fileWrite);
// Read from file
iser::CFileReadArchive fileRead("data.bin");
MyData loadedFromFile;
loadedFromFile.Serialize(fileRead);

Version Management

#include <iser/CVersionInfo.h>
// Create version info
iser::CVersionInfo versionInfo(1, 2, 0);
// Create archive with version
iser::CMemoryWriteArchive archive(&versionInfo);
// When reading, version is automatically checked
iser::CMemoryReadArchive readArchive(archive.GetData());
const iser::IVersionInfo* loadedVersion = readArchive.GetVersionInfo();
Provides access to version information.

Tagged Sections

// Write with tags
{
iser::CArchiveTag tag(archive, "Header");
archive.Process(headerData, "data");
}
{
iser::CArchiveTag tag(archive, "Body");
archive.Process(bodyData, "data");
}
Process tag used to group data in archive stream.
Definition CArchiveTag.h:22
virtual bool Process(bool &value) override
Processes (reads or writes) a boolean value.

Thread Safety

Archive objects are not thread-safe. Each thread should use its own archive instance.

Dependencies

The iser library depends on:

  • istd: Standard utilities and interfaces
  • Qt Core: QString, QByteArray, QIODevice, and other core classes

Best Practices

  1. Implement ISerializable: All persistent objects should implement ISerializable
  2. Use Named Fields: Always provide field names for better debugging and XML output
  3. Version Control: Include version information for data compatibility
  4. Handle Errors: Check archive state after serialization operations
  5. Symmetric Operations: Ensure Serialize() works for both reading and writing
  6. Use Tags: Organize complex data structures with CArchiveTag
  7. Test Compatibility: Test serialization with different versions

See Also