Skip to content

Replace BitMaskOptionSet with OptionSet #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 0 additions & 197 deletions Sources/Bluetooth/BitMaskOption.swift

This file was deleted.

84 changes: 43 additions & 41 deletions Sources/Bluetooth/ClassOfDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public struct ClassOfDevice: Equatable, Sendable {

public var formatType: FormatType

public var majorServiceClass: BitMaskOptionSet<MajorServiceClass>
public var majorServiceClass: MajorServiceClass

public var majorDeviceClass: MajorDeviceClass

public init(
formatType: FormatType,
majorServiceClass: BitMaskOptionSet<MajorServiceClass>,
majorServiceClass: MajorServiceClass,
majorDeviceClass: MajorDeviceClass
) {

Expand All @@ -43,7 +43,7 @@ extension ClassOfDevice: DataConvertible {

let majorServiceValue = UInt16(littleEndian: UInt16(bytes: (data[1], data[2]))) >> 5

self.majorServiceClass = BitMaskOptionSet<MajorServiceClass>(rawValue: majorServiceValue)
self.majorServiceClass = MajorServiceClass(rawValue: majorServiceValue)

let majorDeviceClassType = MajorDeviceClassType(rawValue: (data[1] << 3) >> 3) ?? MajorDeviceClassType.miscellaneous

Expand All @@ -70,7 +70,7 @@ extension ClassOfDevice: DataConvertible {
PeripheralDevice(rawValue: (data[0] << 2) >> 4) ?? .uncategorized)

case .imaging:
self.majorDeviceClass = .imaging(BitMaskOptionSet<Imaging>(rawValue: data[0] >> 4))
self.majorDeviceClass = .imaging(Imaging(rawValue: data[0] >> 4))

case .wearable:
self.majorDeviceClass = .wearable(Wearable(rawValue: data[0] >> 2) ?? .uncategorized)
Expand Down Expand Up @@ -127,37 +127,37 @@ extension ClassOfDevice {
}
}

public extension ClassOfDevice {

enum MajorServiceClass: UInt16, BitMaskOption, Sendable {

/// Limited Discoverable Mode [Ref #1]
case limitedDiscoverable = 0b01

/// Positioning (Location identification)
case positioning = 0b1000
extension ClassOfDevice {
@OptionSet<UInt16>
public struct MajorServiceClass: Sendable {
private enum Options: UInt16 {
/// Limited Discoverable Mode [Ref #1]
case limitedDiscoverable = 0b01

/// Networking (LAN, Ad hoc, ...)
case networking = 0b10000
/// Positioning (Location identification)
case positioning = 0b1000

/// Rendering (Printing, Speakers, ...)
case rendering = 0b100000
/// Networking (LAN, Ad hoc, ...)
case networking = 0b10000

/// Capturing (Scanner, Microphone, ...)
case capturing = 0b1000000
/// Rendering (Printing, Speakers, ...)
case rendering = 0b100000

/// Object Transfer (v-Inbox, v-Folder, ...)
case objectTransfer = 0b10000000
/// Capturing (Scanner, Microphone, ...)
case capturing = 0b1000000

/// Audio (Speaker, Microphone, Headset service, ...)
case audio = 0b1_00000000
/// Object Transfer (v-Inbox, v-Folder, ...)
case objectTransfer = 0b10000000

/// Telephony (Cordless telephony, Modem, Headset service, ...)
case telephony = 0b10_00000000
/// Audio (Speaker, Microphone, Headset service, ...)
case audio = 0b1_00000000

/// Information (WEB-server, WAP-server, ...)
case information = 0b100_00000000
/// Telephony (Cordless telephony, Modem, Headset service, ...)
case telephony = 0b10_00000000

/// Information (WEB-server, WAP-server, ...)
case information = 0b100_00000000
}
public static let allCases: [MajorServiceClass] = [
.limitedDiscoverable,
.positioning,
Expand Down Expand Up @@ -195,7 +195,7 @@ public extension ClassOfDevice {
case peripheral(PeripheralKeyboardPointing, PeripheralDevice)

/// Imaging (printer, scanner, camera, display, ...)
case imaging(BitMaskOptionSet<Imaging>)
case imaging(Imaging)

/// Wearable
case wearable(Wearable)
Expand Down Expand Up @@ -522,24 +522,26 @@ public extension ClassOfDevice.MinorDeviceClass {
}
}

public extension ClassOfDevice.MinorDeviceClass {

enum Imaging: UInt8, BitMaskOption, Sendable, CaseIterable {
extension ClassOfDevice.MinorDeviceClass {

/// Uncategorized
case uncategorized = 0b00
@OptionSet<UInt8>
public struct Imaging: Sendable {
private enum Options: UInt8 {
/// Uncategorized
case uncategorized = 0b00

/// Display
case display = 0b01
/// Display
case display = 0b01

/// Camera
case camera = 0b10
/// Camera
case camera = 0b10

/// Scanner
case scanner = 0b100
/// Scanner
case scanner = 0b100

/// Printer
case printer = 0b1000
/// Printer
case printer = 0b1000
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/Bluetooth/OptionSetMacro.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
@attached(extension, conformances: OptionSet)
public macro OptionSet<RawType>() = #externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
Loading