nvflare.fuel.utils.fobs.lobs module

dump_to_bytes(obj: Any, buffer_list=False, max_value_size=None)[source]

Serialize an object to bytes

Parameters:
  • obj – object to be serialized

  • max_value_size – the max size allowed for bytes/str value in the object. If a value exceeds this, it will be

  • specified (converted to datum. If not) –

  • 10MB. (default is) –

  • buffer_list – If true, returns buffer list to save memory

Returns: a bytes object

dump_to_file(obj: Any, file_path: str, max_value_size=None)[source]

Serialize the object and save result to the specified file.

Parameters:
  • obj – object to be serialized

  • file_path – path of the file to store serialized data

  • max_value_size – the max size allowed for bytes/str value in the object. If a value exceeds this, it will be

  • specified (converted to datum. If not) –

  • 10MB. (default is) –

Returns: None

dump_to_stream(obj: Any, stream: BinaryIO, max_value_size=None)[source]

Serialize the specified object to a stream of bytes. If the object contains any datums, they will be included into the result.

The result may contain multiple sections: - the 1st section is the main body (serialized with fobs/msgpack) of the object - if the object contains large binary data, they will be converted to datums, and each datum has one section

During serialization, the object may be altered (replace large value with datums). After serialization, the object is restored to its original state.

Parameters:
  • obj – the object to be serialized.

  • stream – the stream that serialized data will be written to.

  • max_value_size – max size of bytes/str value allowed. If a value exceeds this, it will be converted to datum.

  • specified (If not) –

  • 10MB. (default is) –

Returns: None

load_from_bytes(data: bytes | list) Any[source]

Deserialize the bytes into an object

Parameters:

data – the bytes to be deserialized

Returns: an object

load_from_file(file_path: str) Any[source]

Deserialized data in the specified file into an object

Parameters:

file_path – the file that contains data to be deserialized.

Returns: an object

load_from_stream(stream: BinaryIO)[source]

Load/deserialize data from the specified stream into an object.

The data in the stream must be a well-formed serialized data. It has one or more sections: - The 1st section contains the main body of the object (serialized with fobs/msgpack) - Optionally, more datum sections follow, each representing a datum that is referenced in the main body.

Parameters:

stream – the stream that contains data to be deserialized.

Returns: an object