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

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
 

Detailed Description

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)
Since
ids_peak_icv 1.0

Constructor & Destructor Documentation

◆ __init__()

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.

Parameters
serialization_typeThe serialization format to use (defaults to :class:SerializationType.JSON).
Since
ids_peak_icv 1.0

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

◆ write()

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.

Parameters
archiveThe archive to serialize.
streamThe text stream that receives the serialized data (e.g., file or StringIO).
Exceptions
NotSupportedExceptionThe serialization type is not supported.
Since
ids_peak_icv 1.0

Field Documentation

◆ _type [1/2]

_type = serialization_type
protected

◆ _type [2/2]

dict _type = self._to_dict(archive)