Public Member Functions | |
| None | __init__ (self, SerializationType serialization_type=SerializationType.JSON) |
| Initializes the serializer with the specified serialization type. | |
| None | write (self, IArchive archive, TextIO stream) |
| Serializes an archive and writes it to a stream. | |
Data Fields | |
| dict | _type = self._to_dict(archive) |
Protected Member Functions | |
| dict | _to_dict (self, IArchive archive) |
Recursively converts an IArchive into a plain Python dict. | |
Protected Attributes | |
| _type = serialization_type | |
Serializer for writing IArchive objects to an output stream.
This class converts an IArchive object into a specific serialization format and writes the result to a stream.
Example
from ids_peak_icv.serialization import Archive
from ids_peak_icv.serialization import Serializer, SerializationType
archive = Archive()
archive.set("id", 42)
archive.set("name", "example")
serializer = Serializer(SerializationType.JSON)
with open("archive.json", "w") as f:
serializer.write(archive, f)
| None __init__ | ( | self, | |
| SerializationType | serialization_type = SerializationType.JSON ) |
Initializes the serializer with the specified serialization type.
The chosen format determines how the archive is written when write() is called. If no type is provided, JSON is used by default.
| serialization_type | The serialization format to use (defaults to :class:SerializationType.JSON). |
|
protected |
Recursively converts an IArchive into a plain Python dict.
| archive | The archive to convert. |
| None write | ( | self, | |
| IArchive | archive, | ||
| TextIO | stream ) |
Serializes an archive and writes it to a stream.
Converts the given IArchive object into the configured format and writes the serialized data to the provided stream.
| archive | The archive to serialize. |
| stream | The text stream that receives the serialized data (e.g., file or StringIO). |
| NotSupportedException | The serialization type is not supported. |
|
protected |
| dict _type = self._to_dict(archive) |