Skip to main content

BitStringReader

The reader class. It is responsible for reading packed integers from a BitString.

Index

Constructors

constructor

Accessors

bitsAvailable

  • get bitsAvailable(): number

  • Returns number

    the amount of bits in total that can be read from the current reader, not including already read ones.

overflown

  • get overflown(): boolean

  • Returns boolean

    whether the current reader has any more data to read.

Methods

readBit

  • readBit(): 0 | 1
  • A helper function for efficient reading of a single bit.

    Behaves exactly like readUnsigned(1) but is more efficient.

    @throws

    if there is no more data available.


    Returns 0 | 1

    either 0 or 1.

readBool

  • readBool(): boolean
  • A helper function for efficient reading of a single bit.

    Behaves exactly like BitStringReader.readBit, but returns a boolean value instead of a number.

    @throws

    if there is no more data available.


    Returns boolean

readSigned

  • readSigned(bits: number): number
  • Reads a signed integer from the reader. Throws an Invalid argument error if there is not enough data left to read full bits bits.

    If bits is zero, returns 0 and does not change the state, even if BitStringReader.overflown is true.

    @throws

    if there is not enough bits to read, that is, if bits > BitStringReader.bitsAvailable.


    Parameters

    • bits: number

      a non-negative integer. The amount of bits to read.

    Returns number

    a signed integer. The read value.

readUnsigned

  • readUnsigned(bits: number): number
  • Reads an unsigned integer from the reader. Throws an Invalid argument error if there is not enough data left to read full bits bits.

    If bits is zero, returns 0 and does not change the state, even if BitStringReader.overflown is true.

    @throws

    if there is not enough bits to read, that is, if bits > BitStringReader.bitsAvailable.


    Parameters

    • bits: number

      a non-negative integer. The amount of bits to read.

    Returns number

    a non-negative integer. The read value.

tryReadBit

  • tryReadBit(): 0 | 1
  • A helper function for efficient reading of a single bit.

    Behaves exactly like tryReadUnsigned(1) but is more efficient.


    Returns 0 | 1

    either 0, 1, or undefined, the latter indicating there is no more data to read.

tryReadBool

  • tryReadBool(): boolean
  • A helper function for efficient reading of a single bit.

    Behaves exactly like BitStringReader.tryReadBit, but returns a boolean value instead of a number.


    Returns boolean

    either the value of the bit, or undefined if there is no more data to read.

tryReadSigned

  • tryReadSigned(bits: number): number
  • Reads a signed integer from the reader. Returns undefined if there is not enough data left to read full bits bits.

    If bits is zero, returns 0 and does not change the state, even if BitStringReader.overflown is true.


    Parameters

    • bits: number

      a non-negative integer. The amount of bits to read.

    Returns number

    a signed integer or undefined. The read value or undefined if there is not enough data left to read the full bits bits.

tryReadUnsigned

  • tryReadUnsigned(bits: number): number
  • Reads an unsigned integer from the reader. Returns undefined if there is not enough data left to read full bits bits.

    If bits is zero, returns 0 and does not change the state, even if BitStringReader.overflown is true.


    Parameters

    • bits: number

      a non-negative integer. The amount of bits to read.

    Returns number

    a non-negative integer or undefined. The read value or undefined if there is not enough data left to read the full bits bits.

staticfromBase64