UNPKG

@cloudpss/ubjson

Version:

Opinionated UBJSON encoder/decoder for CloudPSS.

28 lines 815 B
import { readData, readMarkerOrUndefined } from '../helper/decode.js'; import { toUint8Array } from '../helper/utils.js'; import { UnexpectedEofError } from '../helper/errors.js'; /** decoder */ export class DecoderBase { options; constructor(data, options) { this.options = options; this.data = toUint8Array(data); this.view = new DataView(this.data.buffer, this.data.byteOffset, this.data.byteLength); } view; data; /** 当前读指针位置 */ offset = 0; /** EOF */ eof() { throw new UnexpectedEofError(); } /** 解码 */ decode() { const marker = readMarkerOrUndefined(this); if (marker === undefined) return undefined; return readData(this, marker); } } //# sourceMappingURL=decoder.js.map