Skip to content

Fix for decoding TBOR nested structs#416

Open
rajesh-gali wants to merge 2 commits into
mainfrom
user/rajeshgali/tbor-nested-struct-decode
Open

Fix for decoding TBOR nested structs#416
rajesh-gali wants to merge 2 commits into
mainfrom
user/rajeshgali/tbor-nested-struct-decode

Conversation

@rajesh-gali
Copy link
Copy Markdown
Contributor

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:

  • Refactored TOC index helpers: Extracted and made public (pub(crate)) the build_toc_count_expr, offset_by_preceding_groups, and effective_toc_idx helpers in codegen_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))
  • Updated all uses of TOC indices in codegen_view.rs to 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:

  • Group field accessors: Added logic to generate sub-view accessors for #[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))
  • Group-aware validation: Modified generated validation code so that include-group fields delegate TOC entry validation to the group's own validate method, 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:

  • Display implementation: Updated the generated Display impl 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))
  • Length checks: Ensured length checks are not generated for include-group fields, as their validation is handled recursively. ([[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))

Copilot AI review requested due to automatic review settings June 1, 2026 04:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Display output.

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.

Comment thread fw/core/ddi/tbor/derive/src/codegen_view.rs
Comment thread fw/core/ddi/tbor/derive/src/codegen_view.rs Outdated
Comment thread fw/core/ddi/tbor/derive/src/codegen_view.rs
Comment thread fw/core/ddi/tbor/derive/src/codegen_view.rs
@rajesh-gali rajesh-gali marked this pull request as ready for review June 1, 2026 04:56
Copilot AI review requested due to automatic review settings June 1, 2026 04:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

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,
@rajesh-gali rajesh-gali force-pushed the user/rajeshgali/tbor-nested-struct-decode branch from 7c379f8 to ae845a8 Compare June 5, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants