-
Notifications
You must be signed in to change notification settings - Fork 23
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
Packed CBOR decoding support for shared items #93
Draft
mguetschow
wants to merge
44
commits into
bergzand:master
Choose a base branch
from
mguetschow:packed-cbor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…tainer at cost of double follow
…packed logic behind _PACKED_FOLLOW
…t_uint* functions
…ug for indefinite length tables
mguetschow
changed the title
Packed CBOR support for item sharing
Packed CBOR decoding support for item sharing
Feb 29, 2024
mguetschow
changed the title
Packed CBOR decoding support for item sharing
Packed CBOR decoding support for shared items
Feb 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for packed CBOR shared items to NanoCBOR, handling them (mostly) transparently to the user.
The following is supported for now:
nanocbor_decoder_init_packed_table
All additional functionality specific to packed CBOR support is guarded behind the configuration define
NANOCBOR_DECODE_PACKED_ENABLED
and should thus lead to (almost) no overhead compared to currentmaster
when packed CBOR support is disabled (todo: check actual binary size difference).Even if packed CBOR support is enabled at compile-time, it needs to be explicitly requested by using
nanocbor_decoder_init_packed*
instead ofnanocbor_decoder_init
.Implementation Details
nanocbor_value_t
is extended to additionally hold information about the active set of packing tables. The maximal nesting supported is determined by the compile-time configurationNANOCBOR_DECODE_PACKED_NESTED_TABLES_MAX
(currently set to 3). For each table, its start and length (in bytes) are stored.nanocbor_
, exceptnanocbor_get_subcbor
, cf. below), NanoCBOR first tries to handle any potential packed CBOR item (simple value below 16, tag 6, or tag 113). If at least one (or several nested) such packed CBOR items are found, they are (recursively) handled. To avoid code-duplication, the macro family_PACKED_HANDLE_*
is used for this repeated logic. Recursion is bound byNANOCBOR_MAX_RECURSION
, which is decremented for every definition of ananocbor_value_t
.nanocbor_value_t
. If the maximum nesting level of table definitions is reached, the error valueNANOCBOR_ERR_PACKED_MEMORY
is returned to the user.NANOCBOR_ERR_PACKED_UNDEFINED_REFERENCE
is returned.NANOCBOR_ERR_PACKED_FORMAT
is returned.Testing
ninja -C build && build/tests/automated/test_automated
runs an extensive test suite for packed CBOR decoding iffNANOCBOR_DECODE_PACKED_ENABLED == 1
.Open Questions
nanocbor_get_subcbor()
behave? If called on a packed CBOR data item (table setup or reference), right now it would simply return the unhandled packed CBOR data item. For successful later processing, the context (aka the active set of packing tables) would need to be saved / restored somehow. A partly fix could be to handle the packed CBOR data item (handle the table or follow the reference). This would however still break if the resulting item itself still contains shared item references (can happen if it is an array, a map or a tag).Remarks
Note that this only concerns the decoder, encoding packed CBOR is expected to be done manually be the application (needs #88).
Builds on top of (and thus includes) #90, #91, #92.
I could try to rewrite the commit history if that would help for the review.
Edit 2024-04-17: The implementation has been simplified by recursing only over the
_packed_*
functions, instead of the API-facing functions.Edit 2024-08-23: The macro implementation was changed to fix a bug where the decoder context was forwarded even if the wrong getter function has been used.