UNPKG

@piltoverarchive/riftbound-deck-codes

Version:

Encode and decode Riftbound TCG decks to/from shareable strings

40 lines 1.4 kB
/** * VarintTranslator handles encoding and decoding of variable-length integers * used in the Riftbound deck code format. * * Variable-length integers use the most significant bit (MSB) as a continuation flag. * If MSB is 1, more bytes follow. If MSB is 0, this is the final byte. */ export default class VarintTranslator { private static readonly AllButMSB; private static readonly JustMSB; private bytes; constructor(_bytes: ArrayBuffer | Uint8Array); get length(): number; /** * Reads and removes a varint from the beginning of the byte array * @returns The decoded integer value * @throws Error if no bytes available or invalid varint format */ PopVarint(): number; /** * Slices the internal byte array * @param begin - Start index * @param end - Optional end index */ sliceAndSet(begin: number, end?: number): void; /** * Gets a byte at the specified index * @param index - Index to retrieve * @returns The byte value at the index * @throws Error if index is out of bounds */ get(index: number): number; /** * Converts a number into its varint byte representation * @param value - The number to encode * @returns Uint8Array containing the varint encoding */ static GetVarint(value: number): Uint8Array; } //# sourceMappingURL=VarintTranslator.d.ts.map