Skip to content

Migrate GATTCharacteristic to DataConvertible - #206

Merged
colemancda merged 3 commits into
masterfrom
feature/gatt-data
Jul 9, 2026
Merged

Migrate GATTCharacteristic to DataConvertible#206
colemancda merged 3 commits into
masterfrom
feature/gatt-data

Conversation

@colemancda

@colemancda colemancda commented Jul 9, 2026

Copy link
Copy Markdown
Member

What changed

Finishes the encode-side DataContainer migration for the GATT characteristic types (#161) and removes the deprecated Foundation.Data API surface.

  • GATTCharacteristic now refines DataConvertible, matching GATTDescriptor and GAPData. All 66 conforming types implement the generic append<Data: DataContainer>(to:) and dataLength instead of hand-written var data: Foundation.Data.
  • Removed DeprecatedGATTCharacteristic and the bridging defaults in GATTCharacteristic.swift. The old defaults (var data / append) were mutually recursive — a type implementing neither would infinitely recurse at runtime; that footgun is gone since append is now a hard requirement.
  • Removed the module's own DataContainer.init<T: GATTCharacteristic> overload; the DataConvertible one in the core module adds reserveCapacity plus a debug assert(count == dataLength) that validates every hand-written dataLength in tests.
  • Dropped import Foundation from migrated files (kept where genuinely needed: GATTDateTime, GATTAlertNotificationControlPoint, GATTUUIDList).
  • Renamed GATTBloodPressureManagement.swiftGATTBloodPressureMeasurement.swift to match the type it declares.

Bugs fixed in passing

  • GATTCrossTrainerData never declared the GATTCharacteristic conformance — it only had the members. Added.
  • GATTCrossTrainerData counted 1 byte for expendedEnergy where the encoder writes 5 (Bits16 × 2 + Byte); harmless as reserveCapacity, wrong as dataLength. Fixed.
  • GATTBloodPressureMeasurement encoded mean arterial pressure without .littleEndian, unlike its sibling fields (big-endian-platform bug). Normalized.
  • GATTNewAlert.Information no longer has a fatalError path on string encoding (data += rawValue.utf8).

Tests

Replaced the 65 Foundation-only #expect(characteristic.data == data) assertions with a roundTrip helper that checks dataLength and round-trips each characteristic through Foundation.Data, [UInt8], and LowEnergyAdvertisingData, so the generic path is actually exercised.

Reviewer notes

  • Source-breaking: downstream code loses characteristic.data — use Data(characteristic) instead.
  • Byte-order review point: all multibyte appends go through .littleEndian; CI hosts are little-endian so a missed one wouldn't fail tests.
  • All 279 tests pass in debug (with the dataLength asserts active) and release; swift format lint / swiftlint clean on touched files.

…ent.swift

Match the filename to the declared type and remove duplicate imports.
Finish the encode-side DataContainer migration for all GATT
characteristic types (#161):

- GATTCharacteristic now refines DataConvertible, matching GATTDescriptor
  and GAPData; every type implements the generic append(to:) and
  dataLength instead of Foundation.Data encoding.
- Remove DeprecatedGATTCharacteristic and the mutually recursive
  bridging defaults (var data / append).
- Remove the redundant DataContainer.init<T: GATTCharacteristic>
  overload; the DataConvertible one adds reserveCapacity and a debug
  assert validating dataLength.
- Add missing GATTCharacteristic conformance to GATTCrossTrainerData
  and fix its expendedEnergy encoded length computation.
- Drop unconditional Foundation imports from migrated files.

Source-breaking: 'characteristic.data' is removed; use
'Data(characteristic)' instead.
Replace the Foundation-only encode assertions with a roundTrip helper
that validates dataLength and re-encodes each characteristic through
Foundation.Data, [UInt8] and LowEnergyAdvertisingData, and decodes from
a non-Foundation container.
@colemancda
colemancda force-pushed the feature/gatt-data branch from c29bc9c to 39d27d0 Compare July 9, 2026 20:03
@colemancda
colemancda merged commit 7a63257 into master Jul 9, 2026
28 of 38 checks passed
@colemancda
colemancda deleted the feature/gatt-data branch July 9, 2026 20:22
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