Skip to content

Commit

Permalink
#161 Add DataConvertible conformance to GATTExternalReportReference
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 8, 2024
1 parent ea9c036 commit d513ed6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions Sources/BluetoothGATT/GATTExternalReportReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,36 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation
import Bluetooth

// MARK: - External Report Reference
/// GATT External Report Reference Descriptor
///
/// The External Report Reference characteristic descriptor allows a HID Host to map information from the Report Map characteristic value for Input Report, Output Report or Feature Report data to the Characteristic UUID of external service characteristics used to transfer the associated data.
@frozen
public struct GATTExternalReportReference: GATTDescriptor {
public struct GATTExternalReportReference: GATTDescriptor, Hashable, Sendable {

public static let uuid: BluetoothUUID = .externalReportReference
public static var uuid: BluetoothUUID { .externalReportReference }

public let uuid: BluetoothUUID
public var uuid: BluetoothUUID

public init(uuid: BluetoothUUID) {

self.uuid = uuid
}
}

extension GATTExternalReportReference: DataConvertible {

public init?(data: Data) {

public init?<Data: DataContainer>(data: Data) {
guard let uuid = BluetoothUUID(data: data)
else { return nil }

self.init(uuid: BluetoothUUID(littleEndian: uuid))
}

public var data: Data {
return Data(uuid)
public func append<Data>(to data: inout Data) where Data : DataContainer {
data += uuid
}

public var descriptor: GATTAttribute.Descriptor {

return GATTAttribute.Descriptor(uuid: type(of: self).uuid,
value: data,
permissions: [.read])
public var dataLength: Int {
uuid.dataLength
}
}

0 comments on commit d513ed6

Please sign in to comment.