UNPKG

cbor2

Version:

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC8949).

72 lines (69 loc) 2.32 kB
import { D as DecodeOptions, M as MtAiValue } from './options-B_2zDXXZ.js'; import './sorts.js'; /** * Decode CBOR bytes to a JS value. * * @param src CBOR bytes to decode. * @param options Options for decoding. * @returns JS value decoded from cbor. * @throws {Error} No value found, decoding errors. */ declare function decode<T = unknown>(src: Uint8Array | string, options?: DecodeOptions): T; /** * Decode the bytes of a CBOR Sequence to major-type/additional-information/ * value tuples. Each of these tuples is an event in parsing the sequence. * * Note that this includes items indicating the start of an array or map, and * the end of an indefinite-length item, and tag numbers separate from the * tag content. Does not guarantee that the input is valid. * * Will attempt to read all items in an array or map, even if indefinite. * Throws when there is insufficient data to do so. The same applies when * reading tagged items, byte strings and text strings. * * @see https://www.rfc-editor.org/rfc/rfc8742.html * @example * ```js * const s = new Sequence(buffer); * for (const [majorType, additionalInfo, value] of s.seq()) { * ... * } * ``` */ declare class SequenceEvents { #private; /** * Create an Event * @param src CBOR bytes to decode. * @param options Options for decoding. */ constructor(src: Uint8Array | string, options?: DecodeOptions); /** * Peek at the next tuple, allowing for later reads. * * @throws {Error} On insufficient data. */ peek(): MtAiValue | undefined; /** * Read the next tuple. * * @throws {Error} On insufficient data. */ read(): MtAiValue | undefined; /** * Iterate over all tuples. * * @throws {Error} On insufficient data. */ [Symbol.iterator](): Generator<MtAiValue, void, undefined>; } /** * Decode a CBOR Sequence consisting of multiple CBOR items. * * @param src CBOR bytes to decode. * @param options Options for decoding. * @yields JS value decoded from CBOR sequence. * @see https://www.rfc-editor.org/rfc/rfc8742.html */ declare function decodeSequence<T = unknown>(src: Uint8Array | string, options?: DecodeOptions): Generator<T, undefined, undefined>; export { SequenceEvents, decode, decodeSequence };