import { ExtensionCodecType } from "./ExtensionCodec"; import { Decoder } from "./Decoder"; import { ContextOf, SplitUndefined } from "./context"; export type DecodeOptions = Readonly< Partial<{ extensionCodec: ExtensionCodecType; /** * Maximum string length. * Default to 4_294_967_295 (UINT32_MAX). */ maxStrLength: number; /** * Maximum binary length. * Default to 4_294_967_295 (UINT32_MAX). */ maxBinLength: number; /** * Maximum array length. * Default to 4_294_967_295 (UINT32_MAX). */ maxArrayLength: number; /** * Maximum map length. * Default to 4_294_967_295 (UINT32_MAX). */ maxMapLength: number; /** * Maximum extension length. * Default to 4_294_967_295 (UINT32_MAX). */ maxExtLength: number; }> > & ContextOf; export const defaultDecodeOptions: DecodeOptions = {}; /** * It decodes a MessagePack-encoded buffer. * * This is a synchronous decoding function. See other variants for asynchronous decoding: `decodeAsync()`, `decodeStream()`, `decodeArrayStream()`. */ export function decode( buffer: ArrayLike | ArrayBuffer, options: DecodeOptions> = defaultDecodeOptions as any, ): unknown { const decoder = new Decoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength, ); return decoder.decode(buffer); }