Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BitSource

This provides an easy abstraction to read bits at a time from a sequence of bytes, where the number of bits read is not often a multiple of 8.

This class is thread-safe but not reentrant -- unless the caller modifies the bytes array it passed in, in which case all bets are off.

author

Sean Owen

Hierarchy

  • BitSource

Index

Constructors

constructor

  • new BitSource(bytes: Uint8Array): BitSource
  • Parameters

    • bytes: Uint8Array

      bytes from which this will read bits. Bits will be read from the first byte first. Bits are read within a byte from most-significant to least-significant bit.

    Returns BitSource

Properties

Private bitOffset

bitOffset: number

Private byteOffset

byteOffset: number

Private bytes

bytes: Uint8Array

bytes from which this will read bits. Bits will be read from the first byte first. Bits are read within a byte from most-significant to least-significant bit.

Methods

available

  • available(): number

getBitOffset

  • getBitOffset(): number
  • Returns number

    index of next bit in current byte which would be read by the next call to {@link #readBits(int)}.

getByteOffset

  • getByteOffset(): number
  • Returns number

    index of next byte in input byte array which would be read by the next call to {@link #readBits(int)}.

readBits

  • readBits(numBits: number): number
  • throws

    IllegalArgumentException if numBits isn't in [1,32] or more than is available

    Parameters

    • numBits: number

      number of bits to read

    Returns number

    int representing the bits read. The bits will appear as the least-significant bits of the int

Generated using TypeDoc