Skip to content

Commit 6059112

Browse files
committed
Bit readers' bits() function is now a common extension of BitReader protocol
1 parent 24743cd commit 6059112

3 files changed

Lines changed: 17 additions & 28 deletions

File tree

Sources/BitReader.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,20 @@ public protocol BitReader: class {
3434
func uint16() -> UInt16
3535

3636
}
37+
38+
extension BitReader {
39+
40+
public func bits(count: Int) -> [UInt8] {
41+
guard count > 0
42+
else { return [] }
43+
44+
var array = [UInt8]()
45+
array.reserveCapacity(count)
46+
for _ in 0..<count {
47+
array.append(self.bit())
48+
}
49+
50+
return array
51+
}
52+
53+
}

Sources/LsbBitReader.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ public final class LsbBitReader: ByteReader, BitReader {
1313
return self.bitMask == 1
1414
}
1515

16-
public func bits(count: Int) -> [UInt8] {
17-
guard count > 0 else {
18-
return []
19-
}
20-
21-
var array = [UInt8]()
22-
array.reserveCapacity(count)
23-
for _ in 0..<count {
24-
array.append(self.bit())
25-
}
26-
27-
return array
28-
}
29-
3016
public func intFromBits(count: Int) -> Int {
3117
guard count > 0 else {
3218
return 0

Sources/MsbBitReader.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ public final class MsbBitReader: ByteReader, BitReader {
1313
return self.bitMask == 128
1414
}
1515

16-
public func bits(count: Int) -> [UInt8] {
17-
guard count > 0 else {
18-
return []
19-
}
20-
21-
var array = [UInt8]()
22-
array.reserveCapacity(count)
23-
for _ in 0..<count {
24-
array.append(self.bit())
25-
}
26-
27-
return array
28-
}
29-
3016
public func intFromBits(count: Int) -> Int {
3117
guard count > 0 else {
3218
return 0

0 commit comments

Comments
 (0)