7.4.2.3. pymodaq_utils.serialize.serializer module
Created the 20/10/2023
@author: Sebastien Weber
- class pymodaq_utils.serialize.serializer.BytesSerializeDeserialize[source]
Bases:
SerializableBaseMethods
deserialize(bytes_str)Implements deserialization into self type from bytes
serialize(some_bytes)Implements self serialization into bytes
- static deserialize(bytes_str: bytes) Tuple[bytes, bytes][source]
Implements deserialization into self type from bytes
- Parameters:
bytes_str (bytes) –
- Returns:
SerializableBase (object to reconstruct)
bytes (leftover bytes to deserialize)
Notes
The actual deserialization should be done using the SerializableFactory and its method :meth:SerializableFactory.get_apply_deserializer
- class pymodaq_utils.serialize.serializer.ListSerializeDeserialize[source]
Bases:
SerializableBaseMethods
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: bytes) Tuple[List[Any], bytes][source]
Convert bytes into a list of objects
Convert the first bytes into a list reading first information about the list elt types, length …
- Returns:
list (the decoded list)
bytes (the remaining bytes string if any)
- static serialize(list_object: List) bytes[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:
the total bytes message to serialize the list of objects
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:
SerializableBaseMethods
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: bytes) Tuple[ndarray, bytes][source]
Convert bytes into a numpy ndarray object
Convert the first bytes into a ndarray reading first information about the array’s data
- Returns:
ndarray (the decoded numpy array)
bytes (the remaining bytes string if any)
- static serialize(array: ndarray) bytes[source]
Convert a ndarray into a bytes message together with the info to convert it back
- Parameters:
array (np.ndarray) –
- Returns:
bytes
- Return type:
the total bytes message to serialize the scalar
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.ScalarSerializeDeserialize[source]
Bases:
SerializableBaseMethods
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: bytes) Tuple[complex, bytes][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)
- Returns:
numbers.Number (the decoded number)
bytes (the remaining bytes string if any)
- class pymodaq_utils.serialize.serializer.SerializableTypes(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumType names of serializable types
- ARRAY = 'array'
- AXIS = 'axis'
- BOOL = 'bool'
- BYTES = 'bytes'
- DATA_TO_EXPORT = 'dte'
- DATA_WITH_AXES = 'dwa'
- LIST = 'list'
- PARAMETER = 'parameter'
- SCALAR = 'scalar'
- STRING = 'string'
- class pymodaq_utils.serialize.serializer.StringSerializeDeserialize[source]
Bases:
SerializableBaseMethods
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