@surrealdb/cbor
Version:
CBOR encoder and decoder for SurrealDB.
136 lines (133 loc) • 3.68 kB
TypeScript
// Generated by dts-bundle-generator v9.5.1
export type Replacer = (v: any) => unknown;
export type Major = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
export declare const POW_2_53: number;
export declare const POW_2_64: bigint;
export type Fill<T = unknown> = [
Gap<T>,
T
];
export declare class Gap<T = unknown> {
readonly args: [
T?
];
constructor(...args: [
T?
]);
fill(value: T): Fill<T>;
hasDefault(): boolean;
get default(): T | undefined;
}
export declare class PartiallyEncoded {
readonly chunks: [
Uint8Array,
Gap
][];
readonly end: Uint8Array;
readonly replacer: Replacer | undefined;
constructor(chunks: [
Uint8Array,
Gap
][], end: Uint8Array, replacer: Replacer | undefined);
build(fills: Fill[], partial?: false): Uint8Array;
build(fills: Fill[], partial: true): PartiallyEncoded;
}
export declare function partiallyEncodeObject(object: Record<string, unknown>, options?: EncoderOptions<true>): Record<string, PartiallyEncoded>;
export declare class Writer {
readonly byteLength: number;
private _chunks;
private _pos;
private _buf;
private _view;
private _byte;
constructor(byteLength?: number);
chunk(gap: Gap): void;
get chunks(): [
Uint8Array,
Gap
][];
get buffer(): Uint8Array;
private claim;
writeUint8(value: number): void;
writeUint16(value: number): void;
writeUint32(value: number): void;
writeUint64(value: bigint): void;
writeFloat32(value: number): void;
writeFloat64(value: number): void;
writeUint8Array(data: Uint8Array): void;
writePartiallyEncoded(data: PartiallyEncoded): void;
writeMajor(type: Major, length: number | bigint): void;
output(partial?: false, replacer?: Replacer): Uint8Array;
output(partial: true, replacer?: Replacer): PartiallyEncoded;
}
export interface EncoderOptions<Partial extends boolean = boolean> {
replacer?: Replacer;
writer?: Writer;
partial?: Partial;
fills?: Fill[];
}
export declare function encode(input: unknown, options?: EncoderOptions<false>): Uint8Array;
export declare function encode(input: unknown, options?: EncoderOptions<true>): PartiallyEncoded;
export declare class Reader {
private _view;
private _byte;
private _pos;
constructor(buffer: Uint8Array);
skip(amount?: number): void;
peekUint8(): number;
readUint8(): number;
readUint16(): number;
readUint32(): number;
readUint64(): bigint;
readFloat16(): number;
readFloat32(): number;
readFloat64(): number;
readBytes(amount: number): Uint8Array;
readMajor(): [
Major,
number
];
readMajorLength(length: number): number | bigint;
}
export interface DecodeOptions {
map?: "object" | "map";
tagged?: Record<number, Replacer>;
}
export declare function decode(input: Uint8Array | Reader, options?: DecodeOptions): any;
export declare function infiniteBytes(r: Reader, forMajor: Major): ArrayBuffer;
export declare class Tagged<T = unknown> {
readonly tag: number | bigint;
readonly value: T;
constructor(tag: number | bigint, value: T);
}
export declare abstract class CborError {
abstract readonly name: string;
readonly message: string;
constructor(message: string);
}
export declare class CborNumberError extends CborError {
name: string;
}
export declare class CborRangeError extends CborError {
name: string;
}
export declare class CborInvalidMajorError extends CborError {
name: string;
}
export declare class CborBreak extends CborError {
name: string;
constructor();
}
export declare class CborPartialDisabled extends CborError {
name: string;
constructor();
}
export declare class CborFillMissing extends CborError {
name: string;
constructor();
}
export declare class Encoded {
readonly encoded: Uint8Array;
constructor(encoded: Uint8Array);
}
export {};