micro-packed
Version:
Define complex binary structures using composable primitives
64 lines • 2.73 kB
TypeScript
import { type Bytes, type CoderType, type TArg } from './index.ts';
/**
* Print an array of rows as a formatted terminal table.
* @param data - Rows to print.
* @throws If the table has no printable columns or rows. {@link Error}
* @example
* Print a quick table with auto-sized columns.
* ```ts
* import { table } from 'micro-packed/debugger.js';
* table([{ Name: 'field', Value: '01ff' }]);
* ```
*/
export declare function table(data: any[]): void;
/**
* Decode input while printing the partially decoded map when an error occurs.
* @param coder - Coder used for the decode step.
* @param data - Hex, base64, or raw bytes to decode.
* @param forcePrint - Print the decoded map even when decoding succeeds.
* @returns Decoded value produced by `coder`.
* @throws If decoding the input fails. {@link Error}
* @example
* Inspect a failing decode and print the consumed fields before rethrowing.
* ```ts
* import { U32LE } from 'micro-packed';
* import { decode } from 'micro-packed/debugger.js';
* decode(U32LE, Uint8Array.of(1, 0, 0, 0));
* ```
*/
export declare function decode(coder: CoderType<any>, data: TArg<string | Bytes>, forcePrint?: boolean): ReturnType<(typeof coder)['decode']>;
/**
* Print a field-by-field diff between two encoded payloads.
* @param coder - Coder used to decode both payloads before diffing.
* @param actual - Actual bytes or encoded string.
* @param expected - Expected bytes or encoded string.
* @param skipSame - Skip rows whose decoded values are identical.
* @throws If either payload cannot be decoded for diffing. {@link Error}
* @example
* Compare two encoded payloads field by field.
* ```ts
* import { U16BE, struct } from 'micro-packed';
* import { diff } from 'micro-packed/debugger.js';
* const coder = struct({ value: U16BE });
* diff(coder, Uint8Array.of(0, 1), Uint8Array.of(0, 2), false);
* ```
*/
export declare function diff(coder: CoderType<any>, actual: TArg<string | Bytes>, expected: TArg<string | Bytes>, skipSame?: boolean): void;
/**
* Wraps a CoderType with debug logging for encoding and decoding operations.
* @param inner - Inner CoderType to wrap.
* @returns Inner wrapped in debug prints via console.log.
* @throws If the inner coder is invalid. {@link Error}
* @example
* Print each encode/decode step while keeping the original coder API.
* ```ts
* import { U32LE } from 'micro-packed';
* import { debug } from 'micro-packed/debugger.js';
* const debugInt = debug(U32LE); // Will print info to console on encoding/decoding
* ```
*/
export declare function debug<T>(inner: CoderType<T>): CoderType<T>;
export declare const _TESTS: {
chrWidth: (s: string) => number;
};
//# sourceMappingURL=debugger.d.ts.map