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
{
public:
{
}
private:
int m_value = 42;
QString m_name = "Example";
};
MyData data;
data.Serialize(writeArchive);
QByteArray serialized = writeArchive.GetData();
Implementation of archive using memory buffer to store the persistent objects.
Represents an input/output persistence archive for object serialization.
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
MyData loadedData;
loadedData.Serialize(readArchive);
Implementation of archive using memory buffer to read the persistent objects.
File-Based Serialization
#include <iser/CFileWriteArchive.h>
#include <iser/CFileReadArchive.h>
iser::CFileWriteArchive fileWrite("data.bin");
data.Serialize(fileWrite);
iser::CFileReadArchive fileRead("data.bin");
MyData loadedFromFile;
loadedFromFile.Serialize(fileRead);
Version Management
#include <iser/CVersionInfo.h>
iser::CVersionInfo versionInfo(1, 2, 0);
Provides access to version information.
Tagged Sections
{
archive.
Process(headerData,
"data");
}
{
}
Process tag used to group data in archive stream.
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
- Implement ISerializable: All persistent objects should implement ISerializable
- Use Named Fields: Always provide field names for better debugging and XML output
- Version Control: Include version information for data compatibility
- Handle Errors: Check archive state after serialization operations
- Symmetric Operations: Ensure Serialize() works for both reading and writing
- Use Tags: Organize complex data structures with CArchiveTag
- Test Compatibility: Test serialization with different versions
See Also