-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for generating mixed payload spec converters #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@Poofjunior suggested member length inference rules should be made clear in a documentation table, so it can inform both users of the generator and developers of other interface generators, e.g. Python. |
|
Feedback from SRM:
|
98f5bf9 to
8bd4519
Compare
f2c541a to
29d1a06
Compare
- Auto-generate converters for payload spec with mixed types - Support for explicit member length - Support for inferring member length based on interface type - AllowUnsafeBlocks is now required for building generated helper code
Assumes UTF-8 encoding for strings, and sub-arrays of the same primitive payload type.
Conversion code for custom interface types can often be shared across registers. Here we make the internal conversion class partial and provide a simple heuristic for generating conversion method calls based on the interface type name.
Also added regression test for a complex register mixing mask types.
The current spec assumes fixed-length strings but built-in encoding methods throw if indices are out of bounds. Here we ensure longer strings are trimmed to fit register length on encoding. Conversely, any null-terminators are removed during decoding.
In addition to fixed-length string payload members we want to allow fixed-length string registers.
29d1a06 to
d052122
Compare
|
@Poofjunior @bruno-f-cruz In the end it just isn't possible to do automatic size inference for some important types, e.g. We should still talk about and provide completion for these built-in interface types in the spec, but it will probably be easier to start explicit for the purposes of these mixed payload converters. |
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 for a new
lengthattribute to determine how many bytes will be consumed from the payload array. For now the initial implementation provides conversions fromU8registers, but could be extended in the future to any base word-size.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
ToSingle,ToUInt32andWriteBytesare auxiliary methods for marshalling multi-byte values to/from arrays.