IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
Serializer Class Reference

Public Member Functions

None __init__ (self, SerializationType serialization_type=SerializationType.JSON)
 Initializes a new serializer with the given serialization type.
 
None write (self, IArchive archive, TextIO stream)
 Serializes an IArchive object and writes it to the given 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
 

Detailed Description

A serializer that converts IArchive objects into a textual representation.

Currently, only JSON is supported.

Example::

from ids_peak_icv.serialization.archive import Archive
archive = Archive()
archive.set("name", "example")
serializer = Serializer()
with open("input.json", "w") as f:
    serializer.write(archive, f)
Since
ids_peak_icv 1.0

Definition at line 12 of file serializer.py.

Constructor & Destructor Documentation

◆ __init__()

None __init__ ( self,
SerializationType serialization_type = SerializationType.JSON )

Initializes a new serializer with the given serialization type.

Parameters
serialization_typeThe output serialization format. Defaults to :class:SerializationType.JSON.
Since
ids_peak_icv 1.0

Definition at line 33 of file serializer.py.

Member Function Documentation

◆ _to_dict()

dict _to_dict ( self,
IArchive archive )
protected

Recursively converts an IArchive into a plain Python dict.

Parameters
archiveThe archive to convert. :returns: A dictionary representation of the archive, suitable for serialization.
Since
ids_peak_icv 1.0

Definition at line 72 of file serializer.py.

◆ write()

None write ( self,
IArchive archive,
TextIO stream )

Serializes an IArchive object and writes it to the given stream.

Parameters
archiveThe archive to serialize.
streamA writable text stream (e.g., file or StringIO).
Exceptions
NotSupportedExceptionIf the configured serialization type is not supported.

Example::

archive = Archive()
archive.set("id", 42)
serializer = Serializer(SerializationType.JSON)
with open("output.json", "w") as f:

serializer.write(archive, f)

Since
ids_peak_icv 1.0

Definition at line 47 of file serializer.py.

Field Documentation

◆ _type [1/2]

_type = serialization_type
protected

Definition at line 43 of file serializer.py.

◆ _type [2/2]

dict _type = self._to_dict(archive)

Definition at line 66 of file serializer.py.