Skip to content

Commit

Permalink
Merge pull request #15 from PyMoDAQ/feature/serializable
Browse files Browse the repository at this point in the history
implement last version of pymodaq_data serializer on Parameter
  • Loading branch information
seb5g authored Dec 1, 2024
2 parents 6a82c49 + 7e913de commit eaaf586
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
"setuptools>=60",
"toml",
"pymodaq_utils",
"pymodaq_data>=5.0.3",
"pymodaq_data>=5.0.13",
]

[project.scripts]
Expand Down
10 changes: 6 additions & 4 deletions src/pymodaq_gui/parameter/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import TYPE_CHECKING, List, Tuple, Any
from typing import TYPE_CHECKING, List, Tuple, Any, Union
from dataclasses import Field, fields
import numpy as np
from collections import OrderedDict
Expand Down Expand Up @@ -53,16 +53,18 @@ def serialize(param: 'ParameterWithPath') -> bytes:
return bytes_string

@classmethod
def deserialize(cls, bytes_str: bytes) -> Tuple[Any, bytes]:
def deserialize(cls,
bytes_str: bytes) -> Union[ParameterWithPath,
Tuple[ParameterWithPath, bytes]]:
"""Convert bytes into a ParameterWithPath object
Returns
-------
ParameterWithPath: the decoded object
bytes: the remaining bytes string if any
"""
path, remaining_bytes = ser_factory.get_apply_deserializer(bytes_str)
param_as_xml, remaining_bytes = ser_factory.get_apply_deserializer(remaining_bytes)
path, remaining_bytes = ser_factory.get_apply_deserializer(bytes_str, False)
param_as_xml, remaining_bytes = ser_factory.get_apply_deserializer(remaining_bytes, False)
param_dict = ioxml.XML_string_to_parameter(param_as_xml)
param_obj = Parameter(**param_dict[0])
return ParameterWithPath(param_obj, path), remaining_bytes
Expand Down
2 changes: 1 addition & 1 deletion tests/parameter_test/param_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_ParameterWithPath_serialize():
assert isinstance(putils.ser_factory.get_apply_serializer(p1_with_path), bytes)

param_back: putils.ParameterWithPath = putils.ser_factory.get_apply_deserializer(
putils.ser_factory.get_apply_serializer(p1_with_path))[0]
putils.ser_factory.get_apply_serializer(p1_with_path))
assert param_back.path == p1_with_path.path
assert putils.compareParameters(param_back.parameter, p1_with_path.parameter)

0 comments on commit eaaf586

Please sign in to comment.