Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a-msgpack

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-msgpack - npm Package Compare versions

Comparing version 0.1.42 to 0.3.4

dist/MsgPack.js

177

CHANGELOG.md

@@ -6,2 +6,179 @@ # Change Log

## [0.3.4](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.3.3...a-msgpack@0.3.4) (2019-11-19)
**Note:** Version bump only for package a-msgpack
## [0.3.3](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.3.2...a-msgpack@0.3.3) (2019-10-21)
**Note:** Version bump only for package a-msgpack
## [0.3.2](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.3.1...a-msgpack@0.3.2) (2019-10-14)
**Note:** Version bump only for package a-msgpack
## [0.3.1](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.3.0...a-msgpack@0.3.1) (2019-10-07)
### Bug Fixes
* **a-msgpack:** package proper files ([e68ab76](http://gerrit.corp.arista.io:29418/web-components/commits/e68ab76))
# [0.3.0](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.8...a-msgpack@0.3.0) (2019-10-04)
### Features
* **a-msgpack, cloudvision-connector:** Move to Typescript ([acf4e70](http://gerrit.corp.arista.io:29418/web-components/commits/acf4e70))
## [0.2.8](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.7...a-msgpack@0.2.8) (2019-09-23)
**Note:** Version bump only for package a-msgpack
## [0.2.7](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.6...a-msgpack@0.2.7) (2019-09-17)
**Note:** Version bump only for package a-msgpack
## [0.2.6](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.5...a-msgpack@0.2.6) (2019-09-16)
**Note:** Version bump only for package a-msgpack
## [0.2.5](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.3...a-msgpack@0.2.5) (2019-09-14)
**Note:** Version bump only for package a-msgpack
## [0.2.4](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.3...a-msgpack@0.2.4) (2019-09-10)
**Note:** Version bump only for package a-msgpack
## [0.2.3](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.2...a-msgpack@0.2.3) (2019-08-30)
**Note:** Version bump only for package a-msgpack
## [0.2.2](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.1...a-msgpack@0.2.2) (2019-08-29)
**Note:** Version bump only for package a-msgpack
## [0.2.1](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.2.0...a-msgpack@0.2.1) (2019-08-26)
**Note:** Version bump only for package a-msgpack
# [0.2.0](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.49...a-msgpack@0.2.0) (2019-08-19)
### Features
* **connector:** improve type checking for multithreaded use ([5d13917](http://gerrit.corp.arista.io:29418/web-components/commits/5d13917))
## [0.1.49](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.48...a-msgpack@0.1.49) (2019-08-14)
**Note:** Version bump only for package a-msgpack
## [0.1.48](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.47...a-msgpack@0.1.48) (2019-08-13)
**Note:** Version bump only for package a-msgpack
## [0.1.47](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.46...a-msgpack@0.1.47) (2019-08-12)
**Note:** Version bump only for package a-msgpack
## [0.1.46](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.45...a-msgpack@0.1.46) (2019-07-26)
**Note:** Version bump only for package a-msgpack
## [0.1.45](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.44...a-msgpack@0.1.45) (2019-07-26)
**Note:** Version bump only for package a-msgpack
## [0.1.44](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.43...a-msgpack@0.1.44) (2019-07-25)
**Note:** Version bump only for package a-msgpack
## [0.1.43](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.42...a-msgpack@0.1.43) (2019-07-16)
**Note:** Version bump only for package a-msgpack
## [0.1.42](http://gerrit.corp.arista.io:29418/web-components/compare/a-msgpack@0.1.41...a-msgpack@0.1.42) (2019-07-16)

@@ -8,0 +185,0 @@

1867

lib/MsgPack.js

@@ -7,554 +7,249 @@ 'use strict';

var Int64 = _interopDefault(require('int64-buffer'));
var JSBI = _interopDefault(require('jsbi'));
const decoder = new TextDecoder();
const encoder = new TextEncoder();
var ExtensionBuffer = /** @class */ (function () {
function ExtensionBuffer(buffer, etype) {
this.buffer = buffer;
this.etype = etype;
}
return ExtensionBuffer;
}());
// The given argument must be an array of Uint8Arrays.
var decoder = new TextDecoder();
var encoder = new TextEncoder();
/**
* Concatenates multiple buffers into one.
*
* @param buffers Array of buffers to concat
*/
function concat(buffers) {
const bufferCount = buffers.length;
let totalLength = 0;
for (let i = 0; i < bufferCount; ++i) {
totalLength += buffers[i].byteLength;
}
const output = new Uint8Array(totalLength);
let offset = 0;
for (let i = 0; i < bufferCount; ++i) {
const buffer = buffers[i];
output.set(buffer, offset);
offset += buffer.byteLength;
}
return output;
var bufferCount = buffers.length;
var totalLength = 0;
for (var i = 0; i < bufferCount; ++i) {
totalLength += buffers[i].byteLength;
}
var output = new Uint8Array(totalLength);
var offset = 0;
for (var i = 0; i < bufferCount; ++i) {
var buffer = buffers[i];
output.set(buffer, offset);
offset += buffer.byteLength;
}
return output;
}
// The first argument must be a Uint8Array.
// Start and end indices will be clamped to the range of the given Uint8Array.
/**
* Clamps the given Uint8Array to the given start and end indies.
*
* @param buffer Uint8 buffer
* @param start Start index for new buffer
* @param end End Index for new buffer
*
* @returns The clamped buffer as a new Uint8Array
*/
function subarray(buffer, start, end) {
const newStart = Math.min(Math.max(0, start), buffer.byteLength);
return new Uint8Array(
buffer.buffer,
buffer.byteOffset + newStart,
Math.min(Math.max(newStart, end), buffer.byteLength) - newStart,
);
var newStart = Math.min(Math.max(0, start), buffer.byteLength);
return new Uint8Array(buffer.buffer, buffer.byteOffset + newStart, Math.min(Math.max(newStart, end), buffer.byteLength) - newStart);
}
/**
* Returns the stringified version of what is represended by the data in the buffer,
* clamped by the start and end index.
*
* @param buffer Uint8 buffer
* @param start Start index
* @param end End index
*/
function toString(buffer, start, end) {
return decoder.decode(subarray(buffer, start, end));
return decoder.decode(subarray(buffer, start, end));
}
/**
* Returns the passed data represendted by a Uint8Buffer
*
* @param string
*/
function fromString(string) {
return encoder.encode(string);
return encoder.encode(string);
}
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var int64Buffer = createCommonjsModule(function (module, exports) {
// int64-buffer.js
/*jshint -W018 */ // Confusing use of '!'.
/*jshint -W030 */ // Expected an assignment or function call and instead saw an expression.
/*jshint -W093 */ // Did you mean to return a conditional instead of an assignment?
var Uint64BE, Int64BE, Uint64LE, Int64LE;
!function(exports) {
// constants
var UNDEFINED = "undefined";
var BUFFER = (UNDEFINED !== typeof Buffer) && Buffer;
var UINT8ARRAY = (UNDEFINED !== typeof Uint8Array) && Uint8Array;
var ARRAYBUFFER = (UNDEFINED !== typeof ArrayBuffer) && ArrayBuffer;
var ZERO = [0, 0, 0, 0, 0, 0, 0, 0];
var isArray = Array.isArray || _isArray;
var BIT32 = 4294967296;
var BIT24 = 16777216;
// storage class
var storage; // Array;
// generate classes
Uint64BE = factory("Uint64BE", true, true);
Int64BE = factory("Int64BE", true, false);
Uint64LE = factory("Uint64LE", false, true);
Int64LE = factory("Int64LE", false, false);
// class factory
function factory(name, bigendian, unsigned) {
var posH = bigendian ? 0 : 4;
var posL = bigendian ? 4 : 0;
var pos0 = bigendian ? 0 : 3;
var pos1 = bigendian ? 1 : 2;
var pos2 = bigendian ? 2 : 1;
var pos3 = bigendian ? 3 : 0;
var fromPositive = bigendian ? fromPositiveBE : fromPositiveLE;
var fromNegative = bigendian ? fromNegativeBE : fromNegativeLE;
var proto = Int64.prototype;
var isName = "is" + name;
var _isInt64 = "_" + isName;
// properties
proto.buffer = void 0;
proto.offset = 0;
proto[_isInt64] = true;
// methods
proto.toNumber = toNumber;
proto.toString = toString;
proto.toJSON = toNumber;
proto.toArray = toArray;
// add .toBuffer() method only when Buffer available
if (BUFFER) proto.toBuffer = toBuffer;
// add .toArrayBuffer() method only when Uint8Array available
if (UINT8ARRAY) proto.toArrayBuffer = toArrayBuffer;
// isUint64BE, isInt64BE
Int64[isName] = isInt64;
// CommonJS
exports[name] = Int64;
return Int64;
// constructor
function Int64(buffer, offset, value, raddix) {
if (!(this instanceof Int64)) return new Int64(buffer, offset, value, raddix);
return init(this, buffer, offset, value, raddix);
}
// isUint64BE, isInt64BE
function isInt64(b) {
return !!(b && b[_isInt64]);
}
// initializer
function init(that, buffer, offset, value, raddix) {
if (UINT8ARRAY && ARRAYBUFFER) {
if (buffer instanceof ARRAYBUFFER) buffer = new UINT8ARRAY(buffer);
if (value instanceof ARRAYBUFFER) value = new UINT8ARRAY(value);
}
// Int64BE() style
if (!buffer && !offset && !value && !storage) {
// shortcut to initialize with zero
that.buffer = newArray(ZERO, 0);
return;
}
// Int64BE(value, raddix) style
if (!isValidBuffer(buffer, offset)) {
var _storage = storage || Array;
raddix = offset;
value = buffer;
offset = 0;
buffer = new _storage(8);
}
that.buffer = buffer;
that.offset = offset |= 0;
// Int64BE(buffer, offset) style
if (UNDEFINED === typeof value) return;
// Int64BE(buffer, offset, value, raddix) style
if ("string" === typeof value) {
fromString(buffer, offset, value, raddix || 10);
} else if (isValidBuffer(value, raddix)) {
fromArray(buffer, offset, value, raddix);
} else if ("number" === typeof raddix) {
writeInt32(buffer, offset + posH, value); // high
writeInt32(buffer, offset + posL, raddix); // low
} else if (value > 0) {
fromPositive(buffer, offset, value); // positive
} else if (value < 0) {
fromNegative(buffer, offset, value); // negative
} else {
fromArray(buffer, offset, ZERO, 0); // zero, NaN and others
}
}
function fromString(buffer, offset, str, raddix) {
var pos = 0;
var len = str.length;
var high = 0;
var low = 0;
if (str[0] === "-") pos++;
var sign = pos;
while (pos < len) {
var chr = parseInt(str[pos++], raddix);
if (!(chr >= 0)) break; // NaN
low = low * raddix + chr;
high = high * raddix + Math.floor(low / BIT32);
low %= BIT32;
}
if (sign) {
high = ~high;
if (low) {
low = BIT32 - low;
} else {
high++;
function map(decoder, len, decode) {
var value = {};
for (var i = 0; i < len; ++i) {
var key = decode(decoder);
var stringKey = 'undefined';
if (typeof key === 'string') {
stringKey = key;
}
}
writeInt32(buffer, offset + posH, high);
writeInt32(buffer, offset + posL, low);
else if (key === null) {
stringKey = 'null';
}
else {
stringKey = JSON.stringify(key);
}
value[stringKey] = decode(decoder);
}
function toNumber() {
var buffer = this.buffer;
var offset = this.offset;
var high = readInt32(buffer, offset + posH);
var low = readInt32(buffer, offset + posL);
if (!unsigned) high |= 0; // a trick to get signed
return high ? (high * BIT32 + low) : low;
return value;
}
function array(decoder, len, decode) {
var value = new Array(len);
for (var i = 0; i < len; ++i) {
value[i] = decode(decoder);
}
function toString(radix) {
var buffer = this.buffer;
var offset = this.offset;
var high = readInt32(buffer, offset + posH);
var low = readInt32(buffer, offset + posL);
var str = "";
var sign = !unsigned && (high & 0x80000000);
if (sign) {
high = ~high;
low = BIT32 - low;
}
radix = radix || 10;
while (1) {
var mod = (high % radix) * BIT32 + low;
high = Math.floor(high / radix);
low = Math.floor(mod / radix);
str = (mod % radix).toString(radix) + str;
if (!high && !low) break;
}
if (sign) {
str = "-" + str;
}
return str;
}
function writeInt32(buffer, offset, value) {
buffer[offset + pos3] = value & 255;
value = value >> 8;
buffer[offset + pos2] = value & 255;
value = value >> 8;
buffer[offset + pos1] = value & 255;
value = value >> 8;
buffer[offset + pos0] = value & 255;
}
function readInt32(buffer, offset) {
return (buffer[offset + pos0] * BIT24) +
(buffer[offset + pos1] << 16) +
(buffer[offset + pos2] << 8) +
buffer[offset + pos3];
}
}
function toArray(raw) {
var buffer = this.buffer;
var offset = this.offset;
storage = null; // Array
if (raw !== false && isArray(buffer)) {
return (buffer.length === 8) ? buffer : buffer.slice(offset, offset + 8);
}
return newArray(buffer, offset);
}
function toBuffer(raw) {
var buffer = this.buffer;
var offset = this.offset;
storage = BUFFER;
if (raw !== false && BUFFER.isBuffer(buffer)) {
return (buffer.length === 8) ? buffer : buffer.slice(offset, offset + 8);
}
// Buffer.from(arraybuffer) available since Node v4.5.0
// https://nodejs.org/en/blog/release/v4.5.0/
return BUFFER.from(toArrayBuffer.call(this, raw));
}
function toArrayBuffer(raw) {
var buffer = this.buffer;
var offset = this.offset;
var arrbuf = buffer.buffer;
storage = UINT8ARRAY;
// arrbuf.slice() ignores buffer.offset until Node v8.0.0
if (raw !== false && !buffer.offset && (arrbuf instanceof ARRAYBUFFER)) {
return (arrbuf.byteLength === 8) ? arrbuf : arrbuf.slice(offset, offset + 8);
}
var dest = new UINT8ARRAY(8);
fromArray(dest, 0, buffer, offset);
return dest.buffer;
}
function isValidBuffer(buffer, offset) {
var len = buffer && buffer.length;
offset |= 0;
return len && (offset + 8 <= len) && ("string" !== typeof buffer[offset]);
}
function fromArray(destbuf, destoff, srcbuf, srcoff) {
destoff |= 0;
srcoff |= 0;
for (var i = 0; i < 8; i++) {
destbuf[destoff++] = srcbuf[srcoff++] & 255;
}
}
function newArray(buffer, offset) {
return Array.prototype.slice.call(buffer, offset, offset + 8);
}
function fromPositiveBE(buffer, offset, value) {
var pos = offset + 8;
while (pos > offset) {
buffer[--pos] = value & 255;
value /= 256;
}
}
function fromNegativeBE(buffer, offset, value) {
var pos = offset + 8;
value++;
while (pos > offset) {
buffer[--pos] = ((-value) & 255) ^ 255;
value /= 256;
}
}
function fromPositiveLE(buffer, offset, value) {
var end = offset + 8;
while (offset < end) {
buffer[offset++] = value & 255;
value /= 256;
}
}
function fromNegativeLE(buffer, offset, value) {
var end = offset + 8;
value++;
while (offset < end) {
buffer[offset++] = ((-value) & 255) ^ 255;
value /= 256;
}
}
// https://github.com/retrofox/is-array
function _isArray(val) {
return !!val && "[object Array]" == Object.prototype.toString.call(val);
}
}(typeof exports.nodeName !== 'string' ? exports : (commonjsGlobal || {}));
});
function map(decode, decoder, len) {
const value = {};
for (let i = 0; i < len; ++i) {
value[decode(decoder)] = decode(decoder);
}
return value;
return value;
}
function array(decode, decoder, len) {
const value = new Array(len);
for (let i = 0; i < len; ++i) {
value[i] = decode(decoder);
}
return value;
}
function str(decoder, len) {
const start = decoder.offset;
decoder.offset = start + len;
if (decoder.offset > decoder.buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return toString(decoder.buffer, start, decoder.offset);
var start = decoder.offset;
decoder.offset = start + len;
if (decoder.offset > decoder.buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return toString(decoder.buffer, start, decoder.offset);
}
function bin(decoder, len) {
const start = decoder.offset;
decoder.offset = start + len;
if (decoder.offset > decoder.buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return subarray(decoder.buffer, start, decoder.offset);
var start = decoder.offset;
decoder.offset = start + len;
if (decoder.offset > decoder.buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return subarray(decoder.buffer, start, decoder.offset);
}
function ext(decoder, len) {
const start = decoder.offset;
decoder.offset = start + len + 1;
if (decoder.offset > decoder.buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
const etype = decoder.buffer[start];
if (decoder.codec) {
const unpacker = decoder.codec._unpackerFor(etype); // eslint-disable-line no-underscore-dangle
if (unpacker) {
return unpacker(subarray(decoder.buffer, start + 1, decoder.offset));
var start = decoder.offset;
decoder.offset = start + len + 1;
if (decoder.offset > decoder.buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
}
throw new Error('Unrecognized extension type: ' + (etype ? '0x' + etype.toString(16) : etype));
var etype = decoder.buffer[start];
if (decoder.codec) {
var unpacker = decoder.codec.unpackerFor(etype); // eslint-disable-line no-underscore-dangle
if (unpacker) {
return unpacker(subarray(decoder.buffer, start + 1, decoder.offset));
}
}
throw new Error('Unrecognized extension type: ' + (etype ? '0x' + etype.toString(16) : etype));
}
function uint8(decoder) {
const buffer = decoder.buffer;
if (decoder.offset >= buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return buffer[decoder.offset++];
var buffer = decoder.buffer;
if (decoder.offset >= buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return buffer[decoder.offset++];
}
function uint16(decoder) {
const buffer = decoder.buffer;
if (decoder.offset + 2 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return (buffer[decoder.offset++] << 8) | buffer[decoder.offset++];
var buffer = decoder.buffer;
if (decoder.offset + 2 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return (buffer[decoder.offset++] << 8) | buffer[decoder.offset++];
}
function uint32(decoder) {
const buffer = decoder.buffer;
if (decoder.offset + 4 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return (
buffer[decoder.offset++] * 0x1000000 +
((buffer[decoder.offset++] << 16) | (buffer[decoder.offset++] << 8) | buffer[decoder.offset++])
);
var buffer = decoder.buffer;
if (decoder.offset + 4 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return (buffer[decoder.offset++] * 0x1000000 +
((buffer[decoder.offset++] << 16) | (buffer[decoder.offset++] << 8) | buffer[decoder.offset++]));
}
function uint64(decoder) {
const offset = decoder.offset;
const buffer = decoder.buffer;
if (decoder.offset + 8 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
decoder.offset += 8;
if (decoder.useJSBI) {
const strValue = new int64Buffer.Uint64BE(buffer.buffer, buffer.byteOffset + offset).toString();
return JSBI.BigInt(strValue);
}
return new DataView(buffer.buffer).getBigUint64(buffer.byteOffset + offset);
var offset = decoder.offset;
var buffer = decoder.buffer;
if (decoder.offset + 8 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
decoder.offset += 8;
if (decoder.useJSBI) {
var strValue = new Int64.Uint64BE(buffer.buffer, buffer.byteOffset + offset).toString();
return JSBI.BigInt(strValue);
}
return new DataView(buffer.buffer).getBigUint64(buffer.byteOffset + offset);
}
function int8(decoder) {
const val = uint8(decoder);
return !(val & 0x80) ? val : (0xff - val + 1) * -1;
var val = uint8(decoder);
return !(val & 0x80) ? val : (0xff - val + 1) * -1;
}
function int16(decoder) {
const val = uint16(decoder);
return val & 0x8000 ? val | 0xffff0000 : val;
var val = uint16(decoder);
return val & 0x8000 ? val | 0xffff0000 : val;
}
function int32(decoder) {
const buffer = decoder.buffer;
if (decoder.offset + 4 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return (
(buffer[decoder.offset++] << 24) |
(buffer[decoder.offset++] << 16) |
(buffer[decoder.offset++] << 8) |
buffer[decoder.offset++]
);
var buffer = decoder.buffer;
if (decoder.offset + 4 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
return ((buffer[decoder.offset++] << 24) |
(buffer[decoder.offset++] << 16) |
(buffer[decoder.offset++] << 8) |
buffer[decoder.offset++]);
}
function int64(decoder) {
const offset = decoder.offset;
const buffer = decoder.buffer;
if (decoder.offset + 8 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
decoder.offset += 8;
if (decoder.useJSBI) {
const strValue = new int64Buffer.Int64BE(buffer.buffer, buffer.byteOffset + offset).toString();
return JSBI.BigInt(strValue);
}
return new DataView(buffer.buffer).getBigInt64(buffer.byteOffset + offset);
var offset = decoder.offset;
var buffer = decoder.buffer;
if (decoder.offset + 8 > buffer.byteLength) {
throw new RangeError('BUFFER_SHORTAGE');
}
decoder.offset += 8;
if (decoder.useJSBI) {
var strValue = new Int64.Int64BE(buffer.buffer, buffer.byteOffset + offset).toString();
return JSBI.BigInt(strValue);
}
return new DataView(buffer.buffer).getBigInt64(buffer.byteOffset + offset);
}
function float32(decoder) {
const buffer = decoder.buffer;
const offset = decoder.offset;
decoder.offset += 4;
return new DataView(buffer.buffer).getFloat32(buffer.byteOffset + offset);
var buffer = decoder.buffer;
var offset = decoder.offset;
decoder.offset += 4;
return new DataView(buffer.buffer).getFloat32(buffer.byteOffset + offset);
}
function float64(decoder) {
const buffer = decoder.buffer;
const offset = decoder.offset;
decoder.offset += 8;
return new DataView(buffer.buffer).getFloat64(buffer.byteOffset + offset);
var buffer = decoder.buffer;
var offset = decoder.offset;
decoder.offset += 8;
return new DataView(buffer.buffer).getFloat64(buffer.byteOffset + offset);
}
var ReadFormat = {
map,
array,
str,
bin,
ext,
uint8,
uint16,
uint32,
uint64,
int8,
int16,
int32,
int64,
float32,
float64,
map: map,
array: array,
str: str,
bin: bin,
ext: ext,
uint8: uint8,
uint16: uint16,
uint32: uint32,
uint64: uint64,
int8: int8,
int16: int16,
int32: int32,
int64: int64,
float32: float32,
float64: float64,
};
const readUint8 = ReadFormat.uint8;
var readUint8 = ReadFormat.uint8;
function decode(decoder) {
const type = readUint8(decoder);
const func = decoder.codec.readToken[type];
if (!func) {
throw new Error('Invalid type: 0x' + type.toString(16));
}
return func(decoder);
var type = readUint8(decoder);
var func = decoder.codec.readers[type];
if (!func) {
throw new Error('Invalid type: 0x' + type.toString(16));
}
return func(decoder);
}
function encode(encoder, value) {
encoder.codec.writeType[typeof value](encoder, value);
}
// Creates a readToken function that returns a constant value.
function constant(value) {
return () => {
return value;
};
return function () {
return value;
};
}
// Transforms the given method to always receive a second argument, which is
// a number constant.
function fix(len, method) {
return (decoder) => {
return method(decoder, len);
};
return function (decoder) {
return method(decoder, len);
};
}
// Transforms the given method to always receive a second argument, which is
// a number returned by lenFunc when given a Paper.
function flex(lenFunc, method) {
return (decoder) => {
return method(decoder, lenFunc(decoder));
};
return function (decoder) {
return method(decoder, lenFunc(decoder));
};
}

@@ -564,650 +259,664 @@

// interpretation of the bytes at the given Paper's offset.
function generateDefaultReadToken(decode) {
const readToken = new Array(256);
const curriedMap = (...m) => ReadFormat.map(decode, ...m);
const curriedArray = (...m) => ReadFormat.array(decode, ...m);
let i;
// positive fixint -- 0x00 - 0x7f
for (i = 0x00; i <= 0x7f; ++i) {
var readToken = new Array(256);
var curriedMap = function (decoder, len) {
return ReadFormat.map(decoder, len, decode);
};
var curriedArray = function (decoder, len) {
return ReadFormat.array(decoder, len, decode);
};
var i;
// positive fixint -- 0x00 - 0x7f
for (i = 0x00; i <= 0x7f; ++i) {
readToken[i] = constant(i);
}
// fixstr -- 0xa0 - 0xbf
for (i = 0xa0; i <= 0xbf; ++i) {
}
// fixstr -- 0xa0 - 0xbf
for (i = 0xa0; i <= 0xbf; ++i) {
readToken[i] = fix(i - 0xa0, ReadFormat.str);
}
// nil -- 0xc0
readToken[0xc0] = constant(null);
// (never used) -- 0xc1
readToken[0xc1] = null;
// false -- 0xc2
// true -- 0xc3
readToken[0xc2] = constant(false);
readToken[0xc3] = constant(true);
// bin 8 -- 0xc4
// bin 16 -- 0xc5
// bin 32 -- 0xc6
readToken[0xc4] = flex(ReadFormat.uint8, ReadFormat.bin);
readToken[0xc5] = flex(ReadFormat.uint16, ReadFormat.bin);
readToken[0xc6] = flex(ReadFormat.uint32, ReadFormat.bin);
// ext 8 -- 0xc7
// ext 16 -- 0xc8
// ext 32 -- 0xc9
readToken[0xc7] = flex(ReadFormat.uint8, ReadFormat.ext);
readToken[0xc8] = flex(ReadFormat.uint16, ReadFormat.ext);
readToken[0xc9] = flex(ReadFormat.uint32, ReadFormat.ext);
// float 32 -- 0xca
// float 64 -- 0xcb
readToken[0xca] = ReadFormat.float32;
readToken[0xcb] = ReadFormat.float64;
// uint 8 -- 0xcc
// uint 16 -- 0xcd
// uint 32 -- 0xce
// uint 64 -- 0xcf
readToken[0xcc] = ReadFormat.uint8;
readToken[0xcd] = ReadFormat.uint16;
readToken[0xce] = ReadFormat.uint32;
readToken[0xcf] = ReadFormat.uint64;
// int 8 -- 0xd0
// int 16 -- 0xd1
// int 32 -- 0xd2
// int 64 -- 0xd3
readToken[0xd0] = ReadFormat.int8;
readToken[0xd1] = ReadFormat.int16;
readToken[0xd2] = ReadFormat.int32;
readToken[0xd3] = ReadFormat.int64;
// fixext 1 -- 0xd4
// fixext 2 -- 0xd5
// fixext 4 -- 0xd6
// fixext 8 -- 0xd7
// fixext 16 -- 0xd8
readToken[0xd4] = fix(1, ReadFormat.ext);
readToken[0xd5] = fix(2, ReadFormat.ext);
readToken[0xd6] = fix(4, ReadFormat.ext);
readToken[0xd7] = fix(8, ReadFormat.ext);
readToken[0xd8] = fix(16, ReadFormat.ext);
// str 8 -- 0xd9
// str 16 -- 0xda
// str 32 -- 0xdb
readToken[0xd9] = flex(ReadFormat.uint8, ReadFormat.str);
readToken[0xda] = flex(ReadFormat.uint16, ReadFormat.str);
readToken[0xdb] = flex(ReadFormat.uint32, ReadFormat.str);
// negative fixint -- 0xe0 - 0xff
for (i = 0xe0; i <= 0xff; ++i) {
}
// nil -- 0xc0
readToken[0xc0] = constant(null);
// (never used) -- 0xc1
readToken[0xc1] = null;
// false -- 0xc2
// true -- 0xc3
readToken[0xc2] = constant(false);
readToken[0xc3] = constant(true);
// bin 8 -- 0xc4
// bin 16 -- 0xc5
// bin 32 -- 0xc6
readToken[0xc4] = flex(ReadFormat.uint8, ReadFormat.bin);
readToken[0xc5] = flex(ReadFormat.uint16, ReadFormat.bin);
readToken[0xc6] = flex(ReadFormat.uint32, ReadFormat.bin);
// ext 8 -- 0xc7
// ext 16 -- 0xc8
// ext 32 -- 0xc9
readToken[0xc7] = flex(ReadFormat.uint8, ReadFormat.ext);
readToken[0xc8] = flex(ReadFormat.uint16, ReadFormat.ext);
readToken[0xc9] = flex(ReadFormat.uint32, ReadFormat.ext);
// float 32 -- 0xca
// float 64 -- 0xcb
readToken[0xca] = ReadFormat.float32;
readToken[0xcb] = ReadFormat.float64;
// uint 8 -- 0xcc
// uint 16 -- 0xcd
// uint 32 -- 0xce
// uint 64 -- 0xcf
readToken[0xcc] = ReadFormat.uint8;
readToken[0xcd] = ReadFormat.uint16;
readToken[0xce] = ReadFormat.uint32;
readToken[0xcf] = ReadFormat.uint64;
// int 8 -- 0xd0
// int 16 -- 0xd1
// int 32 -- 0xd2
// int 64 -- 0xd3
readToken[0xd0] = ReadFormat.int8;
readToken[0xd1] = ReadFormat.int16;
readToken[0xd2] = ReadFormat.int32;
readToken[0xd3] = ReadFormat.int64;
// fixext 1 -- 0xd4
// fixext 2 -- 0xd5
// fixext 4 -- 0xd6
// fixext 8 -- 0xd7
// fixext 16 -- 0xd8
readToken[0xd4] = fix(1, ReadFormat.ext);
readToken[0xd5] = fix(2, ReadFormat.ext);
readToken[0xd6] = fix(4, ReadFormat.ext);
readToken[0xd7] = fix(8, ReadFormat.ext);
readToken[0xd8] = fix(16, ReadFormat.ext);
// str 8 -- 0xd9
// str 16 -- 0xda
// str 32 -- 0xdb
readToken[0xd9] = flex(ReadFormat.uint8, ReadFormat.str);
readToken[0xda] = flex(ReadFormat.uint16, ReadFormat.str);
readToken[0xdb] = flex(ReadFormat.uint32, ReadFormat.str);
// negative fixint -- 0xe0 - 0xff
for (i = 0xe0; i <= 0xff; ++i) {
readToken[i] = constant(i - 0x100);
}
// fixmap -- 0x80 - 0x8f
for (i = 0x80; i <= 0x8f; ++i) {
}
// fixmap -- 0x80 - 0x8f
for (i = 0x80; i <= 0x8f; ++i) {
readToken[i] = fix(i - 0x80, curriedMap);
}
// fixarray -- 0x90 - 0x9f
for (i = 0x90; i <= 0x9f; ++i) {
}
// fixarray -- 0x90 - 0x9f
for (i = 0x90; i <= 0x9f; ++i) {
readToken[i] = fix(i - 0x90, curriedArray);
}
}
// array 16 -- 0xdc
// array 32 -- 0xdd
readToken[0xdc] = flex(ReadFormat.uint16, curriedArray);
readToken[0xdd] = flex(ReadFormat.uint32, curriedArray);
// map 16 -- 0xde
// map 32 -- 0xdf
readToken[0xde] = flex(ReadFormat.uint16, curriedMap);
readToken[0xdf] = flex(ReadFormat.uint32, curriedMap);
var DefaultReadToken = Object.freeze(readToken);
// array 16 -- 0xdc
// array 32 -- 0xdd
readToken[0xdc] = flex(ReadFormat.uint16, curriedArray);
readToken[0xdd] = flex(ReadFormat.uint32, curriedArray);
(function (WriterTypes) {
WriterTypes["array"] = "array";
WriterTypes["bigint"] = "bigint";
WriterTypes["bin"] = "bin";
WriterTypes["boolean"] = "boolean";
WriterTypes["int"] = "int";
WriterTypes["map"] = "map";
WriterTypes["number"] = "number";
WriterTypes["object"] = "object";
WriterTypes["string"] = "string";
WriterTypes["jsBi"] = "jsBi";
WriterTypes["function"] = "function";
WriterTypes["null"] = "null";
WriterTypes["symbol"] = "symbol";
WriterTypes["undefined"] = "undefined";
})(exports.WriterTypes || (exports.WriterTypes = {}));
(function (MsgPackHeaderTypes) {
MsgPackHeaderTypes["type"] = "type";
MsgPackHeaderTypes["int8"] = "int8";
MsgPackHeaderTypes["int16"] = "int16";
MsgPackHeaderTypes["int32"] = "int32";
MsgPackHeaderTypes["int64"] = "int64";
MsgPackHeaderTypes["float32"] = "float32";
MsgPackHeaderTypes["float64"] = "float64";
})(exports.MsgPackHeaderTypes || (exports.MsgPackHeaderTypes = {}));
(function (Types) {
Types["array"] = "array";
Types["bigint"] = "bigint";
Types["bin"] = "bin";
Types["boolean"] = "boolean";
Types["ext"] = "ext";
Types["int"] = "int";
Types["jsBi"] = "jsBi";
Types["map"] = "map";
Types["nil"] = "nil";
Types["number"] = "number";
Types["object"] = "object";
Types["string"] = "string";
})(exports.Types || (exports.Types = {}));
(function (ReaderTypes) {
ReaderTypes["map"] = "map";
ReaderTypes["array"] = "array";
ReaderTypes["str"] = "str";
ReaderTypes["bin"] = "bin";
ReaderTypes["ext"] = "ext";
ReaderTypes["uint8"] = "uint8";
ReaderTypes["uint16"] = "uint16";
ReaderTypes["uint32"] = "uint32";
ReaderTypes["uint64"] = "uint64";
ReaderTypes["int8"] = "int8";
ReaderTypes["int16"] = "int16";
ReaderTypes["int32"] = "int32";
ReaderTypes["int64"] = "int64";
ReaderTypes["float32"] = "float32";
ReaderTypes["float64"] = "float64";
})(exports.ReaderTypes || (exports.ReaderTypes = {}));
// map 16 -- 0xde
// map 32 -- 0xdf
readToken[0xde] = flex(ReadFormat.uint16, curriedMap);
readToken[0xdf] = flex(ReadFormat.uint32, curriedMap);
function encode(encoder, value) {
var writer = encoder.codec.writers[typeof value];
if (typeof writer === 'function') {
writer(encoder, value);
}
}
return readToken;
// Check that a value looks like a JSBI value--that is, it's an object, it has __clzmsd
function isJsbi(value) {
return Array.isArray(value) && '__clzmsd' in value;
}
function getPacker(constructor, classes, packers) {
for (var i = 0, len = classes.length; i < len; ++i) {
if (constructor === classes[i]) {
return packers[i];
}
}
return null;
}
function type(encoder, encodingType) {
encoder.reserve(1);
encoder.buffer[encoder.offset++] = encodingType;
encoder.reserve(1);
encoder.buffer[encoder.offset++] = encodingType;
}
function int8$1(encoder, encodingType, value) {
encoder.reserve(2);
const buffer = encoder.buffer;
buffer[encoder.offset++] = encodingType;
buffer[encoder.offset++] = value;
encoder.reserve(2);
var buffer = encoder.buffer;
buffer[encoder.offset++] = encodingType;
buffer[encoder.offset++] = value;
}
function int16$1(encoder, encodingType, value) {
encoder.reserve(3);
const buffer = encoder.buffer;
buffer[encoder.offset++] = encodingType;
buffer[encoder.offset++] = value >>> 8;
buffer[encoder.offset++] = value;
encoder.reserve(3);
var buffer = encoder.buffer;
buffer[encoder.offset++] = encodingType;
buffer[encoder.offset++] = value >>> 8;
buffer[encoder.offset++] = value;
}
function int32$1(encoder, encodingType, value) {
encoder.reserve(5);
const buffer = encoder.buffer;
buffer[encoder.offset++] = encodingType;
buffer[encoder.offset++] = value >>> 24;
buffer[encoder.offset++] = value >>> 16;
buffer[encoder.offset++] = value >>> 8;
buffer[encoder.offset++] = value;
encoder.reserve(5);
var buffer = encoder.buffer;
buffer[encoder.offset++] = encodingType;
buffer[encoder.offset++] = value >>> 24;
buffer[encoder.offset++] = value >>> 16;
buffer[encoder.offset++] = value >>> 8;
buffer[encoder.offset++] = value;
}
function int64$1(encoder, encodingType) {
encoder.reserve(8);
encoder.buffer[encoder.offset++] = encodingType;
encoder.reserve(8);
encoder.buffer[encoder.offset++] = encodingType;
}
function float32$1(encoder, value) {
encoder.reserve(5);
const buffer = encoder.buffer;
buffer[encoder.offset++] = 0xca;
new DataView(buffer.buffer).setFloat32(buffer.byteOffset + encoder.offset, value);
encoder.offset += 4;
encoder.reserve(5);
var buffer = encoder.buffer;
buffer[encoder.offset++] = 0xca;
new DataView(buffer.buffer).setFloat32(buffer.byteOffset + encoder.offset, value);
encoder.offset += 4;
}
function float64$1(encoder, value) {
encoder.reserve(9);
const buffer = encoder.buffer;
buffer[encoder.offset++] = 0xcb;
new DataView(buffer.buffer).setFloat64(buffer.byteOffset + encoder.offset, value);
encoder.offset += 8;
encoder.reserve(9);
var buffer = encoder.buffer;
buffer[encoder.offset++] = 0xcb;
new DataView(buffer.buffer).setFloat64(buffer.byteOffset + encoder.offset, value);
encoder.offset += 8;
}
var writeHeader = {
type,
int8: int8$1,
int16: int16$1,
int32: int32$1,
int64: int64$1,
float32: float32$1,
float64: float64$1,
var headers = {
type: type,
int8: int8$1,
int16: int16$1,
int32: int32$1,
int64: int64$1,
float32: float32$1,
float64: float64$1,
};
// Fills the writeType hash with functions that each encode values of their
// Fills the writeType hash with functions that each encode values of the: voidir
// respective types at the given Paper's offset.
function int(encoder, value) {
const uivalue = value >>> 0;
if (value === uivalue) {
// positive fixint -- 0x00 - 0x7f
// uint 8 -- 0xcc
// uint 16 -- 0xcd
// uint 32 -- 0xce
if (uivalue <= 0x7f) {
writeHeader.type(encoder, uivalue);
} else if (uivalue <= 0xff) {
writeHeader.int8(encoder, 0xcc, uivalue);
} else if (uivalue <= 0xffff) {
writeHeader.int16(encoder, 0xcd, uivalue);
} else {
writeHeader.int32(encoder, 0xce, uivalue);
var uivalue = value >>> 0;
if (value === uivalue) {
// positive fixint -- 0x00 - 0x7f
// uint 8 -- 0xcc
// uint 16 -- 0xcd
// uint 32 -- 0xce
if (uivalue <= 0x7f) {
headers.type(encoder, uivalue);
}
else if (uivalue <= 0xff) {
headers.int8(encoder, 0xcc, uivalue);
}
else if (uivalue <= 0xffff) {
headers.int16(encoder, 0xcd, uivalue);
}
else {
headers.int32(encoder, 0xce, uivalue);
}
}
} else {
const ivalue = value | 0;
// negative fixint -- 0xe0 - 0xff
// int 8 -- 0xd0
// int 16 -- 0xd1
// int 32 -- 0xd2
if (ivalue >= -0x20) {
writeHeader.type(encoder, ivalue & 0xff);
} else if (ivalue >= -0x80) {
writeHeader.int8(encoder, 0xd0, ivalue);
} else if (ivalue >= -0x8000) {
writeHeader.int16(encoder, 0xd1, ivalue);
} else {
writeHeader.int32(encoder, 0xd2, ivalue);
else {
var ivalue = value | 0;
// negative fixint -- 0xe0 - 0xff
// int 8 -- 0xd0
// int 16 -- 0xd1
// int 32 -- 0xd2
if (ivalue >= -0x20) {
headers.type(encoder, ivalue & 0xff);
}
else if (ivalue >= -0x80) {
headers.int8(encoder, 0xd0, ivalue);
}
else if (ivalue >= -0x8000) {
headers.int16(encoder, 0xd1, ivalue);
}
else {
headers.int32(encoder, 0xd2, ivalue);
}
}
}
}
function number(encoder, value) {
const uivalue = value >>> 0;
const ivalue = value | 0;
if (value === uivalue || value === ivalue) {
// int
int(encoder, value);
} else {
writeHeader.float64(encoder, value); // float 64 -- 0xcb
}
var uivalue = value >>> 0;
var ivalue = value | 0;
if (value === uivalue || value === ivalue) {
// int
int(encoder, value);
}
else {
headers.float64(encoder, value); // float 64 -- 0xcb
}
}
function string(encoder, value) {
const utf8 = fromString(value);
const byteLength = utf8.byteLength;
// fixstr -- 0xa0 - 0xbf
// str 8 -- 0xd9
// str 16 -- 0xda
// str 32 -- 0xdb
if (byteLength < 32) {
writeHeader.type(encoder, 0xa0 + byteLength);
} else if (byteLength <= 0xff) {
writeHeader.int8(encoder, 0xd9, byteLength);
} else if (byteLength <= 0xffff) {
writeHeader.int16(encoder, 0xda, byteLength);
} else {
writeHeader.int32(encoder, 0xdb, byteLength);
}
encoder.send(utf8);
var utf8 = fromString(value);
var byteLength = utf8.byteLength;
// fixstr -- 0xa0 - 0xbf
// str 8 -- 0xd9
// str 16 -- 0xda
// str 32 -- 0xdb
if (byteLength < 32) {
headers.type(encoder, 0xa0 + byteLength);
}
else if (byteLength <= 0xff) {
headers.int8(encoder, 0xd9, byteLength);
}
else if (byteLength <= 0xffff) {
headers.int16(encoder, 0xda, byteLength);
}
else {
headers.int32(encoder, 0xdb, byteLength);
}
encoder.send(utf8);
}
function boolean(encoder, value) {
// false -- 0xc2
// true -- 0xc3
writeHeader.type(encoder, value ? 0xc3 : 0xc2);
// false -- 0xc2
// true -- 0xc3
headers.type(encoder, value ? 0xc3 : 0xc2);
}
function nil(encoder) {
// nil -- 0xc0
writeHeader.type(encoder, 0xc0);
// nil -- 0xc0
headers.type(encoder, 0xc0);
}
function bin$1(encoder, value) {
const byteLength = value.byteLength;
// bin 8 -- 0xc4
// bin 16 -- 0xc5
// bin 32 -- 0xc6
if (byteLength <= 0xff) {
writeHeader.int8(encoder, 0xc4, byteLength);
} else if (byteLength <= 0xffff) {
writeHeader.int16(encoder, 0xc5, byteLength);
} else {
writeHeader.int32(encoder, 0xc6, byteLength);
}
encoder.send(value);
var byteLength = value.byteLength;
// bin 8 -- 0xc4
// bin 16 -- 0xc5
// bin 32 -- 0xc6
if (byteLength <= 0xff) {
headers.int8(encoder, 0xc4, byteLength);
}
else if (byteLength <= 0xffff) {
headers.int16(encoder, 0xc5, byteLength);
}
else {
headers.int32(encoder, 0xc6, byteLength);
}
encoder.send(value);
}
function ext$1(encoder, value) {
const byteLength = value.buffer.byteLength;
// fixext 1 -- 0xd4
// fixext 2 -- 0xd5
// fixext 4 -- 0xd6
// fixext 8 -- 0xd7
// fixext 16 -- 0xd8
// ext 8 -- 0xc7
// ext 16 -- 0xc8
// ext 32 -- 0xc9
if (byteLength === 1) {
writeHeader.int8(encoder, 0xd4, value.etype);
} else if (byteLength === 2) {
writeHeader.int8(encoder, 0xd5, value.etype);
} else if (byteLength === 4) {
writeHeader.int8(encoder, 0xd6, value.etype);
} else if (byteLength === 8) {
writeHeader.int8(encoder, 0xd7, value.etype);
} else if (byteLength === 16) {
writeHeader.int8(encoder, 0xd8, value.etype);
} else if (byteLength <= 0xff) {
writeHeader.int8(encoder, 0xc7, byteLength);
writeHeader.type(encoder, value.etype);
} else if (byteLength <= 0xffff) {
writeHeader.int16(encoder, 0xc8, byteLength);
writeHeader.type(encoder, value.etype);
} else {
writeHeader.int32(encoder, 0xc9, byteLength);
writeHeader.type(encoder, value.etype);
}
encoder.send(value.buffer);
var byteLength = value.buffer.byteLength;
// fixext 1 -- 0xd4
// fixext 2 -- 0xd5
// fixext 4 -- 0xd6
// fixext 8 -- 0xd7
// fixext 16 -- 0xd8
// ext 8 -- 0xc7
// ext 16 -- 0xc8
// ext 32 -- 0xc9
if (byteLength === 1) {
headers.int8(encoder, 0xd4, value.etype);
}
else if (byteLength === 2) {
headers.int8(encoder, 0xd5, value.etype);
}
else if (byteLength === 4) {
headers.int8(encoder, 0xd6, value.etype);
}
else if (byteLength === 8) {
headers.int8(encoder, 0xd7, value.etype);
}
else if (byteLength === 16) {
headers.int8(encoder, 0xd8, value.etype);
}
else if (byteLength <= 0xff) {
headers.int8(encoder, 0xc7, byteLength);
headers.type(encoder, value.etype);
}
else if (byteLength <= 0xffff) {
headers.int16(encoder, 0xc8, byteLength);
headers.type(encoder, value.etype);
}
else {
headers.int32(encoder, 0xc9, byteLength);
headers.type(encoder, value.etype);
}
encoder.send(value.buffer);
}
function array$1(encode, encoder, value) {
const length = value.length;
// fixarray -- 0x90 - 0x9f
// array 16 -- 0xdc
// array 32 -- 0xdd
if (length < 16) {
writeHeader.type(encoder, 0x90 + length);
} else if (length <= 0xffff) {
writeHeader.int16(encoder, 0xdc, length);
} else {
writeHeader.int32(encoder, 0xdd, length);
}
for (let i = 0; i < length; ++i) {
encode(encoder, value[i]);
}
function array$1(encoder, value, encode) {
var length = value.length;
// fixarray -- 0x90 - 0x9f
// array 16 -- 0xdc
// array 32 -- 0xdd
if (length < 16) {
headers.type(encoder, 0x90 + length);
}
else if (length <= 0xffff) {
headers.int16(encoder, 0xdc, length);
}
else {
headers.int32(encoder, 0xdd, length);
}
for (var i = 0; i < length; ++i) {
encode(encoder, value[i]);
}
}
function map$1(encode, encoder, value) {
const keys = Object.keys(value);
const length = keys.length;
// fixmap -- 0x80 - 0x8f
// map 16 -- 0xde
// map 32 -- 0xdf
if (length < 16) {
writeHeader.type(encoder, 0x80 + length);
} else if (length <= 0xffff) {
writeHeader.int16(encoder, 0xde, length);
} else {
writeHeader.int32(encoder, 0xdf, length);
}
for (let i = 0; i < length; ++i) {
const key = keys[i];
encode(encoder, key);
encode(encoder, value[key]);
}
function map$1(encoder, value, encode) {
var keys = Object.keys(value);
var length = keys.length;
// fixmap -- 0x80 - 0x8f
// map 16 -- 0xde
// map 32 -- 0xdf
if (length < 16) {
headers.type(encoder, 0x80 + length);
}
else if (length <= 0xffff) {
headers.int16(encoder, 0xde, length);
}
else {
headers.int32(encoder, 0xdf, length);
}
for (var _i = 0, _a = Object.entries(value); _i < _a.length; _i++) {
var _b = _a[_i], k = _b[0], v = _b[1];
encode(encoder, k);
encode(encoder, v);
}
}
function jsBi(encode, encoder, value) {
// uint 64 -- 0xcf
// int 64 -- 0xd3
const strValue = value.toString();
if (
strValue === '0' ||
(JSBI.LE(value, 0x7fffffff) && JSBI.GE(value, -0xffffffff)) ||
(strValue < '0' && JSBI.GE(value, -0xffffffff))
) {
encode(encoder, parseInt(value, 10));
} else if (strValue < '0') {
writeHeader.int64(encoder, 0xd3);
const arrayValue = new int64Buffer.Int64BE(strValue);
encoder.send(new Uint8Array(arrayValue.toArray()));
} else {
writeHeader.int64(encoder, 0xcf);
const arrayValue = new int64Buffer.Uint64BE(strValue);
encoder.send(new Uint8Array(arrayValue.toArray()));
}
function jsBi(encoder, value, encode) {
// uint 64 -- 0xcf
// int 64 -- 0xd3
var strValue = value.toString();
if (strValue === '0' ||
(JSBI.LE(value, 0x7fffffff) && JSBI.GE(value, -0xffffffff)) ||
(strValue < '0' && JSBI.GE(value, -0xffffffff))) {
encode(encoder, Number(value));
}
else if (strValue < '0') {
headers.int64(encoder, 0xd3);
var arrayValue = new Int64.Int64BE(strValue);
encoder.send(new Uint8Array(arrayValue.toArray()));
}
else {
headers.int64(encoder, 0xcf);
var arrayValue = new Int64.Uint64BE(strValue);
encoder.send(new Uint8Array(arrayValue.toArray()));
}
}
function object(encode, writeType, encoder, value) {
if (value === null) {
return nil(encoder);
}
if (Array.isArray(value)) {
// int 64 as JSBI.BigInt (JSBI is an array internally)
if (value instanceof JSBI) {
return jsBi(encode, encoder, value);
function object(encoder, value, encode) {
if (value === null) {
return nil(encoder);
}
return array$1(encode, encoder, value);
}
if (value instanceof Uint8Array) {
return bin$1(encoder, value);
}
if (encoder.codec) {
const packer = encoder.codec._packerFor(value); // eslint-disable-line no-underscore-dangle
if (packer) {
return ext$1(encoder, packer(value));
if (Array.isArray(value)) {
// int 64 as JSBI.BigInt (JSBI is an array internally)
if (isJsbi(value)) {
return jsBi(encoder, value, encode);
}
return array$1(encoder, value, encode);
}
}
// float 32 -- 0xca
if (value instanceof Float32Array) {
return writeHeader.float32(encoder, value.value);
}
return writeType.map(encoder, value);
if (value instanceof Uint8Array) {
return bin$1(encoder, value);
}
if (encoder.codec) {
var packer = encoder.codec.packerFor(value); // eslint-disable-line no-underscore-dangle
if (packer) {
return ext$1(encoder, packer(value));
}
}
// float 32 -- 0xca
if (value instanceof Float32Array) {
return headers.float32(encoder, parseFloat(value.toString()));
}
return encoder.codec.writers.map(encoder, value);
}
function bigint(encode, encoder, value) {
// uint 64 -- 0xcf
// int 64 -- 0xd3
if (
value === BigInt(0) ||
BigInt.asIntN(32, value) > 0 ||
(value < 0 && BigInt.asUintN(32, value) === value * BigInt(-1))
) {
encode(encoder, parseInt(value, 10));
} else if (value < 0) {
writeHeader.int64(encoder, 0xd3);
const arrayValue = new DataView(new ArrayBuffer(8));
arrayValue.setBigInt64(0, value);
encoder.send(new Uint8Array(arrayValue.buffer));
} else {
writeHeader.int64(encoder, 0xcf);
const arrayValue = new DataView(new ArrayBuffer(8));
arrayValue.setBigUint64(0, value);
encoder.send(new Uint8Array(arrayValue.buffer));
}
function bigint(encoder, value, encode) {
// uint 64 -- 0xcf
// int 64 -- 0xd3
if (value === BigInt(0) ||
BigInt.asIntN(32, value) > 0 ||
(value < 0 && BigInt.asUintN(32, value) === value * BigInt(-1))) {
encode(encoder, Number(value));
}
else if (value < 0) {
headers.int64(encoder, 0xd3);
var arrayValue = new DataView(new ArrayBuffer(8));
arrayValue.setBigInt64(0, value);
encoder.send(new Uint8Array(arrayValue.buffer));
}
else {
headers.int64(encoder, 0xcf);
var arrayValue = new DataView(new ArrayBuffer(8));
arrayValue.setBigUint64(0, value);
encoder.send(new Uint8Array(arrayValue.buffer));
}
}
var writeFormat = {
array: array$1,
bigint,
bin: bin$1,
boolean,
ext: ext$1,
int,
jsBi,
map: map$1,
nil,
number,
object,
string,
var WriteFormat = {
array: array$1,
bigint: bigint,
bin: bin$1,
boolean: boolean,
ext: ext$1,
int: int,
jsBi: jsBi,
map: map$1,
nil: nil,
number: number,
object: object,
string: string,
};
function generateDefaultWriteType(encode) {
const writeType = {};
var _a;
var writeType = Object.freeze((_a = {},
_a[exports.WriterTypes.bin] = WriteFormat.bin,
_a[exports.WriterTypes.boolean] = WriteFormat.boolean,
_a[exports.WriterTypes.function] = WriteFormat.nil,
_a[exports.WriterTypes.int] = WriteFormat.int,
_a[exports.WriterTypes.null] = WriteFormat.nil,
_a[exports.WriterTypes.number] = WriteFormat.number,
_a[exports.WriterTypes.string] = WriteFormat.string,
_a[exports.WriterTypes.symbol] = WriteFormat.nil,
_a[exports.WriterTypes.undefined] = WriteFormat.nil,
_a[exports.WriterTypes.jsBi] = function (encoder, value) {
return WriteFormat.jsBi(encoder, value, encode);
},
_a[exports.WriterTypes.array] = function (encoder, value) {
return WriteFormat.array(encoder, value, encode);
},
_a[exports.WriterTypes.bigint] = function (encoder, value) {
return WriteFormat.bigint(encoder, value, encode);
},
_a[exports.WriterTypes.map] = function (encoder, value) {
return WriteFormat.map(encoder, value, encode);
},
_a[exports.WriterTypes.object] = function (encoder, value) {
return WriteFormat.object(encoder, value, encode);
},
_a));
writeType.bin = writeFormat.bin;
writeType.boolean = writeFormat.boolean;
writeType.function = writeFormat.nil;
writeType.int = writeFormat.int;
writeType.null = writeFormat.nil;
writeType.number = writeFormat.number;
writeType.string = writeFormat.string;
writeType.symbol = writeFormat.nil;
writeType.undefined = writeFormat.nil;
writeType.jsBi = writeFormat.jsBi;
writeType.array = (...m) => writeFormat.array(encode, ...m);
writeType.bigint = (...m) => writeFormat.bigint(encode, ...m);
writeType.map = (...m) => writeFormat.map(encode, ...m);
writeType.object = (...m) => writeFormat.object(encode, writeType, ...m);
return writeType;
}
// This is isolated for optimization purposes.
function getPacker(constructor, classes, packers) {
for (let i = 0, len = classes.length; i < len; ++i) {
if (constructor === classes[i]) {
return packers[i];
/* eslint-disable no-dupe-class-members */
var Codec = /** @class */ (function () {
function Codec() {
this.packers = [];
this.packerClasses = [];
this.unpackers = new Map();
this.writers = writeType;
this.readers = DefaultReadToken;
}
}
Codec.prototype.setWriters = function (writers) {
this.writers = writers;
};
Codec.prototype.setReaders = function (readers) {
this.readers = readers;
};
Codec.prototype.register = function (etype, Class, packer, unpacker) {
if (~~etype !== etype || !(etype >= 0 && etype < 128)) {
throw new TypeError('Invalid extension type (must be between 0 and 127).');
}
this.packers.push(function (value) { return new ExtensionBuffer(packer(value), etype); });
this.packerClasses.push(Class);
this.unpackers.set(etype, unpacker);
return this;
};
Codec.prototype.packerFor = function (value) {
return getPacker(value.constructor, this.packerClasses, this.packers);
};
Codec.prototype.unpackerFor = function (etype) {
return this.unpackers.get(etype) || null;
};
return Codec;
}());
return null;
}
function join(filters) {
const slicedFilters = filters.slice();
const iterator = function iterator(value, filter) {
return filter(value);
};
return (value) => {
return slicedFilters.reduce(iterator, value);
};
}
const ExtensionBuffer = function ExtensionBuffer(buffer, etype) {
this.buffer = buffer;
this.etype = etype;
};
function Codec() {
if (!(this instanceof Codec)) {
throw new TypeError('Codecs must be constructed with the "new" keyword.');
}
this._packers = [];
this._packerClasses = [];
this._unpackers = {};
this.writeType = generateDefaultWriteType(encode);
this.readToken = generateDefaultReadToken(decode);
}
Codec.prototype.replaceWriteType = function replaceWriteType(type, func, includeEncode = false) {
this.writeType[type] = includeEncode ? (...m) => func(encode, ...m) : func;
};
Codec.prototype.replaceReadToken = function replaceReadToken(
token,
creator,
len,
func,
includeDecode = false,
) {
this.readToken[token] = includeDecode
? creator(len, (...m) => func(decode, ...m))
: creator(len, func);
};
Codec.prototype.register = function register(etype, Class, packer, unpacker) {
if (Array.isArray(packer)) {
packer = join(packer); // eslint-disable-line no-param-reassign
}
if (Array.isArray(unpacker)) {
unpacker = join(unpacker); // eslint-disable-line no-param-reassign
}
if (~~etype !== etype || !(etype >= 0 && etype < 128)) {
throw new TypeError('Invalid extension type (must be between 0 and 127).');
}
if (typeof Class !== 'function') {
throw new TypeError('Expected second argument to be a constructor function.');
}
this._packers.push((value) => {
const buffer = packer(value);
if (!(buffer instanceof Uint8Array)) {
throw new TypeError('Codec must return a Uint8Array (encoding "' + Class.name + '").');
var MIN_BUFFER_SIZE = 2048;
var MAX_BUFFER_SIZE = 65536;
var Paper = /** @class */ (function () {
function Paper(codec, useJSBI) {
if (useJSBI === void 0) { useJSBI = false; }
this.codec = codec;
this.useJSBI = useJSBI;
this.buffer = new Uint8Array();
this.buffers = [this.buffer];
this.offset = 0;
this.start = 0;
}
return new ExtensionBuffer(buffer, etype);
});
this._packerClasses.push(Class);
this._unpackers[etype] = unpacker;
return this;
};
Codec.prototype._packerFor = function _packerFor(value) {
return getPacker(value.constructor, this._packerClasses, this._packers);
};
Codec.prototype._unpackerFor = function _unpackerFor(etype) {
return this._unpackers[etype];
};
Paper.prototype.push = function (chunk) {
this.buffers.push(chunk);
};
Paper.prototype.read = function () {
this.flush();
var chunk = this.buffers.length > 1 ? concat(this.buffers) : this.buffers[0];
this.buffers.length = 0;
return chunk;
};
Paper.prototype.flush = function () {
if (this.start < this.offset) {
this.push(subarray(this.buffer, this.start, this.offset));
this.start = this.offset;
}
};
Paper.prototype.reserve = function (length) {
if (!this.buffer) {
this.alloc(length);
return;
}
var size = this.buffer.byteLength;
// Does it need to be resized?
if (this.offset + length > size) {
// Flush current buffer.
if (this.offset) {
this.flush();
}
// Resize it to 2x current length.
this.alloc(Math.max(length, Math.min(size * 2, MAX_BUFFER_SIZE)));
}
};
Paper.prototype.alloc = function (length) {
this.setBuffer(new Uint8Array(Math.max(length, MIN_BUFFER_SIZE)));
};
Paper.prototype.setBuffer = function (buffer) {
this.buffer = buffer;
this.offset = 0;
this.start = 0;
};
Paper.prototype.send = function (buffer) {
var end = this.offset + buffer.byteLength;
if (this.buffer && end <= this.buffer.byteLength) {
this.buffer.set(buffer, this.offset);
this.offset = end;
}
else {
this.flush();
this.push(buffer);
}
};
return Paper;
}());
/* eslint-disable react/no-this-in-sfc */
const MIN_BUFFER_SIZE = 2048;
const MAX_BUFFER_SIZE = 65536;
const Paper = function Paper(codec, useJSBI) {
this.codec = codec;
this.useJSBI = useJSBI;
};
Paper.prototype.push = function push(chunk) {
const buffers = this.buffers || (this.buffers = []);
buffers.push(chunk);
};
Paper.prototype.read = function read() {
this.flush();
const buffers = this.buffers;
if (buffers) {
const chunk = buffers.length > 1 ? concat(buffers) : buffers[0];
buffers.length = 0;
return chunk;
}
return null;
};
Paper.prototype.flush = function flush() {
if (this.start < this.offset) {
this.push(subarray(this.buffer, this.start, this.offset));
this.start = this.offset;
}
};
Paper.prototype.reserve = function reserve(length) {
if (!this.buffer) {
return this.alloc(length);
}
const size = this.buffer.byteLength;
// Does it need to be resized?
if (this.offset + length > size) {
// Flush current buffer.
if (this.offset) {
this.flush();
var MsgPack = /** @class */ (function () {
function MsgPack(codec, forceJSBI) {
if (codec === void 0) { codec = new Codec(); }
if (forceJSBI === void 0) { forceJSBI = false; }
this.codec = codec;
this.useJSBI = this.useJsbi(forceJSBI);
this.decoder = new Paper(this.codec, this.useJSBI);
this.encoder = new Paper(this.codec);
}
// Resize it to 2x current length.
this.alloc(Math.max(length, Math.min(size * 2, MAX_BUFFER_SIZE)));
}
return null;
};
Paper.prototype.alloc = function alloc(length) {
this.setBuffer(new Uint8Array(Math.max(length, MIN_BUFFER_SIZE)));
};
Paper.prototype.setBuffer = function setBuffer(buffer) {
this.buffer = buffer;
this.offset = 0;
this.start = 0;
};
Paper.prototype.send = function send(buffer) {
const end = this.offset + buffer.byteLength;
if (this.buffer && end <= this.buffer.byteLength) {
this.buffer.set(buffer, this.offset);
this.offset = end;
} else {
this.flush();
this.push(buffer);
}
};
MsgPack.prototype.decode = function (input) {
this.decoder.setBuffer(input);
return decode(this.decoder);
};
MsgPack.prototype.encode = function (input) {
encode(this.encoder, input);
return this.encoder.read();
};
MsgPack.prototype.setCodec = function (codec, forceJSBI) {
if (forceJSBI === void 0) { forceJSBI = false; }
this.codec = codec;
this.useJSBI = this.useJsbi(forceJSBI);
};
MsgPack.prototype.useJsbi = function (forceJSBI) {
var useJSBI = forceJSBI;
if (typeof BigInt === 'undefined') {
useJSBI = true;
}
return useJSBI;
};
return MsgPack;
}());
const Codec$1 = Codec;
function encode$1(input, codec = new Codec$1()) {
if (!(codec instanceof Codec$1)) {
throw new TypeError('Expected second argument to be a Codec, if provided.');
}
const encoder = new Paper(codec);
encode(encoder, input);
return encoder.read();
}
function decode$1(input, codec = new Codec$1(), forceJSBI = false) {
let useJSBI = forceJSBI;
if (!(codec instanceof Codec$1)) {
throw new TypeError('Expected second argument to be a Codec, if provided.');
}
if (!(input instanceof Uint8Array)) {
throw new TypeError('Expected first argument to be a Uint8Array.');
}
if (typeof BigInt === 'undefined') {
useJSBI = true;
}
const decoder = new Paper(codec, useJSBI);
decoder.setBuffer(input);
return decode(decoder);
}
const BaseEncoder = Paper;
const Headers = writeHeader;
const Encoder = writeFormat;
const Decoder = ReadFormat;
const BufferUtils = {
concat,
fromString,
subarray,
toString,
var BufferUtils = {
concat: concat,
fromString: fromString,
subarray: subarray,
toString: toString,
};
var TokenCreators = { constant: constant, fix: fix, flex: flex };
const TokenCreators = { constant, fix, flex };
var index = {
encode: encode$1,
decode: decode$1,
Codec: Codec$1,
};
exports.BaseEncoder = BaseEncoder;
exports.BufferUtils = BufferUtils;
exports.Decoder = Decoder;
exports.Encoder = Encoder;
exports.Headers = Headers;
exports.Codec = Codec;
exports.Decoder = ReadFormat;
exports.Encoder = WriteFormat;
exports.Headers = headers;
exports.Paper = Paper;
exports.ReadTokens = DefaultReadToken;
exports.TokenCreators = TokenCreators;
exports.default = index;
exports.WriteTypes = writeType;
exports.baseDecode = decode;
exports.baseEncode = encode;
exports.default = MsgPack;
exports.isJsbi = isJsbi;
{
"name": "a-msgpack",
"version": "0.1.42",
"version": "0.3.4",
"description": "A minimalistic MessagePack encoder and decoder for JavaScript.",
"author": "Stephane Rufer <stephane@arista.com>",
"homepage": "http://www.arista.com",
"license": "MIT",
"main": "lib/MsgPack.js",
"unpkg": "dist/MsgPack.js",
"module": "es/MsgPack.js",
"typings": "typings/src/index.d.ts",
"scripts": {
"build": "yarn run clean && yarn run build:es && yarn run build:commonjs && yarn run build:umd && yarn run build:umd:min && yarn run build:types",
"build:commonjs": "cross-env NODE_ENV=cjs rollup -c -o lib/MsgPack.js",
"build:es": "cross-env BABEL_ENV=es NODE_ENV=es rollup -c -o es/MsgPack.js",
"build:types": "rimraf typings && tsc --emitDeclarationOnly -p tsconfig-build.json",
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -o dist/MsgPack.js",
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -o dist/MsgPack.min.js",
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -o dist/MsgPack.js",
"build": "yarn run clean && yarn run build:es && yarn run build:commonjs && yarn run build:umd && yarn run build:umd:min",
"check": "yarn run lint && yarn run test",
"clean": "rimraf dist lib es",
"lint": "eslint *.js src/** test/**",
"docs": "typedoc --toc index --out docs/html",
"docs:md": "typedoc --theme markdown --out docs/md --hideSources",
"lint": "eslint --max-warnings 0 --ext .js,.ts *.js src/**/*.ts types/**/*.ts test/**/*.ts",
"prepare": "yarn run lint && yarn run test:cov && yarn run build",
"test": "jest",
"test:clean": "rimraf .jest-cache",
"test:cov": "rimraf coverage && yarn run test --coverage",
"test:watch": "yarn run test --watch",
"test": "jest"
"type-check": "tsc --noEmit"
},

@@ -32,31 +40,24 @@ "keywords": [

],
"author": "Stephane Rufer <stephane@arista.com>",
"license": "MIT",
"files": [
"dist",
"lib",
"es",
"src",
"typings"
],
"dependencies": {
"int64-buffer": "0.99.1007",
"jsbi": "2.0.5"
"jsbi": "3.1.1"
},
"devDependencies": {
"@babel/cli": "7.5.0",
"@babel/core": "7.4.5",
"@babel/preset-env": "7.4.5",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.2",
"babel-jest": "24.8.0",
"benchmark": "2.1.4",
"cli-color": "1.4.0",
"cross-env": "5.2.0",
"eslint": "5.16.0",
"eslint-config-arista": "0.2.23",
"eslint-plugin-babel": "5.3.0",
"jest": "24.8.0",
"msgpack": "1.0.2",
"@types/msgpack-lite": "0.1.7",
"msgpack-lite": "0.1.26",
"rimraf": "2.6.3",
"rollup": "1.12.4",
"rollup-plugin-commonjs": "10.0.1",
"rollup": "1.23.1",
"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-terser": "5.1.1"
},
"gitHead": "1ee7cc6ac00fd3fb7083a57224d06286405b36c2"
"rollup-plugin-terser": "5.1.2",
"rollup-plugin-typescript": "1.0.1",
"tslib": "1.10.0",
"typescript": "3.7.2"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc