Support variable length structs as array elements
- Dominant language
- Python
- Stars
- 92
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
I was trying to define a set of emboss structs from the batch scanning section of [Android's Bluetooth vendor extensions](https://source.android.com/docs/core/connect/bluetooth/hci_requirements). In the full version of the results that the Controller returns, there are some variable length array elements that are currently impossible to add to Emboss. I would have liked to do something like this:
```
struct LEBatchScanTruncatedResult:
0 [+hci.BdAddr.$size_in_bytes] hci.BdAddr peer_address
$next [+1] hci.LEAddressType peer_address_type
$next [+1] Int tx_power
$next [+1] Int rssi
$next [+2] UInt timestamp
struct LEBatchScanFullResult:
0 [+hci.BdAddr.$size_in_bytes] hci.BdAddr peer_address
$next [+1] hci.LEAddressType peer_address_type
$next [+1] Int tx_power
$next [+1] Int rssi
$next [+2] UInt timestamp
$next [+1] UInt advertising_data_length (ad_len)
$next [+ad_len] UInt:8[ad_len] advertising_data
$next [+1] UInt scan_response_length (sr_len)
$next [+sr_len] UInt:8[sr_len] scan_response_data
struct LEBatchScanReadResultsCommandCompleteEvent:
let hdr_size = hci.CommandCompleteEvent.$size_in_bytes
0 [+hdr_size] hci.CommandCompleteEvent command_complete
$next [+1] hci.StatusCode status
$next [+1] BatchScanSubOpcode sub_opcode
[requires: this == BatchScanSubOpcode.READ_RESULT_PARAMETERS]
$next [+1] BatchScanReadMode read_mode
$next [+1] UInt num_records
if read_mode == BatchScanReadMode.TRUNCATED_MODE:
$next [+LEBatchScanTruncatedResult.$size_in_bytes] LEBatchScanTruncatedResult[num_records] truncated_results
if read_mode == BatchScanReadMode.FULL_MODE:
let remaining = command_complete.return_parameters_size-hdr_size-4
$next [+remaining] LEBatchScanFullResult[num_records] full_results
```
Unfortunately, this results in an error from Emboss: "error: Array elements must be fixed size." We should figure out a way to add such functionality in so that users don't have to awkwardly break up packets into multiple structs.
Contributor guide
Assessment
This issue has not been assessed yet.