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 a BitReader, enabling bits reading capabilities. The current offset value of the byteReader 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 by count bit positions.

    Declaration

    Swift

    func bits(count: Int) -> [UInt8]
  • int(fromBits:) Default implementation

    Reads fromBits bits and returns them as a Int number, advancing by fromBits bit positions.

    Default Implementation

    Reads fromBits bits by either using uint64(fromBits:) or uint32(fromBits:) depending on the platform’s integer bit width, converts the result to Int, and returns it, advancing by fromBits bit positions.

    Note

    If the data is supposed to represent a signed integer, it is recommended to use the signedInt(fromBits:representation:) function to get a correct result.

    Declaration

    Swift

    func int(fromBits count: Int) -> Int
  • Reads fromBits bits, treating them as a binary represenation of a signed integer, and returns the result as a Int number, advancing by fromBits bit positions.

    Declaration

    Swift

    func signedInt(fromBits count: Int, representation: SignedNumberRepresentation) -> Int
  • Reads fromBits bits and returns them as a UInt8 number, advancing by fromBits bit positions.

    Declaration

    Swift

    func byte(fromBits count: Int) -> UInt8
  • Reads fromBits bits and returns them as a UInt16 number, advancing by fromBits bit positions.

    Declaration

    Swift

    func uint16(fromBits count: Int) -> UInt16
  • Reads fromBits bits and returns them as a UInt32 number, advancing by fromBits bit positions.

    Declaration

    Swift

    func uint32(fromBits count: Int) -> UInt32
  • Reads fromBits bits and returns them as a UInt64 number, advancing by fromBits 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()