@eyhn/msgpack-stream
Version:
MessagePack for ECMA-262/JavaScript/TypeScript
38 lines • 2.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeStream = exports.decodeMulti = exports.decode = exports.defaultDecodeOptions = void 0;
const Decoder_1 = require("./Decoder");
const StreamDecoder_1 = require("./StreamDecoder");
exports.defaultDecodeOptions = {};
/**
* It decodes a single MessagePack object in a buffer.
*
* This is a synchronous decoding function.
* See other variants for asynchronous decoding: {@link decodeAsync()}, {@link decodeStream()}, or {@link decodeArrayStream()}.
*
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
function decode(buffer, options = exports.defaultDecodeOptions) {
const decoder = new Decoder_1.Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
return decoder.decode(buffer);
}
exports.decode = decode;
/**
* It decodes multiple MessagePack objects in a buffer.
* This is corresponding to {@link decodeMultiStream()}.
*
* @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
* @throws {@link DecodeError} if the buffer contains invalid data.
*/
function decodeMulti(buffer, options = exports.defaultDecodeOptions) {
const decoder = new Decoder_1.Decoder(options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
return decoder.decodeMulti(buffer);
}
exports.decodeMulti = decodeMulti;
function decodeStream(read, options = exports.defaultDecodeOptions) {
const decoder = new StreamDecoder_1.StreamDecoder(read, options.extensionCodec, options.context, options.maxStrLength, options.maxBinLength, options.maxArrayLength, options.maxMapLength, options.maxExtLength);
return decoder.decode();
}
exports.decodeStream = decodeStream;
//# sourceMappingURL=decode.js.map