Skip to content

Commit

Permalink
Improved performance with BitMaskOptionSet
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Dec 11, 2017
1 parent c7b15c0 commit a250d5c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Sources/BluetoothLinux/GATTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public extension GATTClient {

public let uuid: BluetoothUUID

public let properties: Set<Property>
public let properties: BitMaskOptionSet<Property>

public let handle: (declaration: UInt16, value: UInt16)
}
Expand Down Expand Up @@ -516,7 +516,7 @@ internal extension GATTClient {
/// Characteristic Properties
///
/// Bit field of characteristic properties.
var properties: Set<Property>
var properties: BitMaskOptionSet<Property>

/// Characteristic Value Handle
///
Expand All @@ -533,7 +533,7 @@ internal extension GATTClient {
guard let length = Length(rawValue: bytes.count)
else { return nil }

let properties = Property.from(flags: bytes[0])
let properties = BitMaskOptionSet<Property>(rawValue: bytes[0])

let valueHandle = UInt16(littleEndian: UInt16(bytes: (bytes[1], bytes[2])))

Expand Down
2 changes: 1 addition & 1 deletion Sources/BluetoothLinux/GATTDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public extension GATTDatabase {

let declarationAttribute: Attribute = {

let propertiesMask = characteristic.properties.flags
let propertiesMask = characteristic.properties.rawValue
let valueHandleBytes = (handle + 1).littleEndian.bytes
let value = [propertiesMask, valueHandleBytes.0, valueHandleBytes.1] + characteristic.uuid.littleEndianData

Expand Down
7 changes: 2 additions & 5 deletions Sources/BluetoothLinux/Scan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public extension Adapter {
/// - Parameter deviceClass: Device class to filter results by.
///
/// - Parameter options: Array of ```ScanOption```.
func scan(duration: Int = 8, limit: Int = 255, deviceClass: DeviceClass? = nil, options: [ScanOption] = []) throws -> [InquiryResult] {
func scan(duration: Int = 8, limit: Int = 255, deviceClass: DeviceClass? = nil, options: BitMaskOptionSet<ScanOption> = []) throws -> [InquiryResult] {

assert(duration > 0, "Scan must be longer than 0 seconds")
assert(limit > 0, "Must scan at least one device")
assert(limit <= 255, "Cannot be larger than UInt8.max")

let flags = options.flags
let flags = options.rawValue

return try HCIInquiry(identifier, duration: duration, scanLimit: limit, deviceClass: deviceClass, flags: flags)
}
Expand Down Expand Up @@ -76,10 +76,7 @@ public extension Adapter {

public static let all: Set<ScanOption> = [.flushCache]

#if swift(>=3.1)
#elseif swift(>=3.0)
public typealias RawValue = Int32
#endif
}

public struct InquiryResult {
Expand Down
3 changes: 2 additions & 1 deletion Tests/BluetoothLinuxTests/DataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ final class DataTests: XCTestCase {

XCTAssert(characteristicDeclaration.valueHandle == 42)
XCTAssert(characteristicDeclaration.uuid == characteristic.uuid)
XCTAssert(characteristicDeclaration.properties == Set(characteristic.properties))
XCTAssert(characteristicDeclaration.properties.set == Set(characteristic.properties))
XCTAssert(characteristicDeclaration.properties == characteristic.properties)
}
}
}
Expand Down

0 comments on commit a250d5c

Please sign in to comment.