Skip to content

Commit

Permalink
#161 Add DataConvertible conformance to GATTDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 8, 2024
1 parent a2e38bc commit d3adea7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Sources/BluetoothGATT/GATTDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: DataContainer>(data: Data)

/// Encode to data.
var data: Data { get }
func append<Data: DataContainer>(to data: inout Data)
}

public extension GATTAttribute.Descriptor {

init<Descriptor: GATTDescriptor>(
_ descriptor: Descriptor,
permissions: ATTAttributePermissions = [.read]
) {
self.init(
uuid: Descriptor.uuid,
value: Data(descriptor),
permissions: permissions
)
}
}

// MARK: - Characteristic Descriptor
Expand Down

0 comments on commit d3adea7

Please sign in to comment.