Hi,
This is something I was working on few past few weeks: using packed structs
for building and parsing HCI commands in NimBLE stack. For easier transition
I decided to have one big commit affecting both controller and host (mind the
size of change!:).
In general this follows similar changes done already for SMP and ATT. Packed
structs are used for accesing and creating protocol ordered data. While
parsing, unchanged data is passed up in stack as much as possible, so there
are some API constifications required due to that.
As usual, rule of thumb is that protocol data is accessed via packed structs,
and host ordered (parsed) data is (if needed) passed as unpacked structs.
I decided to leave unit tests "as is", which means some defines were moved
there and tests are stil using byte-by-byte parsing and contructions. I think
this is fine since it provides additional cross checking for implemention :)
There are serveral benefits of this approach:
- less source code - 4470 insertions(+), 6137 deletions(-)
- easy to map where host and controller use same command/event
- last but not least, less code size. Sample numbers for optimized build with
most features enabled:
nimble_controller.a 55602 -> 55246
nimble_host.a 68001 -> 65285
Note that while PR is ready to be merged (no regressions in our tests), there
is stil place for improvements: using packed structs for ACL, HCI transports,
some cleanups in generic code for HCI handling etc. This will be work on later
on.
PR implementing this is pending review at
https://github.com/apache/mynewt-nimble/pull/507
Comments are welcome.
--
pozdrawiam
Szymon Janc