/** Offset in bits in a BitStream. May be over 2^32, so avoid bitwise operations. */ export type BitAddress = number; /** * A stream where you can read and write arbitrary amounts of bits. * One can change the offset to seek specific locations. * Only supports signed integers up to 32 bits. Supports variable length integers. * It DOES NOT check for out of bounds reads or writes. * * It works using a 32bits buffer and when reading or writing two situations can happen: * * [+] ONLY LEFT BOUNDARY: the value being read is contained in the exact 32bits word * ``` * [00000000000000000000000000000000] [00000000000000000000000000000000] * ↑ offset ↑ offset + bits * | VALUE | * |------------| * |-- delta --|--- bits ---| * ``` * * [+] CROSS BOUNDARY: the value being read is divided between two 32bits words * ``` * |--------------------------------| |---------------------------------| * | value1 | | value2 | * ↓ aligned32 | ↓ aligned32 + 1 | * [00000000000000000000000000000000] [00000000000000000000000000000000] * ↑ offset ↑ offset + bits * | VALUE | * |--------------------------------| * |-- delta --|------------- bits -------------| * ``` * * `delta`, `bits`, `aligned32` and `offset` represent the variables in the code. */ export declare class BitStream { private buffer; /** Reading and writing "head", bytes will be read or written starting from this offset */ offset: BitAddress; constructor(buffer?: ArrayBuffer); /** * Returns the data buffer up to the current offset as an Uint8Array. * The buffer returned is aligned to 32bits, so it can be used to create another BitStream instance. */ get buffer8(): Readonly; /** * Grows the data buffer to allow new bits to be written. * Note that the buffer instance will change. */ private grow; /** Sets the value at the current offset using the specified number of bits */ setBits(bits: number, value: number): void; /** Reads the value at the current offset using the specified number of bits */ getBits(bits: number): number; /** * Writes a variable length integer, up to the specified number of bits. * Knowing the maximum number of bits lets us decide if we need to use a variable length encoding or if its worse. */ writeVarInt(value: number, maxBits?: number): void; /** Reads a variable length integer, up to the specified number of bits */ readVarInt(maxBits?: number): number; }