Skip to content

Commit 0c359c3

Browse files
committed
Mention ByteReader's preconditions in bit readers' functions and make docs more consistent
1 parent edc6669 commit 0c359c3

3 files changed

Lines changed: 16 additions & 26 deletions

File tree

Sources/ByteReader.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ByteReader {
3737
/**
3838
Reads byte and returns it, advancing by one position.
3939

40-
- Precondition: There MUST be enough data left (`offset < size`).
40+
- Precondition: There MUST be enough data left.
4141
*/
4242
public func byte() -> UInt8 {
4343
precondition(self.offset < self.size)
@@ -48,7 +48,7 @@ public class ByteReader {
4848
/**
4949
Reads `count` bytes and returns them as an array of `UInt8`, advancing by `count` positions.
5050

51-
- Precondition: There MUST be enough data left (`offset + count <= size`).
51+
- Precondition: There MUST be enough data left.
5252
- Precondition: Parameter `count` MUST not be less than 0.
5353
*/
5454
public func bytes(count: Int) -> [UInt8] {
@@ -64,7 +64,7 @@ public class ByteReader {
6464
/**
6565
Reads 8 bytes and returns them as a `UInt64` number, advancing by 8 positions.
6666

67-
- Precondition: There MUST be enough data left to read (`offset + 8 <= size`).
67+
- Precondition: There MUST be enough data left.
6868
*/
6969
public func uint64() -> UInt64 {
7070
precondition(self.offset + 8 <= self.size)
@@ -76,7 +76,7 @@ public class ByteReader {
7676
/**
7777
Reads 4 bytes and returns them as a `UInt32` number, advancing by 4 positions.
7878

79-
- Precondition: There MUST be enough data left to read (`offset + 4 <= size`).
79+
- Precondition: There MUST be enough data left.
8080
*/
8181
public func uint32() -> UInt32 {
8282
precondition(self.offset + 4 <= self.size)
@@ -88,7 +88,7 @@ public class ByteReader {
8888
/**
8989
Reads 2 bytes and returns them as a `UInt16` number, advancing by 2 positions.
9090

91-
- Precondition: There MUST be enough data left to read (`offset + 2 <= size`).
91+
- Precondition: There MUST be enough data left.
9292
*/
9393
public func uint16() -> UInt16 {
9494
precondition(self.offset + 2 <= self.size)

Sources/LsbBitReader.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ public final class LsbBitReader: ByteReader, BitReader {
113113
/**
114114
Reads byte and returns it, advancing by one BYTE position.
115115

116-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
117-
to check if the end is reached.
118116
- Precondition: Reader MUST be aligned.
117+
- Precondition: There MUST be enough data left.
119118
*/
120119
public override func byte() -> UInt8 {
121120
precondition(isAligned, "BitReader is not aligned.")
@@ -125,9 +124,8 @@ public final class LsbBitReader: ByteReader, BitReader {
125124
/**
126125
Reads `count` bytes and returns them as an array of `UInt8`, advancing by `count` BYTE positions.
127126

128-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
129-
to check if the end is reached.
130127
- Precondition: Reader MUST be aligned.
128+
- Precondition: There MUST be enough data left.
131129
*/
132130
public override func bytes(count: Int) -> [UInt8] {
133131
precondition(isAligned, "BitReader is not aligned.")
@@ -137,9 +135,8 @@ public final class LsbBitReader: ByteReader, BitReader {
137135
/**
138136
Reads 8 bytes and returns them as a `UInt64` number, advancing by 8 BYTE positions.
139137

140-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
141-
to check if the end is reached.
142138
- Precondition: Reader MUST be aligned.
139+
- Precondition: There MUST be enough data left.
143140
*/
144141
public override func uint64() -> UInt64 {
145142
precondition(isAligned, "BitReader is not aligned.")
@@ -149,9 +146,8 @@ public final class LsbBitReader: ByteReader, BitReader {
149146
/**
150147
Reads 4 bytes and returns them as a `UInt32` number, advancing by 4 BYTE positions.
151148

152-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
153-
to check if the end is reached.
154149
- Precondition: Reader MUST be aligned.
150+
- Precondition: There MUST be enough data left.
155151
*/
156152
public override func uint32() -> UInt32 {
157153
precondition(isAligned, "BitReader is not aligned.")
@@ -161,9 +157,8 @@ public final class LsbBitReader: ByteReader, BitReader {
161157
/**
162158
Reads 2 bytes and returns them as a `UInt16` number, advancing by 2 BYTE positions.
163159

164-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
165-
to check if the end is reached.
166160
- Precondition: Reader MUST be aligned.
161+
- Precondition: There MUST be enough data left.
167162
*/
168163
public override func uint16() -> UInt16 {
169164
precondition(isAligned, "BitReader is not aligned.")

Sources/MsbBitReader.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ 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-
- Precondition: There MUST be enough data left.
6362
- Precondition: Parameter `fromBits` MUST not be less than 0.
63+
- Precondition: There MUST be enough data left.
6464
*/
6565
public func int(fromBits count: Int) -> Int {
6666
precondition(count >= 0)
@@ -113,9 +113,8 @@ public final class MsbBitReader: ByteReader, BitReader {
113113
/**
114114
Reads byte and returns it, advancing by one BYTE position.
115115

116-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
117-
to check if the end is reached.
118116
- Precondition: Reader MUST be aligned.
117+
- Precondition: There MUST be enough data left.
119118
*/
120119
public override func byte() -> UInt8 {
121120
precondition(isAligned, "BitReader is not aligned.")
@@ -125,9 +124,8 @@ public final class MsbBitReader: ByteReader, BitReader {
125124
/**
126125
Reads `count` bytes and returns them as an array of `UInt8`, advancing by `count` BYTE positions.
127126

128-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
129-
to check if the end is reached.
130127
- Precondition: Reader MUST be aligned.
128+
- Precondition: There MUST be enough data left.
131129
*/
132130
public override func bytes(count: Int) -> [UInt8] {
133131
precondition(isAligned, "BitReader is not aligned.")
@@ -137,9 +135,8 @@ public final class MsbBitReader: ByteReader, BitReader {
137135
/**
138136
Reads 8 bytes and returns them as a `UInt64` number, advancing by 8 BYTE positions.
139137

140-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
141-
to check if the end is reached.
142138
- Precondition: Reader MUST be aligned.
139+
- Precondition: There MUST be enough data left.
143140
*/
144141
public override func uint64() -> UInt64 {
145142
precondition(isAligned, "BitReader is not aligned.")
@@ -149,9 +146,8 @@ public final class MsbBitReader: ByteReader, BitReader {
149146
/**
150147
Reads 4 bytes and returns them as a `UInt32` number, advancing by 4 BYTE positions.
151148

152-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
153-
to check if the end is reached.
154149
- Precondition: Reader MUST be aligned.
150+
- Precondition: There MUST be enough data left.
155151
*/
156152
public override func uint32() -> UInt32 {
157153
precondition(isAligned, "BitReader is not aligned.")
@@ -161,9 +157,8 @@ public final class MsbBitReader: ByteReader, BitReader {
161157
/**
162158
Reads 2 bytes and returns them as a `UInt16` number, advancing by 2 BYTE positions.
163159

164-
- Warning: Doesn't check if there is any data left. It is advisable to use `isFinished` BEFORE calling this method
165-
to check if the end is reached.
166160
- Precondition: Reader MUST be aligned.
161+
- Precondition: There MUST be enough data left.
167162
*/
168163
public override func uint16() -> UInt16 {
169164
precondition(isAligned, "BitReader is not aligned.")

0 commit comments

Comments
 (0)