File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,10 +40,10 @@ public final class LsbBitReader: ByteReader, BitReader {
4040 /**
4141 Reads bit and returns it, advancing by one BIT position.
4242
43- - Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
44- to check if the end is reached.
43+ - Precondition: There MUST be enough data left.
4544 */
4645 public func bit( ) -> UInt8 {
46+ precondition ( bitsLeft >= 1 )
4747 let bit : UInt8 = self . currentByte & self . bitMask > 0 ? 1 : 0
4848
4949 if self . bitMask == 128 {
@@ -59,12 +59,14 @@ public final class LsbBitReader: ByteReader, BitReader {
5959 /**
6060 Reads `count` bits and returns them as a `Int` number, advancing by `count` BIT positions.
6161
62- - Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
63- to check if the end is reached .
62+ - Precondition: There MUST be enough data left.
63+ - Precondition: Parameter `fromBits` MUST not be less than 0 .
6464 */
6565 public func int( fromBits count: Int ) -> Int {
66+ precondition ( count >= 0 )
6667 guard count > 0
6768 else { return 0 }
69+ precondition ( bitsLeft >= count)
6870
6971 var result = 0
7072 for i in 0 ..< count {
Original file line number Diff line number Diff line change @@ -40,10 +40,10 @@ public final class MsbBitReader: ByteReader, BitReader {
4040 /**
4141 Reads bit and returns it, advancing by one BIT position.
4242
43- - Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
44- to check if the end is reached.
43+ - Precondition: There MUST be enough data left.
4544 */
4645 public func bit( ) -> UInt8 {
46+ precondition ( bitsLeft >= 1 )
4747 let bit : UInt8 = self . currentByte & self . bitMask > 0 ? 1 : 0
4848
4949 if self . bitMask == 1 {
@@ -59,12 +59,14 @@ public final class MsbBitReader: ByteReader, BitReader {
5959 /**
6060 Reads `count` bits and returns them as a `Int` number, advancing by `count` BIT positions.
6161
62- - Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
63- to check if the end is reached .
62+ - Precondition: There MUST be enough data left.
63+ - Precondition: Parameter `fromBits` MUST not be less than 0 .
6464 */
6565 public func int( fromBits count: Int ) -> Int {
66+ precondition ( count >= 0 )
6667 guard count > 0
6768 else { return 0 }
69+ precondition ( bitsLeft >= count)
6870
6971 var result = 0
7072 for i in 0 ..< count {
You can’t perform that action at this time.
0 commit comments