Migrate GATTCharacteristic to DataConvertible - #206
Merged
Conversation
…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
force-pushed
the
feature/gatt-data
branch
from
July 9, 2026 20:03
c29bc9c to
39d27d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Finishes the encode-side
DataContainermigration for the GATT characteristic types (#161) and removes the deprecatedFoundation.DataAPI surface.GATTCharacteristicnow refinesDataConvertible, matchingGATTDescriptorandGAPData. All 66 conforming types implement the genericappend<Data: DataContainer>(to:)anddataLengthinstead of hand-writtenvar data: Foundation.Data.DeprecatedGATTCharacteristicand the bridging defaults inGATTCharacteristic.swift. The old defaults (var data/append) were mutually recursive — a type implementing neither would infinitely recurse at runtime; that footgun is gone sinceappendis now a hard requirement.DataContainer.init<T: GATTCharacteristic>overload; theDataConvertibleone in the core module addsreserveCapacityplus a debugassert(count == dataLength)that validates every hand-writtendataLengthin tests.import Foundationfrom migrated files (kept where genuinely needed:GATTDateTime,GATTAlertNotificationControlPoint,GATTUUIDList).GATTBloodPressureManagement.swift→GATTBloodPressureMeasurement.swiftto match the type it declares.Bugs fixed in passing
GATTCrossTrainerDatanever declared theGATTCharacteristicconformance — it only had the members. Added.GATTCrossTrainerDatacounted 1 byte forexpendedEnergywhere the encoder writes 5 (Bits16 × 2 + Byte); harmless asreserveCapacity, wrong asdataLength. Fixed.GATTBloodPressureMeasurementencoded mean arterial pressure without.littleEndian, unlike its sibling fields (big-endian-platform bug). Normalized.GATTNewAlert.Informationno longer has afatalErrorpath on string encoding (data += rawValue.utf8).Tests
Replaced the 65 Foundation-only
#expect(characteristic.data == data)assertions with aroundTriphelper that checksdataLengthand round-trips each characteristic throughFoundation.Data,[UInt8], andLowEnergyAdvertisingData, so the generic path is actually exercised.Reviewer notes
characteristic.data— useData(characteristic)instead..littleEndian; CI hosts are little-endian so a missed one wouldn't fail tests.dataLengthasserts active) and release;swift format lint/swiftlintclean on touched files.