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, Socket

Methods

axis_deserialization()

Convert bytes into an Axis object

boolean_deserialization()

Convert bytes into a boolean object

dte_deserialization()

Convert bytes into a DataToExport object

dwa_deserialization()

Convert bytes into a DataWithAxes object

list_deserialization()

Convert bytes into a list of homogeneous objects

ndarray_deserialization()

Convert bytes into a numpy ndarray object

scalar_deserialization()

Convert bytes into a python number object

string_deserialization()

Convert bytes into a str object

type_and_object_deserialization()

Deserialize specific objects from their binary representation (inverse of Serializer.type_and_object_serialization).

bytes_deserialization

from_b64_string

get_message_length

parameter_deserialization

classmethod from_b64_string(b64_string)[source]
Return type:

DeSerializer

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:

Axis

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:

bool

bytes_deserialization()[source]
Return type:

bytes

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:

DataToExport

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:

DataWithAxes

get_message_length()[source]
Return type:

int

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:

list

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

parameter_deserialization()[source]
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:

complex

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:

str

type_and_object_deserialization()[source]

Deserialize specific objects from their binary representation (inverse of Serializer.type_and_object_serialization).

Return type:

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

class pymodaq_utils.serialize.serializer_legacy.Serializer(obj=None)[source]

Bases: object

Used 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

object_type_serialization(obj)

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

type_and_object_serialization([obj])

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

Parameters:

axis (Axis)

Returns:

bytes

Return type:

bytes

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:

bytes

dte_serialization(dte)[source]

Convert a DataToExport into a bytes string

Parameters:

dte (DataToExport)

Returns:

bytes

Return type:

bytes

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:

bytes

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:

bytes

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:

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

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:

bytes

scalar_serialization(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

string_serialization(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

to_b64_string()[source]
Return type:

str

to_bytes()[source]

Generic method to obtain the bytes string from various objects

Compatible objects are:

type_and_object_serialization(obj=None)[source]

Serialize an object with its type, such that it can be retrieved by DeSerializer.type_and_object_deserialization.

Return type:

bytes