UNPKG

@thi.ng/leb128

Version:

WASM based LEB128 encoder / decoder (signed & unsigned)

59 lines 2.03 kB
/** * Encodes signed integer `x` into LEB128 varint format and returns encoded * bytes. Values will be coerced to i64 range prior to encoding. * * @param x - */ export declare const encodeSLEB128: (x: bigint | number) => Uint8Array<ArrayBuffer>; /** * Takes an `Uint8Array` with LEB128 encoded signed varint and an optional start * index to decode from. Returns 2-tuple of decoded value and number of bytes * consumed. Consumes up to 10 bytes from `src`. * * @param src - * @param idx - */ export declare const decodeSLEB128: (src: Uint8Array, idx?: number) => [bigint, number]; /** * Takes a destination `Uint8Array`, a signed integer `x`, and an optional * index/position to encode an LEB128 formatted byte sequence into the * destination. Returns the number of bytes written. * * @remarks * Also see {@link encodeSLEB128}. * * @param dst - * @param x - * @param pos - */ export declare const encodeSLEB128Into: (dst: Uint8Array, x: bigint | number, pos?: number) => number; /** * Encodes unsigned integer `x` into LEB128 varint format and returns encoded * bytes. Values will be coerced to u64 range prior to encoding. * * @param x - */ export declare const encodeULEB128: (x: bigint | number) => Uint8Array<ArrayBuffer>; /** * Takes an `Uint8Array` with LEB128 encoded unsigned varint and an optional * start index to decode from. Returns 2-tuple of decoded value and number of * bytes consumed. Consumes up to 10 bytes from `src`. * * @param src - * @param idx - */ export declare const decodeULEB128: (src: Uint8Array, idx?: number) => [bigint, number]; /** * Takes a destination Uint8Array, an unsigned integer `x`, and an optional * position to encode an LEB128 formatted byte sequence into the destination. * Returns the number of bytes written. * * @remarks * Also see {@link encodeULEB128}. * * @param dst - * @param x - * @param pos - */ export declare const encodeULEB128Into: (dst: Uint8Array, x: bigint | number, pos?: number) => number; //# sourceMappingURL=index.d.ts.map