diff --git a/Sources/BluetoothGATT/GATTDescriptor.swift b/Sources/BluetoothGATT/GATTDescriptor.swift index 9838ee790..ff7b1fa8c 100644 --- a/Sources/BluetoothGATT/GATTDescriptor.swift +++ b/Sources/BluetoothGATT/GATTDescriptor.swift @@ -6,19 +6,33 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation +import Bluetooth /// GATT Characteristic Descriptor -public protocol GATTDescriptor { +public protocol GATTDescriptor: DataConvertible { /// Bluetooth UUID of the descriptor. static var uuid: BluetoothUUID { get } /// Decode from data. - init?(data: Data) + init?(data: Data) /// Encode to data. - var data: Data { get } + func append(to data: inout Data) +} + +public extension GATTAttribute.Descriptor { + + init( + _ descriptor: Descriptor, + permissions: ATTAttributePermissions = [.read] + ) { + self.init( + uuid: Descriptor.uuid, + value: Data(descriptor), + permissions: permissions + ) + } } // MARK: - Characteristic Descriptor