Fix for decoding TBOR nested structs#416
Open
rajesh-gali wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates TBOR derive code generation to make generated views and validation more aware of #[tbor(include)] field groups, especially when computing effective TOC indices for included/nested groups.
Changes:
- Shares TOC count/index helper logic from encoder codegen with view codegen.
- Updates generated view accessors, validation checks, padding checks, and length checks to use group-aware TOC offsets.
- Adds generated sub-view accessors for include fields and skips include fields in flat
Displayoutput.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
fw/core/ddi/tbor/derive/src/codegen_enc.rs |
Exposes reusable TOC count and effective-index helpers for use by other codegen modules. |
fw/core/ddi/tbor/derive/src/codegen_view.rs |
Applies group-aware TOC index computation to generated views, validation, padding, length checks, and display output. |
| if !(#min_l..=#max_l).contains(&len) { | ||
| return Err(azihsm_fw_ddi_tbor::DecodeError::InvalidFixedLength { | ||
| entry_index: toc_offset + #toc_idx, | ||
| entry_type: 7, |
| if !(#min_l..=#max_l).contains(&len) { | ||
| return Err(azihsm_fw_ddi_tbor::DecodeError::InvalidFixedLength { | ||
| entry_index: toc_offset + #toc_idx, | ||
| entry_type: 7, |
7c379f8 to
ae845a8
Compare
This file contains hidden or 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
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 pull request refactors and enhances the code generation logic for TBOR schema "View" types, with a focus on improving support for
#[tbor(include)]group fields. It introduces new helpers for computing TOC (Table of Contents) indices that correctly handle nested groups, ensures that generated accessors and validation logic are group-aware, and improves modularity by extracting and reusing logic across modules.Enhancements to TOC index computation and group support:
pub(crate)) thebuild_toc_count_expr,offset_by_preceding_groups, andeffective_toc_idxhelpers incodegen_enc.rs, allowing correct symbolic computation of TOC indices and counts with nested include-groups. ([[1]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-428ef521c31698b93136096b8e9c039647f22f2c4c96443beafd846acce0a50bL87-R87),[[2]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-428ef521c31698b93136096b8e9c039647f22f2c4c96443beafd846acce0a50bL233-R261))codegen_view.rsto use the new helpers, ensuring group-aware index calculation in accessors, validation, and padding checks. ([[1]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bR10-R12),[[2]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bL29-R33),[[3]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bL219-R241),[[4]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bL243-R265),[[5]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bL329-R372))Improvements to generated accessors and validation:
#[tbor(include)]fields, returning the appropriate group view type instead of a primitive accessor. ([[1]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bL102-R112),[[2]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bR200-R216))validatemethod, and padding checks are now group-aware. ([[1]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bR314-L298),[[2]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bL329-R372))Other improvements:
Displayimpl to skip include-group fields, as they are not rendered as scalars in the flat display output. ([fw/core/ddi/tbor/derive/src/codegen_view.rsR457-R461](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bR457-R461))[[1]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bR399-R401),[[2]](https://github.com/Azure/azihsm-sdk/pull/416/files#diff-9ca5969bff6431567b788b59d40480c1e291a6887b8a74ae1b8023fe3c9bdf1bL369-R410))