nvflare.fuel.utils.fobs.decomposer module¶
- class DataClassDecomposer(data_type: Type[T])[source]¶
Bases:
Decomposer
Generic decomposers for data classes, which must meet following requirements:
All class members must be serializable. The type of member must be one of the types supported by MessagePack or a decomposer is registered for the type.
The __new__ method only takes one argument which is the class type.
The __init__ method has no side effects. It can only change the states of the object. The side effects include creating files, initializing loggers, modifying global variables.
- decompose(target: T, manager: DatumManager | None = None) Any [source]¶
Decompose the target into types supported by msgpack or classes with decomposers registered.
Msgpack supports primitives, bytes, memoryview, lists, dicts.
- Parameters:
target – The instance to be serialized
manager – Datum manager to store externalized datum
- Returns:
The decomposed serializable objects
- recompose(data: dict, manager: DatumManager | None = None) T [source]¶
Reconstruct the object from decomposed components.
- Parameters:
data – The decomposed component
manager – Datum manager to internalize datum
- Returns:
The reconstructed object
- class Decomposer[source]¶
Bases:
ABC
Abstract base class for decomposers.
Every class to be serialized by FOBS must register a decomposer which is a concrete subclass of this class.
- abstract decompose(target: T, manager: DatumManager | None = None) Any [source]¶
Decompose the target into types supported by msgpack or classes with decomposers registered.
Msgpack supports primitives, bytes, memoryview, lists, dicts.
- Parameters:
target – The instance to be serialized
manager – Datum manager to store externalized datum
- Returns:
The decomposed serializable objects
- abstract recompose(data: Any, manager: DatumManager | None = None) T [source]¶
Reconstruct the object from decomposed components.
- Parameters:
data – The decomposed component
manager – Datum manager to internalize datum
- Returns:
The reconstructed object
- class DictDecomposer(dict_type: Type[dict])[source]¶
Bases:
Decomposer
Generic decomposer for subclasses of dict like Shareable
- decompose(target: dict, manager: DatumManager | None = None) Any [source]¶
Decompose the target into types supported by msgpack or classes with decomposers registered.
Msgpack supports primitives, bytes, memoryview, lists, dicts.
- Parameters:
target – The instance to be serialized
manager – Datum manager to store externalized datum
- Returns:
The decomposed serializable objects
- recompose(data: dict, manager: DatumManager | None = None) dict [source]¶
Reconstruct the object from decomposed components.
- Parameters:
data – The decomposed component
manager – Datum manager to internalize datum
- Returns:
The reconstructed object
- class EnumTypeDecomposer(data_type: Type[Enum])[source]¶
Bases:
Decomposer
Generic decomposers for enum types.
- decompose(target: Enum, manager: DatumManager | None = None) Any [source]¶
Decompose the target into types supported by msgpack or classes with decomposers registered.
Msgpack supports primitives, bytes, memoryview, lists, dicts.
- Parameters:
target – The instance to be serialized
manager – Datum manager to store externalized datum
- Returns:
The decomposed serializable objects
- recompose(data: Any, manager: DatumManager | None = None) Enum [source]¶
Reconstruct the object from decomposed components.
- Parameters:
data – The decomposed component
manager – Datum manager to internalize datum
- Returns:
The reconstructed object
- class Externalizer(manager: DatumManager)[source]¶
Bases:
object
This class is used to help creating ‘decompose’ method of decomposers of arbitrary classes.
- class Internalizer(manager: DatumManager)[source]¶
Bases:
object
This class is used to help creating ‘recompose’ method of decomposers of arbitrary classes.
- restore_position(manager: DatumManager, datum: Datum, position)[source]¶
This function is used for restoring object state at the specified position.
- Parameters:
manager – the datum manager
datum – the datum that contains the value of the original object at the position.
position – the position to be restored
Returns: None