Skip to content

Commit

Permalink
Merge pull request #13 from nee-wom/bugfix_bool_argument
Browse files Browse the repository at this point in the history
Support Bool arguments without type length
  • Loading branch information
mikiepure authored Oct 9, 2022
2 parents 99edd38 + dc6aa97 commit 3c76e9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/pydlt/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,9 @@ def create_from_bytes(
type_info = struct.unpack(f"{endian}I", data[: cls._TYPE_INFO_LENGTH])[0]
type_info_base = type_info & MASK_BASE_TYPE
if type_info_base == TypeInfo.TYPE_BOOL:
type_info_length = type_info & MASK_TYPE_LENGTH
if type_info_length == TypeInfo.TYPE_LENGTH_8BIT:
return ArgumentBool.from_data_payload(
data[cls._TYPE_INFO_LENGTH :], msb_first
)
return ArgumentBool.from_data_payload(
data[cls._TYPE_INFO_LENGTH :], msb_first
)
elif type_info_base == TypeInfo.TYPE_SIGNED:
type_info_length = type_info & MASK_TYPE_LENGTH
if type_info_length == TypeInfo.TYPE_LENGTH_8BIT:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ def test_message_verbose_payload_bool():
assert cast(ArgumentBool, dlt_message2.verbose_payload.arguments[1]).data is True


def test_bool_payload_without_type_length():
b1 = ArgumentBool(True)
dlt_bytes = bytearray(b1.to_bytes(False))
# clear the TypeInfo.TYPE_LENGTH_8BIT flag
dlt_bytes[0] = 0x10
assert Argument.create_from_bytes(dlt_bytes, False).data is True


def test_message_verbose_payload_uint():
path = TEST_RESULTS_DIR_PATH / Path(f"{sys._getframe().f_code.co_name}.dlt")

Expand Down

0 comments on commit 3c76e9f

Please sign in to comment.