Skip to content

Commit

Permalink
#161 Add DataConvertible conformance to `GATTClientCharacteristicCo…
Browse files Browse the repository at this point in the history
…nfiguration`
  • Loading branch information
colemancda committed Nov 8, 2024
1 parent b44598e commit 02c7197
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sources/BluetoothGATT/GATTClientCharacteristicConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ extension GATTClientCharacteristicConfiguration: ExpressibleByIntegerLiteral {
}
}

// MARK: - DataConvertible

extension GATTClientCharacteristicConfiguration: DataConvertible {

public static var length: Int { 2 }

public init?<Data: DataContainer>(data: Data) {

guard data.count == Self.length
else { return nil }

let rawValue = UInt16(littleEndian: UInt16(bytes: (data[0], data[1])))
self.init(rawValue: rawValue)
}

public func append<Data>(to data: inout Data) where Data : DataContainer {
data += rawValue.littleEndian
}

public var dataLength: Int { Self.length }
}

// MARK: - Options

Expand Down

0 comments on commit 02c7197

Please sign in to comment.