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:

  1. 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.

  2. The __new__ method only takes one argument which is the class type.

  3. 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) 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

Returns:

The decomposed serializable objects

recompose(data: dict) T[source]

Reconstruct the object from decomposed components.

Parameters:

data – The decomposed components

Returns:

The reconstructed object

supported_type() Type[T][source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type

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) 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

Returns:

The decomposed serializable objects

abstract recompose(data: Any) T[source]

Reconstruct the object from decomposed components.

Parameters:

data – The decomposed components

Returns:

The reconstructed object

abstract supported_type() Type[T][source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type

class DictDecomposer(dict_type: Type[dict])[source]

Bases: Decomposer

Generic decomposer for subclasses of dict like Shareable

decompose(target: dict) 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

Returns:

The decomposed serializable objects

recompose(data: dict) dict[source]

Reconstruct the object from decomposed components.

Parameters:

data – The decomposed components

Returns:

The reconstructed object

supported_type()[source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type

class EnumTypeDecomposer(data_type: Type[Enum])[source]

Bases: Decomposer

Generic decomposers for enum types.

decompose(target: Enum) 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

Returns:

The decomposed serializable objects

recompose(data: Any) Enum[source]

Reconstruct the object from decomposed components.

Parameters:

data – The decomposed components

Returns:

The reconstructed object

supported_type() Type[Enum][source]

Returns the type/class supported by this decomposer.

Returns:

The class (not instance) of supported type