8.4.2.3. pymodaq_utils.serialize.serializer module

Created the 20/10/2023

@author: Sebastien Weber

class pymodaq_utils.serialize.serializer.BytesSerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

serialize(some_bytes)

static deserialize(bytes_str)[source]
Return type:

Tuple[bytes, bytes]

static serialize(some_bytes)[source]
Return type:

bytes

class pymodaq_utils.serialize.serializer.DictSerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

Convert bytes into a dictionary of serializable objects

serialize(dict_object)

Convert a dictionnary of objects into a bytes message together with the info to convert it back

static deserialize(bytes_str)[source]

Convert bytes into a dictionary of serializable objects

Convert the first bytes into a dict reading first information about the key elts of the dictionnary then the underlying objects …

Return type:

Tuple[dict[str, Union[None, bytes, str, int, float, complex, list, tuple, dict, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], SerializableBase]], bytes]

Returns:

  • dict (the decoded dictionary)

  • bytes (the remaining bytes string if any)

static serialize(dict_object)[source]

Convert a dictionnary of objects into a bytes message together with the info to convert it back

Parameters:

dict_object (dict[Union[None, bytes, str, int, float, complex, list, tuple, dict, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], SerializableBase], Union[None, bytes, str, int, float, complex, list, tuple, dict, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], SerializableBase]]) – the dict could contain whatever objects are registered in the SerializableFactory

Returns:

bytes

Return type:

bytes

Notes

The bytes sequence is constructed as: * the list of keys of the dict

Then for each key: * use the serialization method adapted to the object inferred from the key

class pymodaq_utils.serialize.serializer.ListSerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

Convert bytes into a list of objects

serialize(list_object)

Convert a list of objects into a bytes message together with the info to convert it back

static deserialize(bytes_str)[source]

Convert bytes into a list of objects

Convert the first bytes into a list reading first information about the list elt types, length …

Return type:

Tuple[List[Union[None, bytes, str, int, float, complex, list, tuple, dict, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], SerializableBase]], bytes]

Returns:

  • list (the decoded list)

  • bytes (the remaining bytes string if any)

static serialize(list_object)[source]

Convert a list of objects into a bytes message together with the info to convert it back

Parameters:

list_object (List) – the list could contain whatever objects are registered in the SerializableFactory

Returns:

bytes

Return type:

bytes

Notes

The bytes sequence is constructed as: * the length of the list

Then for each object: * use the serialization method adapted to each object in the list

class pymodaq_utils.serialize.serializer.NdArraySerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

Convert bytes into a numpy ndarray object

serialize(array)

Convert a ndarray into a bytes message together with the info to convert it back

static deserialize(bytes_str)[source]

Convert bytes into a numpy ndarray object

Convert the first bytes into a ndarray reading first information about the array’s data

Return type:

Tuple[ndarray, bytes]

Returns:

  • ndarray (the decoded numpy array)

  • bytes (the remaining bytes string if any)

static serialize(array)[source]

Convert a ndarray into a bytes message together with the info to convert it back

Parameters:

array (ndarray)

Returns:

bytes

Return type:

bytes

Notes

The bytes sequence is constructed as:

  • get data type as a string

  • reshape array as 1D array and get the array dimensionality (len of array’s shape)

  • convert Data array as bytes

  • serialize data type

  • serialize data length

  • serialize data shape length

  • serialize all values of the shape as integers converted to bytes

  • serialize array as bytes

class pymodaq_utils.serialize.serializer.NoneSerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

serialize(obj)

static deserialize(bytes_str)[source]
Return type:

Tuple[None, bytes]

static serialize(obj)[source]
Return type:

bytes

class pymodaq_utils.serialize.serializer.ScalarSerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

Convert bytes into a python object of type (float, int, complex or boolean)

serialize(scalar)

Convert a scalar into a bytes message together with the info to convert it back

static deserialize(bytes_str)[source]

Convert bytes into a python object of type (float, int, complex or boolean)

Get first the data type from a string deserialization, then the data length and finally convert this length of bytes into an object of type (float, int, complex or boolean)

Return type:

Tuple[complex, bytes]

Returns:

  • numbers.Number (the decoded number)

  • bytes (the remaining bytes string if any)

static serialize(scalar)[source]

Convert a scalar into a bytes message together with the info to convert it back

Parameters:

scalar (complex)

Returns:

bytes

Return type:

bytes

class pymodaq_utils.serialize.serializer.SerializableTypes(*values)[source]

Bases: Enum

Type names of serializable types

ARRAY = 'array'
AXIS = 'axis'
BOOL = 'bool'
BYTES = 'bytes'
DATA_TO_EXPORT = 'dte'
DATA_WITH_AXES = 'dwa'
DICT = 'dict'
LIST = 'list'
NONE = 'NoneType'
PARAMETER = 'parameter'
SCALAR = 'scalar'
STRING = 'string'
TUPLE = 'tuple'
class pymodaq_utils.serialize.serializer.StringSerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

Convert bytes into a str object

serialize(string)

Convert a string into a bytes message together with the info to convert it back

static deserialize(bytes_str)[source]

Convert bytes into a str object

Convert first the fourth first bytes into an int encoding the length of the string to decode

Return type:

Tuple[str, bytes]

Returns:

  • str (the decoded string)

  • bytes (the remaining bytes string if any)

static serialize(string)[source]

Convert a string into a bytes message together with the info to convert it back

Parameters:

string (str)

Returns:

bytes

Return type:

bytes

class pymodaq_utils.serialize.serializer.TupleSerializeDeserialize[source]

Bases: SerializableBase

Methods

deserialize(bytes_str)

Convert bytes into a tuple of objects

serialize(tuple_object)

Convert a tuple of objects into a bytes message together with the info to convert it back

static deserialize(bytes_str)[source]

Convert bytes into a tuple of objects

Convert the first bytes into a tuple reading first information about the tuple elt types, length …

Return type:

Tuple[Tuple[Union[None, bytes, str, int, float, complex, list, tuple, dict, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], SerializableBase], ...], bytes]

Returns:

  • tuple (the decoded tuple)

  • bytes (the remaining bytes string if any)

static serialize(tuple_object)[source]

Convert a tuple of objects into a bytes message together with the info to convert it back

Parameters:

tuple_object (Tuple[Union[None, bytes, str, int, float, complex, list, tuple, dict, ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], SerializableBase], ...]) – the tuple could contain whatever objects are registered in the SerializableFactory

Returns:

bytes

Return type:

bytes

Notes

The bytes sequence is constructed as: * the length of the tuple

Then for each object: * use the serialization method adapted to each object in the tuple