Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrapping (~) not supported in CDDL #437

Open
dgpetrie opened this issue Jul 17, 2024 · 1 comment
Open

Unwrapping (~) not supported in CDDL #437

dgpetrie opened this issue Jul 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@dgpetrie
Copy link

CDDL RFC 8610 section 3.7. Unwrapping defines the use of the tilde (~) character operator for unwrapping a map. When zcbor encounters a tilda in the CDDL it throws an exception.

import zcbor
cddl_str = """
second_type = {
~ first_type,
param3: uint,
}

first_type = {
param1: tstr,
param2: uint
}
"""
cddl_res = zcbor.zcbor.zcbor.DataTranslator.from_cddl(cddl_str, 100)

yields:

Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 903, in get_value
handler(self, match_str)
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 775, in
lambda m_self, map_str: m_self.type_and_value(
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 530, in type_and_value
self.set_value(value_generator)
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 533, in set_value
value = value_generator()
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 776, in
"MAP", lambda: m_self.parse(map_str))),
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 990, in parse
instr = value.get_value(instr)
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 914, in get_value
raise TypeError("Could not parse this: '%s'" % instr)
TypeError: Could not parse this: '~ first_type, param3: uint,'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 281, in from_cddl
parsed.get_value(cddl_string.replace("\n", " ").lstrip("&"))
File "/usr/local/lib/python3.8/dist-packages/zcbor/zcbor/zcbor.py", line 905, in get_value
raise Exception("Failed while parsing this: '%s'" % match_str) from e
Exception: Failed while parsing this: ' ~ first_type, param3: uint, '

@oyvindronningstad
Copy link
Collaborator

Thanks for reporting. Unwrapping is one of the features mentioned as unsupported in the release notes. I will note this down as a request so I'm more likely to implement it.

@oyvindronningstad oyvindronningstad added the enhancement New feature or request label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants