BitStringReader
Index
Constructors
constructor
Initialize the reader with a string obtained from calling BitStringWriter.toBitString or similar methods.
Parameters
bitString: string
the input BitString.
Returns BitStringReader
Accessors
bitsAvailable
Returns number
the amount of bits in total that can be read from the current reader, not including already read ones.
overflown
Returns boolean
whether the current reader has any more data to read.
Methods
readBit
A helper function for efficient reading of a single bit.
Behaves exactly like
readUnsigned(1)but is more efficient.Returns 0 | 1
either
0or1.
readBool
A helper function for efficient reading of a single bit.
Behaves exactly like BitStringReader.readBit, but returns a boolean value instead of a number.
Returns boolean
readSigned
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
0and 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. The read value.
readUnsigned
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
0and 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. The read value.
tryReadBit
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, orundefined, the latter indicating there is no more data to read.
tryReadBool
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
undefinedif there is no more data to read.
tryReadSigned
Reads a signed integer from the reader. Returns
undefinedif there is not enough data left to read full bits bits.If bits is zero, returns
0and 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 orundefinedif there is not enough data left to read the full bits bits.
tryReadUnsigned
Reads an unsigned integer from the reader. Returns
undefinedif there is not enough data left to read full bits bits.If bits is zero, returns
0and 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 orundefinedif there is not enough data left to read the full bits bits.
staticfromBase64
Create a new BitStringReader instance from a base64-encoded string obtained from a call to BitStringWriter.toBase64.
Parameters
b64String: string
Returns BitStringReader
The reader class. It is responsible for reading packed integers from a BitString.