/* tslint:disable */ /* eslint-disable */ /** * A successfully-decoded bijou128 value plus its byte length. * * Returned by [`decode`]. Exposes `value` (the decoded `u128`, JS * `bigint`) and `bytesRead` (a JS `number`) as getters. We model this * as a Rust-exported struct rather than constructing a plain JS * object via [`js_sys::Object`] because the struct gives us a real * TypeScript type on the JS side at zero extra runtime cost. */ export class Decoded { private constructor(); free(): void; [Symbol.dispose](): void; /** * Number of bytes consumed from the input slice (1..=17). */ readonly bytesRead: number; /** * The decoded value. */ readonly value: bigint; } /** * Maximum number of bytes a `bijou128` encoding can occupy. * * Exposed as a JS function rather than a `const` because `wasm-bindgen` * does not generate JS bindings for top-level `const` items; calling the * function once and caching is cheap. */ export function MAX_BYTES(): number; /** * Decodes a `bijou128` from the front of `bytes`. * * Returns a [`WasmDecoded`] carrying the value plus the * number of bytes consumed (so the caller can stream-decode by * slicing). * * # Errors * * Throws a JS native `TypeError` if `bytes` is not a `Uint8Array`. * Throws a JS `Error` with `name === "Bijou128DecodeError"` if `bytes` * is too short for the encoding indicated by its tag byte, or if a * tier-16 payload would overflow `u128`. See [`WasmDecodeError`]. * * # JS * * ```js * import { decode } from "bijou128"; * const { value, bytesRead } = decode(new Uint8Array([0xF1, 0x00, 0x04, 0xFF])); * // value === 500n, bytesRead === 3 * decode([0xF1, 0x00, 0x04]); // throws TypeError (plain Array, not Uint8Array) * ``` */ export function decode(bytes: Uint8Array): Decoded; /** * Decodes every `bijou128`-encoded value in `bytes`, returning them as * a JS `Array`. * * Unlike `bijou64_wasm::decodeAll` (which returns a `BigUint64Array`), * there is no `BigUint128Array` in the web platform. Returning * `js_sys::Array` of `bigint`s is the natural mapping for `Vec` — * it preserves the full 128-bit range with zero precision loss at the * cost of one allocation per element on the JS side. * * Equivalent to calling [`decode`] in a loop, advancing by * `bytesRead` after each call until the buffer is empty. * * # Errors * * Throws a JS native `TypeError` if `bytes` is not a `Uint8Array`. * Throws a JS `Error` with `name === "Bijou128DecodeError"` (same * shape as [`decode`]) if any element fails to decode. The * partial-prefix decoded so far is *not* returned — the operation * is all-or-nothing. * * # JS * * ```js * import { encode, decodeAll } from "bijou128"; * const buf = new Uint8Array([...encode(42n), ...encode(500n), ...encode(65535n)]); * const values = decodeAll(buf); * // values is [42n, 500n, 65535n] * ``` */ export function decodeAll(bytes: Uint8Array): Array; /** * Encodes `value` as a fresh `Uint8Array` (1..=17 bytes). * * The Rust side allocates a `Vec` and `wasm-bindgen` copies it into * a JS-managed `Uint8Array` on the way out. This matches the natural * shape of a JS API; if you need an in-place encode into an existing * buffer, use the Rust crate directly. * * # Errors * * Throws a JS native [`TypeError`](js_sys::TypeError) if `value` is * not a `bigint`, or a JS native [`RangeError`](js_sys::RangeError) * if `value` is outside `[0n, 2n ** 128n)`. See [`WasmBigintError`]. * * # JS * * ```js * import { encode } from "bijou128"; * encode(42n); // Uint8Array([0x2A]) * encode(500n); // Uint8Array([0xF1, 0x00, 0x04]) * encode(1n << 128n); // throws RangeError * encode(-1n); // throws RangeError * encode(42); // throws TypeError (Number, not bigint) * ``` */ export function encode(value: bigint): Uint8Array; /** * Returns the encoded length of `value` in bytes (1..=17). * * # Errors * * Throws a JS native [`TypeError`](js_sys::TypeError) if `value` is * not a `bigint`, or a JS native [`RangeError`](js_sys::RangeError) * if `value` is outside `[0n, 2n ** 128n)`. See [`WasmBigintError`]. * * # JS * * ```js * import { encodedLen } from "bijou128"; * encodedLen(0n); // 1 * encodedLen(239n); // 1 * encodedLen(240n); // 2 * encodedLen((1n << 128n) - 1n); // 17 (u128::MAX) * encodedLen(1n << 128n); // throws RangeError * encodedLen(-1n); // throws RangeError * encodedLen(42); // throws TypeError (Number, not bigint) * ``` */ export function encodedLen(value: bigint): number;