Skip to content

Commit 63afc6e

Browse files
committed
Add bitsLeft private comptued property to bit readers
It will be used for various preconditions in bit readers' functions.
1 parent c58c45f commit 63afc6e

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

Sources/LsbBitReader.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public final class LsbBitReader: ByteReader, BitReader {
1414
private var bitMask: UInt8 = 1
1515
private var currentByte: UInt8
1616

17+
private var bitsLeft: Int {
18+
if isFinished {
19+
return 0
20+
} else {
21+
return (self.size - self.offset) * 8 + 8 - bitMask.trailingZeroBitCount
22+
}
23+
}
24+
1725
/// Creates an instance for reading bits (and bytes) from `data`.
1826
public override init(data: Data) {
1927
if data.count > 0 {

Sources/MsbBitReader.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ public final class MsbBitReader: ByteReader, BitReader {
1414
private var bitMask: UInt8 = 128
1515
private var currentByte: UInt8
1616

17+
private var bitsLeft: Int {
18+
if isFinished {
19+
return 0
20+
} else {
21+
return (self.size - self.offset) * 8 + 8 - bitMask.leadingZeroBitCount
22+
}
23+
}
24+
1725
/// Creates an instance for reading bits (and bytes) from `data`.
1826
public override init(data: Data) {
1927
if data.count > 0 {

0 commit comments

Comments
 (0)