8.4.2.5. pymodaq_utils.serialize.utils module

pymodaq_utils.serialize.utils.bytes_to_int(bytes_string: bytes) int[source]

Convert a bytes of length 4 into an integer

pymodaq_utils.serialize.utils.bytes_to_nd_array(data: bytes, dtype: dtype, shape: Tuple[int]) ndarray[source]

Convert bytes to a ndarray given a certain numpy dtype and shape

Parameters:
Return type:

np.ndarray

pymodaq_utils.serialize.utils.bytes_to_scalar(data: bytes, dtype: dtype) complex[source]

Convert bytes to a scalar given a certain numpy dtype

Parameters:
  • data (bytes)

  • dtype (np.dtype)

Return type:

numbers.Number

pymodaq_utils.serialize.utils.bytes_to_string(message: bytes) str[source]
pymodaq_utils.serialize.utils.get_int_from_bytes(bytes_str: bytes) Tuple[int, bytes][source]

Convert the 4 first bytes into an integer :returns: * int (the decoded integer)

  • bytes (the remaining bytes string if any)

pymodaq_utils.serialize.utils.int_to_bytes(an_integer: int) bytes[source]

Convert an unsigned integer into a byte array of length 4 in big endian

Parameters:

an_integer (int)

Return type:

bytearray

pymodaq_utils.serialize.utils.split_nbytes(bytes_str: bytes, bytes_len: int) Tuple[bytes, bytes][source]
pymodaq_utils.serialize.utils.str_len_to_bytes(message: str | bytes) Tuple[bytes, bytes][source]

Convert a string and its length to two bytes :param message: the message to convert :type message: str

Returns:

  • bytes (message converted as a byte array)

  • bytes (length of the message byte array, itself as a byte array of length 4)

pymodaq_utils.serialize.utils.str_to_bytes(message: str) bytes[source]