Skip to content

Fix decoding of single-element payload members - #51

Open
glopesdev wants to merge 1 commit into
mainfrom
fix-member-length
Open

Fix decoding of single-element payload members#51
glopesdev wants to merge 1 commit into
mainfrom
fix-member-length

Conversation

@glopesdev

Copy link
Copy Markdown
Contributor

This affects modules built from a device.yml at runtime, through harp.device.schema. Device packages generated ahead of time by harp-tech/generators take a different path and are unaffected.

A payload member that declares a length now emits an array whatever number the length holds, so a member declaring length: 1 emits a one-element array. A member declaring no length still emits a scalar.

ConverterContext.length keeps the declared value as None when the schema declares none, rather than collapsing an absent length into 1 and then treating only > 1 as an array. That collapse made an absent length and a declared 1 indistinguishable, which is the same defect #44 fixed for registers; it corrected _build_register and left the member path as it was.

span gains an explicit floor of one element, which is now the only place that default lives.

How it surfaced

harp-tech/generators fixed the matching rule in its own target and added three registers to the shared test schema to cover it: an array register, an array register of one element, and a payload whose members declare no length, length: 1 and length: 2. Resyncing that schema and the generated module here is what exposed the divergence, since MixedMemberLength fails against the old emitter and passes against this one.

No published device schema declares a length on a payload member, so nothing in the ecosystem decodes incorrectly today.

Notes for review

tests/assets/core.yml was already identical and is untouched.

tests/device/converters.py takes only the Converter[np.int32] retype, matching the type the schema promises for an interfaceType of int. The rest of that file stays as it is, since it deliberately omits the upstream module docstring and follows the formatting here.

A payload member declaring a length now emits an array whatever number
the length holds, so a member declaring length 1 emits a one-element
array rather than a scalar. The converter context keeps the declared
length as None when the schema declares none, instead of collapsing an
absent length into 1, which made the two indistinguishable. Registers
already behaved this way; only members did not.

The test device schema and the generated module it is compared against
are resynced from harp-tech/generators.
@glopesdev
glopesdev requested a review from bruno-f-cruz August 27, 2026 11:44
@glopesdev glopesdev added the fix Pull request that fixes an issue label Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Pull request that fixes an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant