Add support for generating mixed payload spec converters #87
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 is a proposal to resolve harp-tech/protocol#40 and provide automatically generated type converters for payload specs composed of heterogeneous member types.
This was already partially supported at the payload declaration level, where a different
interfaceTypecould be assigned to specific members. However, theoffsetattribute was limited to indexing exactly one element, so e.g. we could apply a mask to a U16 payload element to extract two U8 fields, but we could not do the opposite and compose a U16 field out of two U8 elements.Here we propose generalizing type conversion to allow the member
interfaceTypeto determine automatically how many bytes will be consumed from the payload array, and how the conversion will be performed.For now the initial implementation supports exclusively
U8registers, but could be extended in the future to any base word-size.Support for a new
lengthattribute is included. This has not yet been ratified in the core device schema, and can be ignored for simple payload specifications. Once the new schema is ratified, length can be used to allow more flexible conversions.Example mixed configuration spec
The following mixed payload spec includes a group mask, a boolean, two floats and one unsigned integer:
The generated conversion will become:
Where
ToByte,ToSingle,ToUInt32andWriteBytesare auxiliary methods for marshalling multi-byte values to/from arrays.