MsbBitReader
public final class MsbBitReader : BitReader
A type that contains functions for reading Data
bit-by-bit using “MSB0” bit numbering scheme and byte-by-byte in the
Little Endian order.
-
Size of the
data
(in bytes).Declaration
Swift
public let size: Int
-
Data which is being read.
Declaration
Swift
public let data: Data
-
Offset to a byte in the
data
which will be read next.Precondition
The reader must be aligned when accessing the setter ofoffset
.Declaration
Swift
public var offset: Int { get set }
-
True, if a bit pointer is aligned to a byte boundary.
Declaration
Swift
public var isAligned: Bool { get }
-
Amount of bits left to read.
Declaration
Swift
public var bitsLeft: Int { get }
-
Amount of bits that were already read.
Declaration
Swift
public var bitsRead: Int { get }
-
Creates an instance for reading bits (and bytes) from the
data
.Declaration
Swift
public init(data: Data)
-
Converts a
ByteReader
instance into aLsbBitReader
, enabling bit reading capabilities. The currentoffset
value of thebyteReader
is preserved.Declaration
Swift
public convenience init(_ byteReader: ByteReader)
-
Advances a bit pointer by the specified amount of bits (the default value is 1).
Warning
This function doesn’t check if there is any data left. It is advised to useisFinished
after calling this method to check if the end was reached.Declaration
Swift
public func advance(by count: Int = 1)
-
Reads a bit and returns it, advancing by one bit position.
Precondition
There must be enough data left.Declaration
Swift
public func bit() -> UInt8
-
Reads
count
bits and returns them as a[UInt8]
array, advancing bycount
bit positions.Precondition
Parametercount
must non-negativePrecondition
There must be enough data left.Declaration
Swift
public func bits(count: Int) -> [UInt8]
-
Reads
fromBits
bits, treating them as a binaryrepresenation
of a signed integer, and returns the result as aInt
number, advancing byfromBits
bit positions.If the
representation
doesn’t match the representation that was used to produce the data then the result may be incorrect.The default value of
representation
isSignedNumberRepresentation.twoComplementNegatives
.Precondition
ParameterfromBits
must be in the0...Int.bitWidth
range.Precondition
There must be enough data left.Declaration
Swift
public func signedInt(fromBits count: Int, representation: SignedNumberRepresentation = .twoComplementNegatives) -> Int
-
Reads
fromBits
bits and returns them as aUInt8
number, advancing byfromBits
bit positions.Precondition
ParameterfromBits
must be in the0...8
range.Precondition
There must be enough data left.Declaration
Swift
public func byte(fromBits count: Int) -> UInt8
-
Reads
fromBits
bits and returns them as aUInt16
number, advancing byfromBits
bit positions.Precondition
ParameterfromBits
must be in the0...16
range.Precondition
There must be enough data left.Declaration
Swift
public func uint16(fromBits count: Int) -> UInt16
-
Reads
fromBits
bits and returns them as aUInt32
number, advancing byfromBits
bit positions.Precondition
ParameterfromBits
must be in the0...32
range.Precondition
There must be enough data left.Declaration
Swift
public func uint32(fromBits count: Int) -> UInt32
-
Reads
fromBits
bits and returns them as aUInt64
number, advancing byfromBits
bit positions.Precondition
ParameterfromBits
must be from0...64
range.Precondition
There must be enough data left.Declaration
Swift
public 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. If the reader is already aligned, then does nothing.
Warning
This function doesn’t check if there is any data left. It is advised to useisFinished
after calling this method to check if the end was reached.Declaration
Swift
public func align()
-
Reads a byte and returns it, advancing by one byte position.
Precondition
The reader must be aligned.Precondition
There must be enough bytes left.Declaration
Swift
public func byte() -> UInt8
-
Reads
count
bytes and returns them as a[UInt8]
array, advancing bycount
byte positions.Precondition
The reader must be aligned.Precondition
Parametercount
must be non-negative.Precondition
There must be enough bytes left.Declaration
Swift
public func bytes(count: Int) -> [UInt8]
-
Reads 8 bytes and returns them as a
UInt64
number, advancing by 8 byte positions.Precondition
The reader must be aligned.Precondition
There must be enough bytes left.Declaration
Swift
public func uint64() -> UInt64
-
Reads
fromBytes
bytes and returns them as aUInt64
number, advancing byfromBytes
byte positions.Note
If it is known that thefromBytes
is exactly 8 then consider using theuint64()
function (without an argument), since it may provide better performance.Precondition
The reader must be aligned.Precondition
ParameterfromBytes
must be in the0...8
range.Precondition
There must be enough bytes left.Declaration
Swift
public func uint64(fromBytes count: Int) -> UInt64
-
Reads 4 bytes and returns them as a
UInt32
number, advancing by 4 byte positions.Precondition
The reader must be aligned.Precondition
There must be enough bytes left.Declaration
Swift
public func uint32() -> UInt32
-
Reads
fromBytes
bytes and returns them as aUInt32
number, advancing byfromBytes
byte positions.Note
If it is known that thefromBytes
is exactly 4 then consider using theuint32()
function (without an argument), since it may provide better performance.Precondition
The reader must be aligned.Precondition
ParameterfromBytes
must be in the0...4
range.Precondition
There must be enough bytes left.Declaration
Swift
public func uint32(fromBytes count: Int) -> UInt32
-
Reads 2 bytes and returns them as a
UInt16
number, advancing by 2 byte positions.Precondition
The reader must be aligned.Precondition
There must be enough data left.Declaration
Swift
public func uint16() -> UInt16
-
Reads
fromBytes
bytes and returns them as aUInt16
number, advancing byfromBytes
byte positions.Note
If it is known that thefromBytes
is exactly 2 then consider using theuint16()
function (without an argument), since it may provide better performance.Precondition
The reader must be aligned.Precondition
ParameterfromBytes
must be in the0...2
range.Precondition
There must be enough bytes left.Declaration
Swift
public func uint16(fromBytes count: Int) -> UInt16