Derive register length from its payload class - #43
Closed
bruno-f-cruz wants to merge 2 commits into
Closed
Conversation
Member
Author
|
Closed in favor of #44. Bottom line: after discussion, @glopesdev and I decided to drop |
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.
lengthandpayload_classboth describe the extent of a register payload but were declared independently, so a register with a multi-element payload reported no length and was then rejected by its own frames.lengthis now derived frompayload_class.The register that could not read itself
RegisterBase.parsesizes the payload from the dtype.HarpMessage.decodesizes it fromlength:Two routes to one quantity, so a register declaring no
lengthparses a frame fine and is rejected bydecode:Device.readandDevice.writeboth end inmsg.decode(register), so this broke every multi-element register: the struct-typed settings registers on devices such as Quac, which #36 reports, andDeviceName, which every Harp device carries.Giving the two a shared
payload_sizeon the register was rejected. The extent is a property of the dtype, not of the register declaration, so restating it there is the shape of the bug rather than its fix, a second copy drifting the moment a payload changes without it.parsekeeps reading the dtype andlengthis derived from it, sodecodecannot disagree. The checks stay distinct either way,parseasking whether a buffer holds at least one payload anddecodewhether a frame holds exactly one.What the extent is measured in
_derive_lengthdividespayload_dtype.itemsizeby the width of onepayload_typeelement. That width comes frompayload_type, not the payload's own_elem_dtype, sincepayload_typeis whatdecodemeasures the frame with and the two need not agree:A payload that is not a whole number of elements raises rather than truncating.
The declared length
A declared
lengthis checked against the payload but not trusted, and the emitter passesreg.lengththrough so a schema declaration is checked too (this means if a schema is wrong, an error will be raised).Tests
Fourteen, each regression confirmed to fail with the derivation disabled.
test_register.pycovers the derivation, the unit it measures in, one-element arrays and their subclasses, a declared 1 normalizing away, and the two rejections.test_emit.pycovers the same through a message, theDevice.readandDevice.writepath.Important note on length=1 => None
@glopesdev
The current schema upstream defines length as not required (however this is different from having a default). The corresponding model in this python client defines length with a default = 1..
This is unfortunate as it prevents us from distinguishing between someone who wrongly adds "1" explicitly (and gets replaced with "None" silently) and someone that genuanly does not define a value and rather has it inferred. I think this should probably be revisit if/when we merge the spec for the variable-length registers. Until then we have two choices:
Closes #36.