Skip to content

Migrate HCICommandParameter encoding to DataContainer - #207

Merged
colemancda merged 1 commit into
masterfrom
feature/hci-data
Jul 9, 2026
Merged

Migrate HCICommandParameter encoding to DataContainer#207
colemancda merged 1 commit into
masterfrom
feature/hci-data

Conversation

@colemancda

Copy link
Copy Markdown
Member

What changed

Finishes the encode-side DataContainer migration for the HCI layer (#161), the counterpart to #206 for BluetoothGATT.

  • HCICommandParameter now requires the generic func append<Data: DataContainer>(to:) instead of Foundation's var data: Data, and HCIPacketHeader (command/event headers) gets the same treatment. DataContainer gains init<T: HCICommandParameter>(_:) and init<T: HCIPacketHeader>(_:) for building buffers.
  • All 91 command/header encoders migrated to the generic API. Types that were already DataConvertible (e.g. HCILECreateConnection, HCILEEncrypt, HCILEAddDeviceToWhiteList) now encode through their existing append directly, dropping the redundant Foundation wrappers.
  • import Foundation removed from 167 of 172 files. The remaining five (BluetoothHostController, HCILESetScanEnable, HCIError, HCIPacketHeader, HCICommandTimeout) genuinely use Foundation.Data/TimeInterval/CustomNSError in the host-controller runtime and are left for a follow-up.
  • HCIWriteLocalName encodes UTF-8 + zero padding without constructing intermediate Foundation.Data; the crashing HCISetEventFilter stub keeps its fatalError but under the new signature (implementing it is tracked separately).

Not in scope

Making the host-controller runtime (deviceRequest/receive, garbageResponse(Data)) generic over DataContainer — that is a deeper refactor of the async I/O surface.

Reviewer notes

  • Source-breaking: command parameters and packet headers no longer expose .data — use Data(parameter) instead (the test target bridges this internally).
  • Encoder bodies were transformed mechanically (return Data([…])data += […], builder pattern → direct appends); byte order and field order are unchanged.
  • All 279 tests pass in debug and the module lints clean (swift format lint, swiftlint).

Finish the encode-side DataContainer migration for the HCI layer (#161):

- HCICommandParameter and HCIPacketHeader now require the generic
  append<Data: DataContainer>(to:) instead of Foundation's
  'var data: Data'; DataContainer gains initializers for both.
- Migrate all 91 command/header encoders to the generic API.
- Remove 'import Foundation' from 167 files; only the host controller
  runtime (BluetoothHostController, HCILESetScanEnable, HCIError,
  HCIPacketHeader, HCICommandTimeout) still uses Foundation.Data.

Source-breaking: command parameters and packet headers no longer
expose 'data'; use 'Data(value)' instead.
@colemancda
colemancda merged commit 1c2c86c into master Jul 9, 2026
34 of 38 checks passed
@colemancda
colemancda deleted the feature/hci-data branch July 9, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant