diff --git a/Sources/BluetoothGATT/ATTFindInformationRequest.swift b/Sources/BluetoothGATT/ATTFindInformationRequest.swift index 22a5a3e3a..be53bcde0 100644 --- a/Sources/BluetoothGATT/ATTFindInformationRequest.swift +++ b/Sources/BluetoothGATT/ATTFindInformationRequest.swift @@ -6,62 +6,53 @@ // Copyright © 2018 PureSwift. All rights reserved. // -import Foundation +import Bluetooth /// Find Information Request /// /// The *Find Information Request* is used to obtain the mapping of attribute handles with their associated types. /// This allows a client to discover the list of attributes and their types on a server. @frozen -public struct ATTFindInformationRequest: ATTProtocolDataUnit, Equatable { +public struct ATTFindInformationRequest: ATTProtocolDataUnit, Equatable, Hashable, Sendable { - public static var attributeOpcode: ATTOpcode { return .findInformationRequest } + public static var attributeOpcode: ATTOpcode { .findInformationRequest } public var startHandle: UInt16 public var endHandle: UInt16 - public init(startHandle: UInt16, - endHandle: UInt16) { - + public init( + startHandle: UInt16, + endHandle: UInt16 + ) { self.startHandle = startHandle self.endHandle = endHandle } } -public extension ATTFindInformationRequest { +// MARK: - DataConvertible + +extension ATTFindInformationRequest: DataConvertible { - internal static var length: Int { return 5 } + public static var length: Int { 5 } - init?(data: Data) { + public init?(data: Data) { - guard data.count == type(of: self).length, - type(of: self).validateOpcode(data) + guard data.count == Self.length, + Self.validateOpcode(data) else { return nil } self.startHandle = UInt16(littleEndian: UInt16(bytes: (data[1], data[2]))) self.endHandle = UInt16(littleEndian: UInt16(bytes: (data[3], data[4]))) } - var data: Data { - - return Data(self) - } -} - -// MARK: - DataConvertible - -extension ATTFindInformationRequest: DataConvertible { - - var dataLength: Int { - - return type(of: self).length + public func append(to data: inout Data) where Data : DataContainer { + data += Self.attributeOpcode.rawValue + data += self.startHandle.littleEndian + data += self.endHandle.littleEndian } - static func += (data: inout T, value: ATTFindInformationRequest) { - - data += attributeOpcode.rawValue - data += value.startHandle.littleEndian - data += value.endHandle.littleEndian + public var dataLength: Int { + Self.length } }