@@ -8,7 +8,7 @@ import Foundation
88/// A type that contains functions for reading `Data` bit-by-bit and byte-by-byte.
99public protocol BitReader : ByteReader {
1010
11- /// True, if reader's BIT pointer is aligned with the BYTE border .
11+ /// True, if a bit pointer is aligned to a byte boundary .
1212 var isAligned : Bool { get }
1313
1414 /// Amount of bits left to read.
@@ -18,45 +18,55 @@ public protocol BitReader: ByteReader {
1818 var bitsRead : Int { get }
1919
2020 /**
21- Converts a `ByteReader` instance into `BitReader`, enabling bits reading capabilities. Current `offset` value of
22- `byteReader` is preserved.
21+ Converts a `ByteReader` instance into a `BitReader`, enabling bits reading capabilities. The current `offset` value
22+ of the `byteReader` is preserved.
2323 */
2424 init ( _ byteReader: ByteReader )
2525
26- // Advances reader's BIT pointer by the specified amount of bits.
26+ /// Advances a bit pointer by the amount of bits.
2727 func advance( by count: Int )
2828
29- /// Reads bit and returns it, advancing by one BIT position.
29+ /// Reads a bit and returns it, advancing by one bit position.
3030 func bit( ) -> UInt8
3131
32- /// Reads `count` bits and returns them as an array of ` UInt8` , advancing by `count` BIT positions.
32+ /// Reads `count` bits and returns them as a `[ UInt8]` array , advancing by `count` bit positions.
3333 func bits( count: Int ) -> [ UInt8 ]
3434
35- /// Reads `fromBits` bits and returns them as an `Int` number, advancing by `fromBits` BIT positions.
35+ /// Reads `fromBits` bits and returns them as a `Int` number, advancing by `fromBits` bit positions.
3636 func int( fromBits count: Int ) -> Int
3737
38- /// Reads `fromBits` bits and returns them as an `Int` number, advancing by `fromBits` BIT positions.
38+ /**
39+ Reads `fromBits` bits, treating them as a binary `represenation` of a signed integer, and returns the result as a
40+ `Int` number, advancing by `fromBits` bit positions.
41+ */
3942 func signedInt( fromBits count: Int , representation: SignedNumberRepresentation ) -> Int
4043
41- /// Reads `fromBits` bits and returns them as an `UInt8` number, advancing by `fromBits` BIT positions.
44+ /// Reads `fromBits` bits and returns them as a `UInt8` number, advancing by `fromBits` bit positions.
4245 func byte( fromBits count: Int ) -> UInt8
4346
44- /// Reads `fromBits` bits and returns them as an `UInt16` number, advancing by `fromBits` BIT positions.
47+ /// Reads `fromBits` bits and returns them as a `UInt16` number, advancing by `fromBits` bit positions.
4548 func uint16( fromBits count: Int ) -> UInt16
4649
47- /// Reads `fromBits` bits and returns them as an `UInt32` number, advancing by `fromBits` BIT positions.
50+ /// Reads `fromBits` bits and returns them as a `UInt32` number, advancing by `fromBits` bit positions.
4851 func uint32( fromBits count: Int ) -> UInt32
4952
50- /// Reads `fromBits` bits and returns them as an `UInt64` number, advancing by `fromBits` BIT positions.
53+ /// Reads `fromBits` bits and returns them as a `UInt64` number, advancing by `fromBits` bit positions.
5154 func uint64( fromBits count: Int ) -> UInt64
5255
53- /// Aligns reader's BIT pointer to the BYTE border , i.e. moves BIT pointer to the first BIT of the next BYTE .
56+ /// Aligns a bit pointer to a byte boundary , i.e. moves the bit pointer to the first bit of the next byte .
5457 func align( )
5558
5659}
5760
5861extension BitReader {
5962
63+ /**
64+ Reads `fromBits` bits by either using `uint64(fromBits:)` or `uint32(fromBits:)` depending on the platform's
65+ integer bit width, converts the result to `Int`, and returns it, advancing by `fromBits` bit positions.
66+
67+ - Note: If the data is supposed to represent a signed integer, it is recommended to use the
68+ `signedInt(fromBits:representation:)` function to get a correct result.
69+ */
6070 public func int( fromBits count: Int ) -> Int {
6171 if MemoryLayout< Int> . size == 8 {
6272 return Int ( truncatingIfNeeded: self . uint64 ( fromBits: count) )
0 commit comments