BitReader
public protocol BitReader : ByteReader
A type that contains functions for reading Data
bit-by-bit and byte-by-byte.
-
True, if a bit pointer is aligned to a byte boundary.
Declaration
Swift
var isAligned: Bool { get }
-
Amount of bits left to read.
Declaration
Swift
var bitsLeft: Int { get }
-
Amount of bits that were already read.
Declaration
Swift
var bitsRead: Int { get }
-
Converts a
ByteReader
instance into aBitReader
, enabling bits reading capabilities. The currentoffset
value of thebyteReader
is preserved.Declaration
Swift
init(_ byteReader: ByteReader)
-
Advances a bit pointer by the amount of bits.
Declaration
Swift
func advance(by count: Int)
-
Reads a bit and returns it, advancing by one bit position.
Declaration
Swift
func bit() -> UInt8
-
Reads
count
bits and returns them as a[UInt8]
array, advancing bycount
bit positions.Declaration
Swift
func bits(count: Int) -> [UInt8]
-
int(fromBits:
Default implementation) Reads
fromBits
bits and returns them as aInt
number, advancing byfromBits
bit positions.Default Implementation
Reads
fromBits
bits by either usinguint64(fromBits:)
oruint32(fromBits:)
depending on the platform’s integer bit width, converts the result toInt
, and returns it, advancing byfromBits
bit positions.Note
If the data is supposed to represent a signed integer, it is recommended to use thesignedInt(fromBits:representation:)
function to get a correct result.Declaration
Swift
func int(fromBits count: Int) -> Int
-
Reads
fromBits
bits, treating them as a binaryrepresenation
of a signed integer, and returns the result as aInt
number, advancing byfromBits
bit positions.Declaration
Swift
func signedInt(fromBits count: Int, representation: SignedNumberRepresentation) -> Int
-
Reads
fromBits
bits and returns them as aUInt8
number, advancing byfromBits
bit positions.Declaration
Swift
func byte(fromBits count: Int) -> UInt8
-
Reads
fromBits
bits and returns them as aUInt16
number, advancing byfromBits
bit positions.Declaration
Swift
func uint16(fromBits count: Int) -> UInt16
-
Reads
fromBits
bits and returns them as aUInt32
number, advancing byfromBits
bit positions.Declaration
Swift
func uint32(fromBits count: Int) -> UInt32
-
Reads
fromBits
bits and returns them as aUInt64
number, advancing byfromBits
bit positions.Declaration
Swift
func uint64(fromBits count: Int) -> UInt64
-
Aligns a bit pointer to a byte boundary, i.e. moves the bit pointer to the first bit of the next byte.
Declaration
Swift
func align()