8.4.2.4. pymodaq_utils.serialize.serializer_legacy module
- class pymodaq_utils.serialize.serializer_legacy.DeSerializer(bytes_string=None)[source]
Bases:
object- Used to DeSerialize bytes to python objects, numpy arrays and PyMoDAQ Axis,
DataWithAxes and DataToExport
objects
- Parameters:
bytes_string (
Union[bytes,Socket]) – the bytes string to deserialize into an object: int, float, string, arrays, list, Axis, DataWithAxes… Could also be a Socket object reading bytes from the network having a get_first_nbytes method
See also
SocketString,SocketMethods
Convert bytes into an Axis object
Convert bytes into a boolean object
Convert bytes into a DataToExport object
Convert bytes into a DataWithAxes object
Convert bytes into a list of homogeneous objects
Convert bytes into a numpy ndarray object
Convert bytes into a python number object
Convert bytes into a str object
Deserialize specific objects from their binary representation (inverse of Serializer.type_and_object_serialization).
bytes_deserialization
from_b64_string
get_message_length
parameter_deserialization
- axis_deserialization()[source]
Convert bytes into an Axis object
Convert the first bytes into an Axis reading first information about the Axis
- Returns:
Axis
- Return type:
- boolean_deserialization()[source]
Convert bytes into a boolean object
Get first the data type from a string deserialization, then the data length and finally convert this length of bytes into a number (float, int) and cast it to a bool
- Returns:
bool
- Return type:
- dte_deserialization()[source]
Convert bytes into a DataToExport object
Convert the first bytes into a DataToExport reading first information about the underlying data
- Returns:
DataToExport
- Return type:
- dwa_deserialization()[source]
Convert bytes into a DataWithAxes object
Convert the first bytes into a DataWithAxes reading first information about the underlying data
- Returns:
DataWithAxes
- Return type:
- list_deserialization()[source]
Convert bytes into a list of homogeneous objects
Convert the first bytes into a list reading first information about the list elt types, length …
- Returns:
list
- Return type:
- ndarray_deserialization()[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
- Return type:
ndarray
- scalar_deserialization()[source]
Convert bytes into a python number object
Get first the data type from a string deserialization, then the data length and finally convert this length of bytes into a number (float, int)
- Returns:
numbers.Number
- Return type:
- string_deserialization()[source]
Convert bytes into a str object
Convert first the fourth first bytes into an int encoding the length of the string to decode
- Returns:
str
- Return type:
- class pymodaq_utils.serialize.serializer_legacy.Serializer(obj=None)[source]
Bases:
objectUsed to Serialize to bytes python objects, numpy arrays and PyMoDAQ DataWithAxes and DataToExport objects
Deprecated in PyMoDAQ >= 5 use the SerializerFactory object
Methods
axis_serialization(axis)Convert an Axis object into a bytes message together with the info to convert it back
bytes_serialization(bytes_string_in)Convert a bytes string into a bytes message together with the info to convert it back
dte_serialization(dte)Convert a DataToExport into a bytes string
dwa_serialization(dwa)Convert a DataWithAxes into a bytes string
list_serialization(list_object)Convert a list of objects into a bytes message together with the info to convert it back
ndarray_serialization(array)Convert a ndarray into a bytes message together with the info to convert it back
Convert an object type into a bytes message as a string together with the info to convert it back
scalar_serialization(scalar)Convert a scalar into a bytes message together with the info to convert it back
string_serialization(string)Convert a string into a bytes message together with the info to convert it back
to_bytes()Generic method to obtain the bytes string from various objects
Serialize an object with its type, such that it can be retrieved by DeSerializer.type_and_object_deserialization.
to_b64_string
- axis_serialization(axis)[source]
Convert an Axis object into a bytes message together with the info to convert it back
Notes
The bytes sequence is constructed as:
serialize the type: ‘Axis’
serialize the axis label
serialize the axis units
serialize the axis array
serialize the axis
serialize the axis spread_order
- bytes_serialization(bytes_string_in)[source]
Convert a bytes string into a bytes message together with the info to convert it back
- Return type:
- dte_serialization(dte)[source]
Convert a DataToExport into a bytes string
- Parameters:
dte (
DataToExport)- Returns:
bytes
- Return type:
Notes
The bytes sequence is constructed as:
serialize the string type: ‘DataToExport’
serialize the timestamp: float
serialize the name
serialize the list of DataWithAxes
- dwa_serialization(dwa)[source]
Convert a DataWithAxes into a bytes string
- Parameters:
dwa (
DataWithAxes)- Returns:
bytes
- Return type:
Notes
The bytes sequence is constructed as:
serialize the string type: ‘DataWithAxes’
serialize the timestamp: float
serialize the name
serialize the source enum as a string
serialize the dim enum as a string
serialize the distribution enum as a string
serialize the list of numpy arrays
serialize the list of labels
serialize the origin
serialize the nav_index tuple as a list of int
serialize the list of axis
serialize the errors attributes (None or list(np.ndarray))
serialize the list of names of extra attributes
serialize the extra attributes
- list_serialization(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 contains either scalars, strings or ndarrays or Axis objects or DataWithAxis objects module- Returns:
bytes
- Return type:
Notes
The bytes sequence is constructed as: * the length of the list
Then for each object:
get data type as a string
use the serialization method adapted to each object in the list
- ndarray_serialization(array)[source]
Convert a ndarray into a bytes message together with the info to convert it back
- Parameters:
array (
ndarray)- Returns:
bytes
- Return type:
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
- object_type_serialization(obj)[source]
Convert an object type into a bytes message as a string together with the info to convert it back
- Return type:
- scalar_serialization(scalar)[source]
Convert a scalar into a bytes message together with the info to convert it back
- string_serialization(string)[source]
Convert a string into a bytes message together with the info to convert it back