Skip to content

Commit

Permalink
#35 changed var to let on data types and improved performance when co…
Browse files Browse the repository at this point in the history
…nverting to little endian
  • Loading branch information
carlos21 committed May 24, 2018
1 parent 1f30f8b commit 4faf738
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Sources/GenericAccessProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ public struct GAPTxPowerLevel: GAPData {

public static let max: GAPTxPowerLevel = 127

public static var dataType: GAPDataType = .txPowerLevel
public static let dataType: GAPDataType = .txPowerLevel

public let powerLevel: Int8

Expand Down Expand Up @@ -994,7 +994,7 @@ public struct GAPClassOfDevice: GAPData {

public static let length = MemoryLayout<Identifier>.size

public static var dataType: GAPDataType = .classOfDevice
public static let dataType: GAPDataType = .classOfDevice

public let device: Identifier

Expand Down Expand Up @@ -1041,7 +1041,7 @@ public struct GAPSimplePairingHashC: GAPData {

public static let length = MemoryLayout<Hash>.size

public static var dataType: GAPDataType = .simplePairingHashC
public static let dataType: GAPDataType = .simplePairingHashC

public let hash: Hash

Expand Down Expand Up @@ -1103,7 +1103,7 @@ public struct GAPSimplePairingRandomizerR: GAPData {

public static let length = MemoryLayout<Hash>.size

public static var dataType: GAPDataType = .simplePairingRandomizerR
public static let dataType: GAPDataType = .simplePairingRandomizerR

public let hash: Hash

Expand Down Expand Up @@ -1165,7 +1165,7 @@ public struct GAPSecurityManagerTKValue: GAPData {

public static let length = MemoryLayout<Hash>.size

public static var dataType: GAPDataType = .securityManagerTKValue
public static let dataType: GAPDataType = .securityManagerTKValue

public let hash: Hash

Expand Down Expand Up @@ -1337,15 +1337,15 @@ extension GAPSecurityManagerOOBFlags: ExpressibleByIntegerLiteral {

public struct GAPSlaveConnectionIntervalRange: GAPData {

public static let length = MemoryLayout<UInt32>.size
public static let length = 4

public static let min: UInt16 = 0x0006

public static let max: UInt16 = 0x0C80

public static let undefined: UInt16 = 0xFFFF

public static var dataType: GAPDataType = .slaveConnectionIntervalRange
public static let dataType: GAPDataType = .slaveConnectionIntervalRange

public let intervalRange: (UInt16, UInt16)

Expand All @@ -1363,14 +1363,17 @@ public struct GAPSlaveConnectionIntervalRange: GAPData {
guard data.count == type(of: self).length
else { return nil }

let interval = (UInt16(bytes: (data[0], data[1])).littleEndian, UInt16(bytes: (data[2], data[3])).littleEndian)
let min = UInt16(littleEndian: UInt16(bytes: (data[0], data[1])))
let max = UInt16(littleEndian: UInt16(bytes: (data[2], data[3])))

self.init(intervalRange: interval)
self.init(intervalRange: (min, max))
}

public var data: Data {

return Data([intervalRange.0.bytes.0.littleEndian, intervalRange.0.bytes.1.littleEndian, intervalRange.1.bytes.0.littleEndian, intervalRange.1.bytes.1.littleEndian])
let range = (min: intervalRange.0.littleEndian.bytes, max: intervalRange.1.littleEndian.bytes)

return Data([range.min.0, range.min.1, range.max.0, range.max.1])
}

}
Expand Down

0 comments on commit 4faf738

Please sign in to comment.