Serializer Module¶
This module handles the serialization and deserialization of image processing operations (OperationDescriptor) to and from persistent storage, currently using XMP metadata.
Architecture¶
The serializer module follows a layered, dependency-injection-based design to ensure flexibility and testability.
Core Interfaces¶
IXmpProvider: Abstracts the low-level XMP packet I/O operations (read/write). Allows switching underlying XMP libraries (e.g., Exiv2, Adobe XMP Toolkit).IXmpPathStrategy: Defines how to determine the file path for the XMP metadata associated with a given source image path. Supports different storage strategies (sidecar, AppData, configurable).IFileSerializerWriter: Interface for writing a list ofOperationDescriptors to a file (e.g., XMP packet).IFileSerializerReader: Interface for reading a list ofOperationDescriptors from a file (e.g., XMP packet).
Core Implementations¶
Exiv2Provider: Concrete implementation ofIXmpProviderusing the Exiv2 library.SidecarXmpPathStrategy: Stores XMP files alongside the image (e.g.,image.jpg->image.jpg.xmp).AppDataXmpPathStrategy: Stores XMP files in a centralized application data directory (e.g.,~/.local/share/CaptureMoment/xmp_cache/).ConfigurableXmpPathStrategy: Stores XMP files in a user-defined directory.FileSerializerWriter: Concrete implementation ofIFileSerializerWriter. UsesIXmpProviderandIXmpPathStrategyto write operations to an XMP file.FileSerializerReader: Concrete implementation ofIFileSerializerReader. UsesIXmpProviderandIXmpPathStrategyto read operations from an XMP file.
High-Level Manager¶
FileSerializerManager: Orchestrates theFileSerializerWriterandFileSerializerReader. Provides a unified interface (saveToFile,loadFromFile) for thePhotoEngineto interact with.
Serialization Utilities¶
OperationSerialization: A namespace containing utility functions (serializeParameter,deserializeParameter) for converting thestd::anyvalues withinOperationDescriptor::paramsto/from string representations suitable for XMP storage, preserving type information.
Initialization¶
Exiv2Initializer: A utility class to ensure the Exiv2 library is initialized before any XMP operations are performed.
Workflow¶
-
Saving Operations:
PhotoEnginecallsFileSerializerManager::saveToFile(image_path, operations).FileSerializerManagerdelegates toFileSerializerWriter::saveToFile.FileSerializerWriterusesIXmpPathStrategy::getXmpPathForImageto determine the XMP file location.FileSerializerWriterconvertsOperationDescriptors to an XMP packet string (usingOperationSerialization).FileSerializerWriterusesIXmpProvider::writeXmpto write the packet to the determined file.
-
Loading Operations:
PhotoEnginecallsFileSerializerManager::loadFromFile(image_path).FileSerializerManagerdelegates toFileSerializerReader::loadFromFile.FileSerializerReaderusesIXmpPathStrategy::getXmpPathForImageto determine the XMP file location.FileSerializerReaderusesIXmpProvider::readXmpto read the XMP packet string.FileSerializerReaderparses the XMP packet back intoOperationDescriptors (usingOperationSerialization).- The list of
OperationDescriptors is returned toPhotoEngine.
Integration¶
The FileSerializerManager is created with the necessary dependencies (FileSerializerWriter, FileSerializerReader, which in turn depend on IXmpProvider and IXmpPathStrategy) and injected into the PhotoEngine constructor. PhotoEngine then uses its FileSerializerManager instance to save and load operations.
Dependencies¶
- Exiv2: For XMP packet parsing and writing.
- spdlog: For logging.
- magic_enum: For converting
OperationTypeenum values to/from strings within the XMP packet.