nvflare.fuel.utils.fobs.lobs module
- dump_to_bytes(obj: Any, buffer_list=False, max_value_size=None, fobs_ctx: dict | None = 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
fobs_ctx – context info for decomposers
Returns: a bytes object
- dump_to_file(obj: Any, file_path: str, max_value_size=None, fobs_ctx: dict | None = 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)
fobs_ctx – context info for decomposers
Returns: None
- dump_to_stream(obj: Any, stream: BinaryIO, max_value_size=None, fobs_ctx: dict | None = 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, large values are represented by datum references in the serialized main body. The input object is not modified.
- 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)
fobs_ctx – context info
Returns: None
- get_datum_dir()[source]
When a file datum is received, the data will be stored in a temporary file under a predefined Datum Directory. This function returns this predefined Datum Directory. The function also tries to create the directory if it does not exist.
The directory can be defined with a system environment variable: NVFLARE_DATUM_DIR.
Returns: name of the datum directory
Notes: temporary dir from tempfile must not be used! This is because the file must continue to exist after it is closed.
- load_from_bytes(data: bytes | list, fobs_ctx: dict | None = None) Any[source]
Deserialize the bytes into an object
- Parameters:
data – the bytes to be deserialized
fobs_ctx – context info for decomposers
Returns: an object
- load_from_file(file_path: str, fobs_ctx: dict | None = None) Any[source]
Deserialized data in the specified file into an object
- Parameters:
file_path – the file that contains data to be deserialized.
fobs_ctx – context info for decomposers
Returns: an object
- load_from_stream(stream: BinaryIO, fobs_ctx: dict | None = None)[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.
fobs_ctx – contextual info for decomposers
Returns: an object