Simulator first commit
This commit is contained in:
12
node_modules/bytebuffer/src/bower.json
generated
vendored
Normal file
12
node_modules/bytebuffer/src/bower.json
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "bytebuffer",
|
||||
"version": "/*?= VERSION */",
|
||||
"author": "Daniel Wirtz <dcode@dcode.io>",
|
||||
"description": "A full-featured ByteBuffer implementation using typed arrays.",
|
||||
"main": "dist/bytebuffer.js",
|
||||
"keywords": ["net", "array", "buffer", "arraybuffer", "typed array", "bytebuffer", "json", "websocket", "webrtc"],
|
||||
"dependencies": {
|
||||
"long": "latest"
|
||||
},
|
||||
"license": "Apache-2.0"
|
||||
}
|
220
node_modules/bytebuffer/src/bytebuffer.js
generated
vendored
Normal file
220
node_modules/bytebuffer/src/bytebuffer.js
generated
vendored
Normal file
@ -0,0 +1,220 @@
|
||||
//? include("macros.js");
|
||||
/**
|
||||
* Constructs a new ByteBuffer.
|
||||
* @class The swiss army knife for binary data in JavaScript.
|
||||
* @exports ByteBuffer
|
||||
* @constructor
|
||||
* @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}.
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_NOASSERT}.
|
||||
* @expose
|
||||
*/
|
||||
var ByteBuffer = function(capacity, littleEndian, noAssert) {
|
||||
if (typeof capacity === 'undefined')
|
||||
capacity = ByteBuffer.DEFAULT_CAPACITY;
|
||||
if (typeof littleEndian === 'undefined')
|
||||
littleEndian = ByteBuffer.DEFAULT_ENDIAN;
|
||||
if (typeof noAssert === 'undefined')
|
||||
noAssert = ByteBuffer.DEFAULT_NOASSERT;
|
||||
if (!noAssert) {
|
||||
capacity = capacity | 0;
|
||||
if (capacity < 0)
|
||||
throw RangeError("Illegal capacity");
|
||||
littleEndian = !!littleEndian;
|
||||
noAssert = !!noAssert;
|
||||
}
|
||||
//? if (NODE) {
|
||||
|
||||
/**
|
||||
* Backing node Buffer.
|
||||
* @type {!Buffer}
|
||||
* @expose
|
||||
*/
|
||||
this.buffer = capacity === 0 ? EMPTY_BUFFER : new Buffer(capacity);
|
||||
//? } else {
|
||||
|
||||
/**
|
||||
* Backing ArrayBuffer.
|
||||
* @type {!ArrayBuffer}
|
||||
* @expose
|
||||
*/
|
||||
this.buffer = capacity === 0 ? EMPTY_BUFFER : new ArrayBuffer(capacity);
|
||||
|
||||
//? if (DATAVIEW) {
|
||||
/**
|
||||
* DataView utilized to manipulate the backing buffer. Becomes `null` if the backing buffer has a capacity of `0`.
|
||||
* @type {?DataView}
|
||||
* @expose
|
||||
*/
|
||||
this.view = capacity === 0 ? null : new DataView(this.buffer);
|
||||
//? } else {
|
||||
/**
|
||||
* Uint8Array utilized to manipulate the backing buffer. Becomes `null` if the backing buffer has a capacity of `0`.
|
||||
* @type {?Uint8Array}
|
||||
* @expose
|
||||
*/
|
||||
this.view = capacity === 0 ? null : new Uint8Array(this.buffer);
|
||||
//? }
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Absolute read/write offset.
|
||||
* @type {number}
|
||||
* @expose
|
||||
* @see ByteBuffer#flip
|
||||
* @see ByteBuffer#clear
|
||||
*/
|
||||
this.offset = 0;
|
||||
|
||||
/**
|
||||
* Marked offset.
|
||||
* @type {number}
|
||||
* @expose
|
||||
* @see ByteBuffer#mark
|
||||
* @see ByteBuffer#reset
|
||||
*/
|
||||
this.markedOffset = -1;
|
||||
|
||||
/**
|
||||
* Absolute limit of the contained data. Set to the backing buffer's capacity upon allocation.
|
||||
* @type {number}
|
||||
* @expose
|
||||
* @see ByteBuffer#flip
|
||||
* @see ByteBuffer#clear
|
||||
*/
|
||||
this.limit = capacity;
|
||||
|
||||
/**
|
||||
* Whether to use little endian byte order, defaults to `false` for big endian.
|
||||
* @type {boolean}
|
||||
* @expose
|
||||
*/
|
||||
this.littleEndian = littleEndian;
|
||||
|
||||
/**
|
||||
* Whether to skip assertions of offsets and values, defaults to `false`.
|
||||
* @type {boolean}
|
||||
* @expose
|
||||
*/
|
||||
this.noAssert = noAssert;
|
||||
};
|
||||
|
||||
/**
|
||||
* ByteBuffer version.
|
||||
* @type {string}
|
||||
* @const
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.VERSION = "/*?= VERSION */";
|
||||
|
||||
/**
|
||||
* Little endian constant that can be used instead of its boolean value. Evaluates to `true`.
|
||||
* @type {boolean}
|
||||
* @const
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.LITTLE_ENDIAN = true;
|
||||
|
||||
/**
|
||||
* Big endian constant that can be used instead of its boolean value. Evaluates to `false`.
|
||||
* @type {boolean}
|
||||
* @const
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.BIG_ENDIAN = false;
|
||||
|
||||
/**
|
||||
* Default initial capacity of `16`.
|
||||
* @type {number}
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.DEFAULT_CAPACITY = 16;
|
||||
|
||||
/**
|
||||
* Default endianess of `false` for big endian.
|
||||
* @type {boolean}
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.DEFAULT_ENDIAN = ByteBuffer.BIG_ENDIAN;
|
||||
|
||||
/**
|
||||
* Default no assertions flag of `false`.
|
||||
* @type {boolean}
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.DEFAULT_NOASSERT = false;
|
||||
//? if (NODE) {
|
||||
|
||||
/**
|
||||
* A `Long` class for representing a 64-bit two's-complement integer value.
|
||||
* @type {!Long}
|
||||
* @const
|
||||
* @see https://npmjs.org/package/long
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.Long = Long;
|
||||
//? } else {
|
||||
|
||||
/**
|
||||
* A `Long` class for representing a 64-bit two's-complement integer value. May be `null` if Long.js has not been loaded
|
||||
* and int64 support is not available.
|
||||
* @type {?Long}
|
||||
* @const
|
||||
* @see https://github.com/dcodeIO/long.js
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.Long = Long || null;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* @alias ByteBuffer.prototype
|
||||
* @inner
|
||||
*/
|
||||
var ByteBufferPrototype = ByteBuffer.prototype;
|
||||
|
||||
/**
|
||||
* An indicator used to reliably determine if an object is a ByteBuffer or not.
|
||||
* @type {boolean}
|
||||
* @const
|
||||
* @expose
|
||||
* @private
|
||||
*/
|
||||
ByteBufferPrototype.__isByteBuffer__;
|
||||
|
||||
Object.defineProperty(ByteBufferPrototype, "__isByteBuffer__", {
|
||||
value: true,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
//? include("helpers.js");
|
||||
|
||||
//? include("methods/static/*.js");
|
||||
//? if (BYTES) {
|
||||
|
||||
//? include("types/bytes/*.js");
|
||||
//? }
|
||||
//? if (INTS) {
|
||||
|
||||
//? include("types/ints/*.js");
|
||||
//? }
|
||||
//? if (FLOATS) {
|
||||
|
||||
//? include("types/floats/float*.js");
|
||||
//? }
|
||||
//? if (VARINTS) {
|
||||
|
||||
//? include("types/varints/*.js");
|
||||
//? }
|
||||
//? if (UTF8 && STRINGS) {
|
||||
|
||||
//? include("types/strings/*.js");
|
||||
//? }
|
||||
|
||||
//? include("methods/*.js");
|
||||
//? if (ENCODINGS) {
|
||||
|
||||
//? include("encodings/*.js");
|
||||
//? }
|
88
node_modules/bytebuffer/src/encodings/base64.js
generated
vendored
Normal file
88
node_modules/bytebuffer/src/encodings/base64.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
//? if (BASE64) {
|
||||
//? if (!NODE) {
|
||||
// lxiv-embeddable
|
||||
|
||||
//? include("../../node_modules/lxiv/dist/lxiv-embeddable.js");
|
||||
|
||||
//? }
|
||||
// encodings/base64
|
||||
|
||||
/**
|
||||
* Encodes this ByteBuffer's contents to a base64 encoded string.
|
||||
* @param {number=} begin Offset to begin at, defaults to {@link ByteBuffer#offset}.
|
||||
* @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}.
|
||||
* @returns {string} Base64 encoded string
|
||||
* @throws {RangeError} If `begin` or `end` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.toBase64 = function(begin, end) {
|
||||
if (typeof begin === 'undefined')
|
||||
begin = this.offset;
|
||||
if (typeof end === 'undefined')
|
||||
end = this.limit;
|
||||
begin = begin | 0; end = end | 0;
|
||||
if (begin < 0 || end > this.capacity || begin > end)
|
||||
throw RangeError("begin, end");
|
||||
//? if (NODE)
|
||||
return this.buffer.toString("base64", begin, end);
|
||||
//? else {
|
||||
var sd; lxiv.encode(function() {
|
||||
//? if (DATAVIEW)
|
||||
return begin < end ? this.view.getUint8(begin++) : null;
|
||||
//? else
|
||||
return begin < end ? this.view[begin++] : null;
|
||||
}.bind(this), sd = stringDestination());
|
||||
return sd();
|
||||
//? }
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a base64 encoded string to a ByteBuffer.
|
||||
* @param {string} str String to decode
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @returns {!ByteBuffer} ByteBuffer
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.fromBase64 = function(str, littleEndian) {
|
||||
//? if (NODE) {
|
||||
return ByteBuffer.wrap(new Buffer(str, "base64"), littleEndian);
|
||||
//? } else {
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("str");
|
||||
var bb = new ByteBuffer(str.length/4*3, littleEndian),
|
||||
i = 0;
|
||||
lxiv.decode(stringSource(str), function(b) {
|
||||
//? if (DATAVIEW)
|
||||
bb.view.setUint8(i++, b);
|
||||
//? else
|
||||
bb.view[i++] = b;
|
||||
});
|
||||
bb.limit = i;
|
||||
//? }
|
||||
return bb;
|
||||
};
|
||||
|
||||
/**
|
||||
* Encodes a binary string to base64 like `window.btoa` does.
|
||||
* @param {string} str Binary string
|
||||
* @returns {string} Base64 encoded string
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window.btoa
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.btoa = function(str) {
|
||||
return ByteBuffer.fromBinary(str).toBase64();
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a base64 encoded string to binary like `window.atob` does.
|
||||
* @param {string} b64 Base64 encoded string
|
||||
* @returns {string} Binary string
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Window.atob
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.atob = function(b64) {
|
||||
return ByteBuffer.fromBase64(b64).toBinary();
|
||||
};
|
||||
|
||||
//? }
|
74
node_modules/bytebuffer/src/encodings/binary.js
generated
vendored
Normal file
74
node_modules/bytebuffer/src/encodings/binary.js
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
//? if (BINARY) {
|
||||
// encodings/binary
|
||||
|
||||
/**
|
||||
* Encodes this ByteBuffer to a binary encoded string, that is using only characters 0x00-0xFF as bytes.
|
||||
* @param {number=} begin Offset to begin at. Defaults to {@link ByteBuffer#offset}.
|
||||
* @param {number=} end Offset to end at. Defaults to {@link ByteBuffer#limit}.
|
||||
* @returns {string} Binary encoded string
|
||||
* @throws {RangeError} If `offset > limit`
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.toBinary = function(begin, end) {
|
||||
if (typeof begin === 'undefined')
|
||||
begin = this.offset;
|
||||
if (typeof end === 'undefined')
|
||||
end = this.limit;
|
||||
begin |= 0; end |= 0;
|
||||
if (begin < 0 || end > this.capacity() || begin > end)
|
||||
throw RangeError("begin, end");
|
||||
//? if (NODE)
|
||||
return this.buffer.toString("binary", begin, end);
|
||||
//? else {
|
||||
if (begin === end)
|
||||
return "";
|
||||
var chars = [],
|
||||
parts = [];
|
||||
while (begin < end) {
|
||||
//? if (NODE)
|
||||
chars.push(this.buffer[begin++]);
|
||||
//? else if (DATAVIEW)
|
||||
chars.push(this.view.getUint8(begin++));
|
||||
//? else
|
||||
chars.push(this.view[begin++]);
|
||||
if (chars.length >= 1024)
|
||||
parts.push(String.fromCharCode.apply(String, chars)),
|
||||
chars = [];
|
||||
}
|
||||
return parts.join('') + String.fromCharCode.apply(String, chars);
|
||||
//? }
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer.
|
||||
* @param {string} str String to decode
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @returns {!ByteBuffer} ByteBuffer
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.fromBinary = function(str, littleEndian) {
|
||||
//? if (NODE) {
|
||||
return ByteBuffer.wrap(new Buffer(str, "binary"), littleEndian);
|
||||
//? } else {
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("str");
|
||||
var i = 0,
|
||||
k = str.length,
|
||||
charCode,
|
||||
bb = new ByteBuffer(k, littleEndian);
|
||||
while (i<k) {
|
||||
charCode = str.charCodeAt(i);
|
||||
if (charCode > 0xff)
|
||||
throw RangeError("illegal char code: "+charCode);
|
||||
//? if (DATAVIEW)
|
||||
bb.view.setUint8(i++, charCode);
|
||||
//? else
|
||||
bb.view[i++] = charCode;
|
||||
}
|
||||
bb.limit = k;
|
||||
//? }
|
||||
return bb;
|
||||
};
|
||||
|
||||
//? }
|
211
node_modules/bytebuffer/src/encodings/debug.js
generated
vendored
Normal file
211
node_modules/bytebuffer/src/encodings/debug.js
generated
vendored
Normal file
@ -0,0 +1,211 @@
|
||||
//? if (DEBUG) {
|
||||
// encodings/debug
|
||||
|
||||
/**
|
||||
* Encodes this ByteBuffer to a hex encoded string with marked offsets. Offset symbols are:
|
||||
* * `<` : offset,
|
||||
* * `'` : markedOffset,
|
||||
* * `>` : limit,
|
||||
* * `|` : offset and limit,
|
||||
* * `[` : offset and markedOffset,
|
||||
* * `]` : markedOffset and limit,
|
||||
* * `!` : offset, markedOffset and limit
|
||||
* @param {boolean=} columns If `true` returns two columns hex + ascii, defaults to `false`
|
||||
* @returns {string|!Array.<string>} Debug string or array of lines if `asArray = true`
|
||||
* @expose
|
||||
* @example `>00'01 02<03` contains four bytes with `limit=0, markedOffset=1, offset=3`
|
||||
* @example `00[01 02 03>` contains four bytes with `offset=markedOffset=1, limit=4`
|
||||
* @example `00|01 02 03` contains four bytes with `offset=limit=1, markedOffset=-1`
|
||||
* @example `|` contains zero bytes with `offset=limit=0, markedOffset=-1`
|
||||
*/
|
||||
ByteBufferPrototype.toDebug = function(columns) {
|
||||
var i = -1,
|
||||
//? if (NODE)
|
||||
k = this.buffer.length,
|
||||
//? else
|
||||
k = this.buffer.byteLength,
|
||||
b,
|
||||
hex = "",
|
||||
asc = "",
|
||||
out = "";
|
||||
while (i<k) {
|
||||
if (i !== -1) {
|
||||
//? if (NODE)
|
||||
b = this.buffer[i];
|
||||
//? else if (DATAVIEW)
|
||||
b = this.view.getUint8(i);
|
||||
//? else
|
||||
b = this.view[i];
|
||||
if (b < 0x10) hex += "0"+b.toString(16).toUpperCase();
|
||||
else hex += b.toString(16).toUpperCase();
|
||||
if (columns)
|
||||
asc += b > 32 && b < 127 ? String.fromCharCode(b) : '.';
|
||||
}
|
||||
++i;
|
||||
if (columns) {
|
||||
if (i > 0 && i % 16 === 0 && i !== k) {
|
||||
while (hex.length < 3*16+3) hex += " ";
|
||||
out += hex+asc+"\n";
|
||||
hex = asc = "";
|
||||
}
|
||||
}
|
||||
if (i === this.offset && i === this.limit)
|
||||
hex += i === this.markedOffset ? "!" : "|";
|
||||
else if (i === this.offset)
|
||||
hex += i === this.markedOffset ? "[" : "<";
|
||||
else if (i === this.limit)
|
||||
hex += i === this.markedOffset ? "]" : ">";
|
||||
else
|
||||
hex += i === this.markedOffset ? "'" : (columns || (i !== 0 && i !== k) ? " " : "");
|
||||
}
|
||||
if (columns && hex !== " ") {
|
||||
while (hex.length < 3*16+3)
|
||||
hex += " ";
|
||||
out += hex + asc + "\n";
|
||||
}
|
||||
return columns ? out : hex;
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a hex encoded string with marked offsets to a ByteBuffer.
|
||||
* @param {string} str Debug string to decode (not be generated with `columns = true`)
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_NOASSERT}.
|
||||
* @returns {!ByteBuffer} ByteBuffer
|
||||
* @expose
|
||||
* @see ByteBuffer#toDebug
|
||||
*/
|
||||
ByteBuffer.fromDebug = function(str, littleEndian, noAssert) {
|
||||
/*?
|
||||
// "<60 61 62 63>"; // 13 = 4
|
||||
// "60<61 62]63" // 11 = 4
|
||||
// "<61 61 61>"; // 10 = 3 => C = ((L+1)/3) | 0
|
||||
// "61<61>61"; // 8 = 3
|
||||
// "<61 61>"; // 7 = 2
|
||||
*/
|
||||
var k = str.length,
|
||||
bb = new ByteBuffer(((k+1)/3)|0, littleEndian, noAssert);
|
||||
var i = 0, j = 0, ch, b,
|
||||
rs = false, // Require symbol next
|
||||
ho = false, hm = false, hl = false, // Already has offset (ho), markedOffset (hm), limit (hl)?
|
||||
fail = false;
|
||||
while (i<k) {
|
||||
switch (ch = str.charAt(i++)) {
|
||||
case '!':
|
||||
if (!noAssert) {
|
||||
if (ho || hm || hl) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
ho = hm = hl = true;
|
||||
}
|
||||
bb.offset = bb.markedOffset = bb.limit = j;
|
||||
rs = false;
|
||||
break;
|
||||
case '|':
|
||||
if (!noAssert) {
|
||||
if (ho || hl) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
ho = hl = true;
|
||||
}
|
||||
bb.offset = bb.limit = j;
|
||||
rs = false;
|
||||
break;
|
||||
case '[':
|
||||
if (!noAssert) {
|
||||
if (ho || hm) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
ho = hm = true;
|
||||
}
|
||||
bb.offset = bb.markedOffset = j;
|
||||
rs = false;
|
||||
break;
|
||||
case '<':
|
||||
if (!noAssert) {
|
||||
if (ho) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
ho = true;
|
||||
}
|
||||
bb.offset = j;
|
||||
rs = false;
|
||||
break;
|
||||
case ']':
|
||||
if (!noAssert) {
|
||||
if (hl || hm) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
hl = hm = true;
|
||||
}
|
||||
bb.limit = bb.markedOffset = j;
|
||||
rs = false;
|
||||
break;
|
||||
case '>':
|
||||
if (!noAssert) {
|
||||
if (hl) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
hl = true;
|
||||
}
|
||||
bb.limit = j;
|
||||
rs = false;
|
||||
break;
|
||||
case "'":
|
||||
if (!noAssert) {
|
||||
if (hm) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
hm = true;
|
||||
}
|
||||
bb.markedOffset = j;
|
||||
rs = false;
|
||||
break;
|
||||
case ' ':
|
||||
rs = false;
|
||||
break;
|
||||
default:
|
||||
if (!noAssert) {
|
||||
if (rs) {
|
||||
fail = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
b = parseInt(ch+str.charAt(i++), 16);
|
||||
if (!noAssert) {
|
||||
if (isNaN(b) || b < 0 || b > 255)
|
||||
throw TypeError("Illegal str: Not a debug encoded string");
|
||||
}
|
||||
//? if (NODE)
|
||||
bb.buffer[j++] = b;
|
||||
//? else if (DATAVIEW)
|
||||
bb.view.setUint8(j++, b);
|
||||
//? else
|
||||
bb.view[j++] = b;
|
||||
rs = true;
|
||||
}
|
||||
if (fail)
|
||||
throw TypeError("Illegal str: Invalid symbol at "+i);
|
||||
}
|
||||
if (!noAssert) {
|
||||
if (!ho || !hl)
|
||||
throw TypeError("Illegal str: Missing offset or limit");
|
||||
//? if (NODE)
|
||||
if (j<bb.buffer.length)
|
||||
//? else
|
||||
if (j<bb.buffer.byteLength)
|
||||
throw TypeError("Illegal str: Not a debug encoded string (is it hex?) "+j+" < "+k);
|
||||
}
|
||||
return bb;
|
||||
};
|
||||
|
||||
//? }
|
75
node_modules/bytebuffer/src/encodings/hex.js
generated
vendored
Normal file
75
node_modules/bytebuffer/src/encodings/hex.js
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
//? if (HEX) {
|
||||
// encodings/hex
|
||||
|
||||
/**
|
||||
* Encodes this ByteBuffer's contents to a hex encoded string.
|
||||
* @param {number=} begin Offset to begin at. Defaults to {@link ByteBuffer#offset}.
|
||||
* @param {number=} end Offset to end at. Defaults to {@link ByteBuffer#limit}.
|
||||
* @returns {string} Hex encoded string
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.toHex = function(begin, end) {
|
||||
begin = typeof begin === 'undefined' ? this.offset : begin;
|
||||
end = typeof end === 'undefined' ? this.limit : end;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE();
|
||||
}
|
||||
//? if (NODE)
|
||||
return this.buffer.toString("hex", begin, end);
|
||||
//? else {
|
||||
var out = new Array(end - begin),
|
||||
b;
|
||||
while (begin < end) {
|
||||
//? if (DATAVIEW)
|
||||
b = this.view.getUint8(begin++);
|
||||
//? else
|
||||
b = this.view[begin++];
|
||||
if (b < 0x10)
|
||||
out.push("0", b.toString(16));
|
||||
else out.push(b.toString(16));
|
||||
}
|
||||
return out.join('');
|
||||
//? }
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a hex encoded string to a ByteBuffer.
|
||||
* @param {string} str String to decode
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_NOASSERT}.
|
||||
* @returns {!ByteBuffer} ByteBuffer
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.fromHex = function(str, littleEndian, noAssert) {
|
||||
if (!noAssert) {
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("Illegal str: Not a string");
|
||||
if (str.length % 2 !== 0)
|
||||
throw TypeError("Illegal str: Length not a multiple of 2");
|
||||
}
|
||||
//? if (NODE) {
|
||||
var bb = new ByteBuffer(0, littleEndian, true);
|
||||
bb.buffer = new Buffer(str, "hex");
|
||||
bb.limit = bb.buffer.length;
|
||||
//? } else {
|
||||
var k = str.length,
|
||||
bb = new ByteBuffer((k / 2) | 0, littleEndian),
|
||||
b;
|
||||
for (var i=0, j=0; i<k; i+=2) {
|
||||
b = parseInt(str.substring(i, i+2), 16);
|
||||
if (!noAssert)
|
||||
if (!isFinite(b) || b < 0 || b > 255)
|
||||
throw TypeError("Illegal str: Contains non-hex characters");
|
||||
//? if (DATAVIEW)
|
||||
bb.view.setUint8(j++, b);
|
||||
//? else
|
||||
bb.view[j++] = b;
|
||||
}
|
||||
bb.limit = j;
|
||||
//? }
|
||||
return bb;
|
||||
};
|
||||
|
||||
//? }
|
3
node_modules/bytebuffer/src/encodings/impl/base64.js
generated
vendored
Normal file
3
node_modules/bytebuffer/src/encodings/impl/base64.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
// encodings/impl/base64
|
||||
|
||||
// TODO
|
65
node_modules/bytebuffer/src/encodings/impl/binary.js
generated
vendored
Normal file
65
node_modules/bytebuffer/src/encodings/impl/binary.js
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// encodings/impl/binary
|
||||
|
||||
/**
|
||||
* Encodes a binary JavaScript string to bytes.
|
||||
* @param {string} src Source string
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {!ByteBuffer} dst Destination ByteBuffer
|
||||
* @param {number} dstOffset Destination offset
|
||||
* @param {number} count Number of char codes to encode
|
||||
* @returns {number} Number of bytes encoded
|
||||
* @inner
|
||||
*/
|
||||
function binary_encode(src, srcOffset, dst, dstOffset, count) {
|
||||
var n = 0;
|
||||
while (count--) {
|
||||
var cc = src.charCodeAt(srcOffset++);
|
||||
if (cc > 255)
|
||||
throw Error("illegal binary char code: "+cc);
|
||||
//? SET('cc', 'dstOffset++', 'dst');
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes bytes to a binary JavaScript string.
|
||||
* @param {!ByteBuffer} src Source ByteBuffer
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {number} count Number of bytes to decode
|
||||
* @returns {string} Decoded string
|
||||
* @inner
|
||||
*/
|
||||
function binary_decode(src, srcOffset, count) {
|
||||
if (count === 0)
|
||||
return "";
|
||||
var parts = [], // readily assembled parts
|
||||
batch = []; // char codes for batch processing
|
||||
while (count--) {
|
||||
batch.push(/*? GET('srcOffset++', 'src') */);
|
||||
if (batch.length > 1023) {
|
||||
parts.push(String.fromCharCode.apply(String, batch));
|
||||
batch.length = 0;
|
||||
}
|
||||
}
|
||||
if (batch.length > 0) {
|
||||
if (parts.length === 0)
|
||||
return String.fromCharCode.apply(String, batch);
|
||||
parts.push(String.fromCharCode.apply(String, batch));
|
||||
}
|
||||
return parts.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the number of bytes required to store a binary JavaScript string.
|
||||
* @param {string} src Source string
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {number} count Number of char codes to calculate
|
||||
* @returns {number} Number of bytes required
|
||||
* @inner
|
||||
*/
|
||||
function binary_calculate(src, srcOffset, count) {
|
||||
return count;
|
||||
}
|
||||
|
||||
ByteBuffer.registerEncoding("binary", binary_encode, binary_decode, binary_calculate);
|
3
node_modules/bytebuffer/src/encodings/impl/debug.js
generated
vendored
Normal file
3
node_modules/bytebuffer/src/encodings/impl/debug.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
// encodings/impl/debug
|
||||
|
||||
// TODO
|
101
node_modules/bytebuffer/src/encodings/impl/hex.js
generated
vendored
Normal file
101
node_modules/bytebuffer/src/encodings/impl/hex.js
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
// encodings/impl/hex
|
||||
|
||||
/**
|
||||
* Encodes a hexadecimal JavaScript string to bytes.
|
||||
* @param {string} src Source string
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {!ByteBuffer} dst Destination ByteBuffer
|
||||
* @param {number} dstOffset Destination offset
|
||||
* @param {number} count Number of char codes to encode
|
||||
* @returns {number} Number of bytes encoded
|
||||
* @inner
|
||||
*/
|
||||
function hex_encode(src, srcOffset, dst, dstOffset, count) {
|
||||
if (count === 0)
|
||||
return 0;
|
||||
var n = 0;
|
||||
while (count--) {
|
||||
if (count === 0)
|
||||
throw Error("truncated hex sequence");
|
||||
--count;
|
||||
var value = 0,
|
||||
shift = 0;
|
||||
for (var i=0; i<2; ++i) {
|
||||
var cc = src.charCodeAt(srcOffset++);
|
||||
switch (cc) {
|
||||
case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
|
||||
value |= (cc - 0x30) << shift;
|
||||
break;
|
||||
case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46:
|
||||
value |= (cc - 0x4B) << shift;
|
||||
break;
|
||||
case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66:
|
||||
value |= (cc - 0x6B) << shift;
|
||||
break;
|
||||
default:
|
||||
throw Error("illegal hex char code: "+cc);
|
||||
}
|
||||
shift += 4;
|
||||
}
|
||||
//? SET('value', 'dstOffset++', 'dst');
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes bytes to a hexadecimal JavaScript string.
|
||||
* @param {!ByteBuffer} src Source ByteBuffer
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {number} count Number of bytes to decode
|
||||
* @returns {string} Decoded string
|
||||
* @inner
|
||||
*/
|
||||
function hex_decode(src, srcOffset, count) {
|
||||
if (count === 0)
|
||||
return "";
|
||||
var parts = [], // readily assembled parts
|
||||
batch = []; // char codes for batch processing
|
||||
while (count--) {
|
||||
var value = /*? GET('srcOffset++', 'src') */,
|
||||
shift = 4;
|
||||
for (var i=0; i<2; ++i) {
|
||||
var c = (value >>> shift) & 0xf;
|
||||
switch (c) {
|
||||
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9:
|
||||
batch.push(0x30 + c);
|
||||
break;
|
||||
case 10: case 11: case 12: case 13: case 14: case 15:
|
||||
batch.push(0x37 + c);
|
||||
break;
|
||||
}
|
||||
shift = 0;
|
||||
}
|
||||
if (batch.length > 1023) {
|
||||
parts.push(String.fromCharCode.apply(String, batch));
|
||||
batch.length = 0;
|
||||
}
|
||||
}
|
||||
if (batch.length > 0) {
|
||||
if (parts.length === 0)
|
||||
return String.fromCharCode.apply(String, batch);
|
||||
parts.push(String.fromCharCode.apply(String, batch));
|
||||
}
|
||||
return parts.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the number of bytes required to store a hexadecimal JavaScript string.
|
||||
* @param {string} src Source string
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {number} count Number of char codes to calculate
|
||||
* @returns {number} Number of bytes required
|
||||
* @inner
|
||||
*/
|
||||
function hex_calculate(src, srcOffset, count) {
|
||||
if ((count % 2) !== 0)
|
||||
throw Error("illegal number of hex char codes: "+count);
|
||||
return count / 2;
|
||||
}
|
||||
|
||||
ByteBuffer.registerEncoding("hex", hex_encode, hex_decode, hex_calculate);
|
126
node_modules/bytebuffer/src/encodings/impl/utf8.js
generated
vendored
Normal file
126
node_modules/bytebuffer/src/encodings/impl/utf8.js
generated
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
// encodings/impl/utf8
|
||||
|
||||
/**
|
||||
* Encodes a standard JavaScript string to UTF8 bytes.
|
||||
* @param {string} src Source string
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {!ByteBuffer} dst Destination ByteBuffer
|
||||
* @param {number} dstOffset Destination offset
|
||||
* @param {number} count Number of char codes to encode
|
||||
* @returns {number} Number of bytes encoded
|
||||
* @inner
|
||||
*/
|
||||
function utf8_encode(src, srcOffset, dst, dstOffset, count) {
|
||||
if (count === 0)
|
||||
return 0;
|
||||
var n = 0;
|
||||
//? // SET(varValue, varOffset, varTarget) with varTarget referencing a ByteBuffer
|
||||
do {
|
||||
var cc = src.charCodeAt(srcOffset++);
|
||||
--count;
|
||||
if (cc < 0x80) {
|
||||
n += 1;
|
||||
//? SET('cc', 'dstOffset++', 'dst');
|
||||
} else if (cc < 0x800) {
|
||||
n += 2;
|
||||
//? SET('0xC0 | (cc >> 6)', 'dstOffset++', 'dst');
|
||||
//? SET('0x80 | (cc & 0x3F)', 'dstOffset++', 'dst');
|
||||
} else if (cc < 0xD800 || cc >= 0xE000) {
|
||||
n += 3;
|
||||
//? SET('0xE0 | (cc >> 12)', 'dstOffset++', 'dst');
|
||||
//? SET('0x80 | ((cc >> 6) & 0x3F)', 'dstOffset++', 'dst');
|
||||
//? SET('0x80 | (cc & 0x3F)', 'dstOffset++', 'dst');
|
||||
} else { // surrogate
|
||||
if (count === 0)
|
||||
throw Error("truncated utf8 surrogate");
|
||||
cc = 0x10000 + (((cc & 0x3FF) << 10) | (src.charCodeAt(srcOffset++) & 0x3FF));
|
||||
--count;
|
||||
n += 4;
|
||||
//? SET('0xF0 | (cc >> 18)', 'dstOffset++', 'dst');
|
||||
//? SET('0x80 | ((cc >> 12) & 0x3F)', 'dstOffset++', 'dst');
|
||||
//? SET('0x80 | ((cc >> 6) & 0x3F)', 'dstOffset++', 'dst');
|
||||
//? SET('0x80 | (cc & 0x3F)', 'dstOffset++', 'dst');
|
||||
}
|
||||
} while (count > 0);
|
||||
return n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes UTF8 bytes to a standard JavaScript string.
|
||||
* @param {!ByteBuffer} src Source ByteBuffer
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {number} count Number of bytes to decode
|
||||
* @returns {string} Decoded string
|
||||
* @inner
|
||||
*/
|
||||
function utf8_decode(src, srcOffset, count) {
|
||||
if (count === 0)
|
||||
return "";
|
||||
var parts = [], // readily assembled parts
|
||||
batch = []; // char codes for batch processing
|
||||
//? // GET(varOffset, varTarget) with varTarget referencing a ByteBuffer
|
||||
while (count--) {
|
||||
var c = /*? GET('srcOffset++', 'src') */,
|
||||
c2, c3;
|
||||
switch (c >> 4) {
|
||||
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
||||
batch.push(c);
|
||||
break;
|
||||
case 12: case 13:
|
||||
if (count < 1)
|
||||
throw Error("truncated utf8 sequence");
|
||||
c2 = /*? GET('srcOffset++', 'src') */;
|
||||
--count;
|
||||
batch.push(((c & 0x1F) << 6) | (c2 & 0x3F));
|
||||
break;
|
||||
case 14:
|
||||
if (count < 2)
|
||||
throw Error("truncated utf8 sequence");
|
||||
c2 = /*? GET('srcOffset++', 'src') */;
|
||||
c3 = /*? GET('srcOffset++', 'src') */;
|
||||
count -= 2;
|
||||
batch.push(((c & 0x0F) << 12) | ((c2 & 0x3F) << 6) | ((c3 & 0x3F) << 0));
|
||||
break;
|
||||
}
|
||||
if (batch.length > 1023) {
|
||||
parts.push(String.fromCharCode.apply(String, batch));
|
||||
batch.length = 0;
|
||||
}
|
||||
}
|
||||
if (batch.length > 0) {
|
||||
if (parts.length === 0)
|
||||
return String.fromCharCode.apply(String, batch);
|
||||
parts.push(String.fromCharCode.apply(String, batch));
|
||||
}
|
||||
return parts.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the number of UTF8 bytes required to store a standard JavaScript string.
|
||||
* @param {string} src Source string
|
||||
* @param {number} srcOffset Source offset
|
||||
* @param {number} count Number of char codes to calculate
|
||||
* @returns {number} Number of bytes required
|
||||
* @inner
|
||||
*/
|
||||
function utf8_calculate(src, srcOffset, count) {
|
||||
if (count === 0)
|
||||
return 0;
|
||||
var n = 0;
|
||||
do {
|
||||
var cc = src.charCodeAt(srcOffset++);
|
||||
--count;
|
||||
if (cc < 0x80) {
|
||||
n += 1;
|
||||
} else if (cc < 0x800) {
|
||||
n += 2;
|
||||
} else if (cc < 0xD800 || cc >= 0xE000) {
|
||||
n += 3;
|
||||
} else {
|
||||
n += 4;
|
||||
}
|
||||
} while (count > 0);
|
||||
return n;
|
||||
}
|
||||
|
||||
ByteBuffer.registerEncoding("utf8", utf8_encode, utf8_decode, utf8_calculate);
|
71
node_modules/bytebuffer/src/encodings/utf8.js
generated
vendored
Normal file
71
node_modules/bytebuffer/src/encodings/utf8.js
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
//? if (UTF8) {
|
||||
// utfx-embeddable
|
||||
|
||||
//? include("../../node_modules/utfx/dist/utfx-embeddable.js");
|
||||
|
||||
// encodings/utf8
|
||||
|
||||
/**
|
||||
* Encodes this ByteBuffer's contents between {@link ByteBuffer#offset} and {@link ByteBuffer#limit} to an UTF8 encoded
|
||||
* string.
|
||||
* @returns {string} Hex encoded string
|
||||
* @throws {RangeError} If `offset > limit`
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.toUTF8 = function(begin, end) {
|
||||
if (typeof begin === 'undefined') begin = this.offset;
|
||||
if (typeof end === 'undefined') end = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE();
|
||||
}
|
||||
//? if (NODE)
|
||||
return this.buffer.toString("utf8", begin, end);
|
||||
//? else {
|
||||
var sd; try {
|
||||
utfx.decodeUTF8toUTF16(function() {
|
||||
//? if (DATAVIEW)
|
||||
return begin < end ? this.view.getUint8(begin++) : null;
|
||||
//? else
|
||||
return begin < end ? this.view[begin++] : null;
|
||||
}.bind(this), sd = stringDestination());
|
||||
} catch (e) {
|
||||
if (begin !== end)
|
||||
throw RangeError("Illegal range: Truncated data, "+begin+" != "+end);
|
||||
}
|
||||
return sd();
|
||||
//? }
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes an UTF8 encoded string to a ByteBuffer.
|
||||
* @param {string} str String to decode
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_NOASSERT}.
|
||||
* @returns {!ByteBuffer} ByteBuffer
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.fromUTF8 = function(str, littleEndian, noAssert) {
|
||||
if (!noAssert)
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("Illegal str: Not a string");
|
||||
//? if (NODE) {
|
||||
var bb = new ByteBuffer(0, littleEndian, noAssert);
|
||||
bb.buffer = new Buffer(str, "utf8");
|
||||
bb.limit = bb.buffer.length;
|
||||
//? } else {
|
||||
var bb = new ByteBuffer(utfx.calculateUTF16asUTF8(stringSource(str), true)[1], littleEndian, noAssert),
|
||||
i = 0;
|
||||
utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
||||
//? if (DATAVIEW)
|
||||
bb.view.setUint8(i++, b);
|
||||
//? else
|
||||
bb.view[i++] = b;
|
||||
});
|
||||
bb.limit = i;
|
||||
//? }
|
||||
return bb;
|
||||
};
|
||||
|
||||
//? }
|
143
node_modules/bytebuffer/src/helpers.js
generated
vendored
Normal file
143
node_modules/bytebuffer/src/helpers.js
generated
vendored
Normal file
@ -0,0 +1,143 @@
|
||||
// helpers
|
||||
//? if (NODE) {
|
||||
|
||||
/**
|
||||
* @type {!Buffer}
|
||||
* @inner
|
||||
*/
|
||||
var EMPTY_BUFFER = new Buffer(0);
|
||||
//? } else {
|
||||
|
||||
/**
|
||||
* @type {!ArrayBuffer}
|
||||
* @inner
|
||||
*/
|
||||
var EMPTY_BUFFER = new ArrayBuffer(0);
|
||||
//? }
|
||||
//? if (!INLINE) {
|
||||
|
||||
/**
|
||||
* Asserts that a value is an integer and returns the type-safe value.
|
||||
* @param {number} value Value to assert
|
||||
* @param {boolean=} unsigned Whether explicitly unsigned
|
||||
* @returns {number} Type-safe value
|
||||
* @throws {TypeError} If `value` is not an integer
|
||||
* @inner
|
||||
*/
|
||||
function assertInteger(value, unsigned) {
|
||||
if (typeof value !== 'number' || value % 1 !== 0)
|
||||
throw TypeError("Illegal value: "+offset+" (not an integer)");
|
||||
return unsigned ? value >>> 0 : value | 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that a value is an integer or Long.
|
||||
* @param {number|!Long} value Value to assert
|
||||
* @param {boolean=} unsigned Whether explicitly unsigned
|
||||
* @returns {number|!Long} Type-safe value
|
||||
* @throws {TypeError} If `value` is not an integer or Long
|
||||
* @inner
|
||||
*/
|
||||
function assertLong(value, unsigned) {
|
||||
if (typeof value === 'number') {
|
||||
return Long.fromNumber(value, unsigned);
|
||||
} else if (typeof value === 'string') {
|
||||
return Long.fromString(value, unsigned);
|
||||
} else if (value && value instanceof Long) {
|
||||
if (typeof unsigned !== 'undefined') {
|
||||
if (unsigned && !value.unsigned) return value.toUnsigned();
|
||||
if (!unsigned && value.unsigned) return value.toSigned();
|
||||
}
|
||||
return value;
|
||||
} else
|
||||
throw TypeError("Illegal value: "+value+" (not an integer or Long)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that `min <= offset <= cap-size` and returns the type-safe offset.
|
||||
* @param {number} offset Offset to assert
|
||||
* @param {number} min Minimum offset
|
||||
* @param {number} cap Cap offset
|
||||
* @param {number} size Required size in bytes
|
||||
* @returns {number} Type-safe offset
|
||||
* @throws {TypeError} If `offset` is not an integer
|
||||
* @throws {RangeError} If `offset < min || offset > cap-size`
|
||||
* @inner
|
||||
*/
|
||||
function assertOffset(offset, min, cap, size) {
|
||||
if (typeof offset !== 'number' || offset % 1 !== 0)
|
||||
throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
||||
offset = offset | 0;
|
||||
if (offset < min || offset > cap-size)
|
||||
throw RangeError("Illegal offset: "+min+" <= "+value+" <= "+cap+"-"+size);
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* assertRange return value.
|
||||
* @type {Array.<number>}
|
||||
*/
|
||||
var rangeVal = new Array(2);
|
||||
|
||||
/**
|
||||
* Asserts that `min <= begin <= end <= cap`. Updates `rangeVal` with the type-safe range.
|
||||
* @param {number} begin Begin offset
|
||||
* @param {number} end End offset
|
||||
* @param {number} min Minimum offset
|
||||
* @param {number} cap Cap offset
|
||||
* @throws {TypeError} If `begin` or `end` is not an integer
|
||||
* @throws {RangeError} If `begin < min || begin > end || end > cap`
|
||||
* @inner
|
||||
*/
|
||||
function assertRange(begin, end, min, cap) {
|
||||
if (typeof begin !== 'number' || begin % 1 !== 0)
|
||||
throw TypeError("Illegal begin: "+begin+" (not a number)");
|
||||
begin = begin | 0;
|
||||
if (typeof end !== 'number' || end % 1 !== 0)
|
||||
throw TypeError("Illegal end: "+range[1]+" (not a number)");
|
||||
end = end | 0;
|
||||
if (begin < min || begin > end || end > cap)
|
||||
throw RangeError("Illegal range: "+min+" <= "+begin+" <= "+end+" <= "+cap);
|
||||
rangeVal[0] = begin; rangeVal[1] = end;
|
||||
}
|
||||
//? }
|
||||
//? if (BASE64 || UTF8) {
|
||||
|
||||
/**
|
||||
* String.fromCharCode reference for compile-time renaming.
|
||||
* @type {function(...number):string}
|
||||
* @inner
|
||||
*/
|
||||
var stringFromCharCode = String.fromCharCode;
|
||||
|
||||
/**
|
||||
* Creates a source function for a string.
|
||||
* @param {string} s String to read from
|
||||
* @returns {function():number|null} Source function returning the next char code respectively `null` if there are
|
||||
* no more characters left.
|
||||
* @throws {TypeError} If the argument is invalid
|
||||
* @inner
|
||||
*/
|
||||
function stringSource(s) {
|
||||
var i=0; return function() {
|
||||
return i < s.length ? s.charCodeAt(i++) : null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a destination function for a string.
|
||||
* @returns {function(number=):undefined|string} Destination function successively called with the next char code.
|
||||
* Returns the final string when called without arguments.
|
||||
* @inner
|
||||
*/
|
||||
function stringDestination() {
|
||||
var cs = [], ps = []; return function() {
|
||||
if (arguments.length === 0)
|
||||
return ps.join('')+stringFromCharCode.apply(String, cs);
|
||||
if (cs.length + arguments.length > 1024)
|
||||
ps.push(stringFromCharCode.apply(String, cs)),
|
||||
cs.length = 0;
|
||||
Array.prototype.push.apply(cs, arguments);
|
||||
};
|
||||
}
|
||||
//? }
|
222
node_modules/bytebuffer/src/macros.js
generated
vendored
Normal file
222
node_modules/bytebuffer/src/macros.js
generated
vendored
Normal file
@ -0,0 +1,222 @@
|
||||
//?...
|
||||
// Welcome to the crazy world of MetaScript! Tell it what you need, it will not moan, and there it is.
|
||||
|
||||
// Substitute for the backing buffer's capacity
|
||||
CAPACITY = NODE ? 'this.buffer.length' : 'this.buffer.byteLength';
|
||||
|
||||
// Asserts that a variable is an integer
|
||||
ASSERT_INTEGER = function(varValue, unsigned) {
|
||||
if (VERBOSE_MS) writeln(__+'// <ASSERT_INTEGER>');
|
||||
if (INLINE) {
|
||||
writeln(__+'if (typeof '+varValue+' !== \'number\' || '+varValue+' % 1 !== 0)');
|
||||
writeln(__+' throw TypeError("Illegal '+varValue+': "+'+varValue+'+" (not an integer)");');
|
||||
writeln(__+varValue+' '+(unsigned ? '>>>' : '|')+'= 0;');
|
||||
} else {
|
||||
writeln(__+varValue+' = assertInteger('+varValue+(typeof unsigned !== 'undefined' ? ', '+unsigned : '')+');');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </ASSERT_INTEGER>');
|
||||
};
|
||||
|
||||
// Asserts that a variable is a number or Long
|
||||
ASSERT_LONG = function(varValue, unsigned) {
|
||||
if (typeof varValue === 'undefined') varValue = 'value';
|
||||
if (VERBOSE_MS) writeln(__+'// <ASSERT_LONG>');
|
||||
if (INLINE) {
|
||||
writeln(__+'if (typeof '+varValue+' === \'number\')');
|
||||
writeln(__+' '+varValue+' = Long.fromNumber('+varValue+');');
|
||||
writeln(__+'else if (typeof '+varValue+' === \'string\')');
|
||||
writeln(__+' '+varValue+' = Long.fromString('+varValue+');');
|
||||
if (typeof unsigned !== 'undefined') { // When explicitly specified only
|
||||
writeln(__+'else if ('+varValue+' && '+varValue+' instanceof Long)');
|
||||
if (unsigned) {
|
||||
writeln(__+' if (!'+varValue+'.unsigned) '+varValue+' = '+varValue+'.toUnsigned();');
|
||||
} else {
|
||||
writeln(__+' if ('+varValue+'.unsigned) '+varValue+' = '+varValue+'.toSigned();');
|
||||
}
|
||||
writeln(__+'else');
|
||||
} else {
|
||||
writeln(__+'else if (!('+varValue+' && '+varValue+' instanceof Long))');
|
||||
}
|
||||
writeln(__+' throw TypeError("Illegal '+varValue+': "+'+varValue+'+" (not an integer or Long)");');
|
||||
} else {
|
||||
writeln(__+varValue+' = assertLong('+varValue+(typeof unsigned !== 'undefined' ? ', '+unsigned : '')+');');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </ASSERT_LONG>');
|
||||
};
|
||||
|
||||
// Casts a variable to a Long if necessary
|
||||
LONG = function(varValue, unsigned) {
|
||||
if (typeof varValue === 'undefined') varValue = 'value';
|
||||
if (VERBOSE_MS) writeln(__+'// <LONG'+(typeof unsigned === 'boolean' ? ' unsigned='+unsigned : '')+'>');
|
||||
writeln(__+'if (typeof '+varValue+' === \'number\')');
|
||||
writeln(__+' '+varValue+' = Long.fromNumber('+varValue+(typeof unsigned === 'boolean' ? ', '+unsigned : '')+');');
|
||||
writeln(__+'else if (typeof '+varValue+' === \'string\')');
|
||||
writeln(__+' '+varValue+' = Long.fromString('+varValue+(typeof unsigned === 'boolean' ? ', '+unsigned : '')+');');
|
||||
if (typeof unsigned === 'boolean') {
|
||||
writeln(__+'else if ('+varValue+'.unsigned !== '+unsigned+') '+varValue+' = '+varValue+'.'+(unsigned ? 'toUnsigned' : 'toSigned')+'();');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </LONG>');
|
||||
};
|
||||
|
||||
// Asserts that an offset is valid
|
||||
ASSERT_OFFSET = function(size, varOffset) {
|
||||
if (typeof size === 'undefined') size = 0;
|
||||
if (typeof varOffset === 'undefined') varOffset = 'offset';
|
||||
if (VERBOSE_MS) writeln(__+'// <ASSERT_OFFSET>');
|
||||
if (INLINE) {
|
||||
writeln(__+'if (typeof '+varOffset+' !== \'number\' || '+varOffset+' % 1 !== 0)');
|
||||
writeln(__+' throw TypeError("Illegal '+varOffset+': "+'+varOffset+'+" (not an integer)");');
|
||||
writeln(__+varOffset+' >>>= 0;');
|
||||
writeln(__+'if ('+varOffset+' < 0 || '+varOffset+' + '+size+' > '+CAPACITY+')');
|
||||
writeln(__+' throw RangeError("Illegal '+varOffset+': 0 <= "+'+varOffset+'+" (+"+'+size+'+") <= "+'+CAPACITY+');');
|
||||
} else {
|
||||
writeln(__+varOffset+' = assertOffset('+varOffset+', 0, '+CAPACITY+', '+size+');');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </ASSERT_OFFSET>');
|
||||
};
|
||||
|
||||
// Asserts that a range is valid
|
||||
ASSERT_RANGE = function(varBegin, varEnd) {
|
||||
if (typeof varBegin === 'undefined') varBegin = 'begin';
|
||||
if (typeof varEnd === 'undefined') varEnd = 'end';
|
||||
if (VERBOSE_MS) writeln(__+'// <ASSERT_RANGE>');
|
||||
if (INLINE) {
|
||||
writeln(__+'if (typeof '+varBegin+' !== \'number\' || '+varBegin+' % 1 !== 0)');
|
||||
writeln(__+' throw TypeError("Illegal '+varBegin+': Not an integer");');
|
||||
writeln(__+varBegin+' >>>= 0;');
|
||||
writeln(__+'if (typeof '+varEnd+' !== \'number\' || '+varEnd+' % 1 !== 0)');
|
||||
writeln(__+' throw TypeError("Illegal '+varEnd+': Not an integer");');
|
||||
writeln(__+varEnd+' >>>= 0;');
|
||||
writeln(__+'if ('+varBegin+' < 0 || '+varBegin+' > '+varEnd+' || '+varEnd+' > '+CAPACITY+')');
|
||||
writeln(__+' throw RangeError("Illegal range: 0 <= "+'+varBegin+'+" <= "+'+varEnd+'+" <= "+'+CAPACITY+');');
|
||||
} else {
|
||||
writeln(__+'assertRange('+varBegin+', '+varEnd+', 0, '+CAPACITY+');');
|
||||
writeln(__+varBegin+' = rangeVal[0]; '+varEnd+' = rangeVal[1];');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </ASSERT_RANGE>');
|
||||
};
|
||||
|
||||
// ENSURE_CAPACITY counter in case that multiple calls are used in a single method
|
||||
var ECN = 0;
|
||||
|
||||
// Ensures that a ByteBuffer is backed by a buffer that takes `size` additional capacity
|
||||
ENSURE_CAPACITY = function(size, varOffset) {
|
||||
if (typeof varOffset === 'undefined') varOffset = 'offset';
|
||||
if (VERBOSE_MS) writeln(__+'// <ENSURE_CAPACITY size='+size+'>');
|
||||
if (INLINE) {
|
||||
writeln(__+varOffset+' += '+size+';');
|
||||
writeln(__+'var capacity'+ECN+' = '+CAPACITY+';');
|
||||
writeln(__+'if ('+varOffset+' > capacity'+ECN+')');
|
||||
writeln(__+' this.resize((capacity'+ECN+' *= 2) > '+varOffset+' ? capacity'+ECN+' : '+varOffset+');');
|
||||
writeln(__+varOffset+' -= '+size+';');
|
||||
} else {
|
||||
writeln(__+'this.ensureCapacity('+varOffset+'+'+size+');');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </ENSURE_CAPACITY>');
|
||||
++ECN;
|
||||
};
|
||||
|
||||
// Sets up a relative operation if `size` is omitted, else increases offset by `size`
|
||||
RELATIVE = function(size, varOffset, varRelOffset) {
|
||||
if (VERBOSE_MS) writeln(__+'// <RELATIVE'+(typeof size !== 'undefined' ? ' size='+size : '')+'>');
|
||||
if (typeof size === 'undefined') {
|
||||
if (typeof varOffset === 'undefined') varOffset = "offset";
|
||||
if (typeof varRelOffset === 'undefined') varRelOffset = "this.offset";
|
||||
writeln(__+'var relative = typeof '+varOffset+' === \'undefined\';');
|
||||
writeln(__+'if (relative) '+varOffset+' = '+varRelOffset+';');
|
||||
} else {
|
||||
if (typeof varOffset === 'undefined') varOffset = "this.offset";
|
||||
writeln(__+'if (relative) this.offset += '+size+';');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </RELATIVE>');
|
||||
};
|
||||
|
||||
// Reads an uint32 from an array
|
||||
READ_UINT32_ARRAY = function(varValue, varOffset, varTarget, varEndian) {
|
||||
if (typeof varValue === 'undefined') varValue = 'value';
|
||||
if (typeof varOffset === 'undefined') varOffset = 'offset';
|
||||
if (typeof varTarget === 'undefined') varTarget = NODE ? 'this.buffer' : 'this.view';
|
||||
var ____ = typeof varEndian !== 'boolean' ? ' ' : '';
|
||||
if (VERBOSE_MS) writeln(__+'// <READ_UINT32'+(typeof varEndian === 'boolean' ? ' le='+varEndian : '')+'>');
|
||||
if (NODE || !DATAVIEW) {
|
||||
if (typeof varEndian !== 'boolean')
|
||||
writeln(__+'if ('+(varEndian || 'this.littleEndian')+') {');
|
||||
if (typeof varEndian !== 'boolean' || varEndian === true) {
|
||||
writeln(__+____+varValue+' = '+varTarget+'['+varOffset+'+2] << 16;');
|
||||
writeln(__+____+varValue+' |= '+varTarget+'['+varOffset+'+1] << 8;');
|
||||
writeln(__+____+varValue+' |= '+varTarget+'['+varOffset+' ];');
|
||||
writeln(__+____+varValue+' += '+varTarget+'['+varOffset+'+3] << 24 >>> 0;');
|
||||
}
|
||||
if (typeof varEndian !== 'boolean')
|
||||
writeln(__+'} else {');
|
||||
if (typeof varEndian !== 'boolean' || varEndian === false) {
|
||||
writeln(__+____+varValue+' = '+varTarget+'['+varOffset+'+1] << 16;');
|
||||
writeln(__+____+varValue+' |= '+varTarget+'['+varOffset+'+2] << 8;');
|
||||
writeln(__+____+varValue+' |= '+varTarget+'['+varOffset+'+3];');
|
||||
writeln(__+____+varValue+' += '+varTarget+'['+varOffset+' ] << 24 >>> 0;');
|
||||
}
|
||||
if (typeof varEndian !== 'boolean')
|
||||
writeln(__+'}');
|
||||
} else {
|
||||
writeln(__+varTarget+'.getUint32('+varOffset+', '+varEndian+');');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </READ_UINT32>');
|
||||
};
|
||||
|
||||
// Writes an uint32 to an array
|
||||
WRITE_UINT32_ARRAY = function(varValue, varOffset, varTarget, varEndian) {
|
||||
if (typeof varValue === 'undefined') varValue = 'value';
|
||||
if (typeof varOffset === 'undefined') varOffset = 'offset';
|
||||
if (typeof varTarget === 'undefined') varTarget = NODE ? 'this.buffer' : 'this.view';
|
||||
var ____ = typeof varEndian !== 'boolean' ? ' ' : '';
|
||||
if (VERBOSE_MS) writeln(__+'// <WRITE_UINT32'+(typeof varEndian === 'boolean' ? ' le='+varEndian : '')+'>');
|
||||
if (NODE || !DATAVIEW) {
|
||||
if (typeof varEndian !== 'boolean')
|
||||
writeln(__+'if ('+(varEndian || 'this.littleEndian')+') {');
|
||||
if (typeof varEndian !== 'boolean' || varEndian === true) {
|
||||
writeln(__+____+varTarget+'['+varOffset+'+3] = ('+varValue+' >>> 24) & 0xFF;');
|
||||
writeln(__+____+varTarget+'['+varOffset+'+2] = ('+varValue+' >>> 16) & 0xFF;');
|
||||
writeln(__+____+varTarget+'['+varOffset+'+1] = ('+varValue+' >>> 8) & 0xFF;');
|
||||
writeln(__+____+varTarget+'['+varOffset+' ] = '+varValue+' & 0xFF;');
|
||||
}
|
||||
if (typeof varEndian !== 'boolean')
|
||||
writeln(__+'} else {');
|
||||
if (typeof varEndian !== 'boolean' || varEndian === false) {
|
||||
writeln(__+____+varTarget+'['+varOffset+' ] = ('+varValue+' >>> 24) & 0xFF;');
|
||||
writeln(__+____+varTarget+'['+varOffset+'+1] = ('+varValue+' >>> 16) & 0xFF;');
|
||||
writeln(__+____+varTarget+'['+varOffset+'+2] = ('+varValue+' >>> 8) & 0xFF;');
|
||||
writeln(__+____+varTarget+'['+varOffset+'+3] = '+varValue+' & 0xFF;');
|
||||
}
|
||||
if (typeof varEndian !== 'boolean')
|
||||
writeln(__+'}');
|
||||
} else {
|
||||
writeln(__+varTarget+'.setUint32('+varValue+', '+varOffset+', '+varEndian+');');
|
||||
}
|
||||
if (VERBOSE_MS) writeln(__+'// </WRITE_UINT32>');
|
||||
};
|
||||
|
||||
SET = function(varValue, varOffset, varTarget) { // with varTarget referencing a ByteBuffer
|
||||
if (typeof varValue === 'undefined') varValue = 'value';
|
||||
if (typeof varOffset === 'undefined') varOffset = 'offset';
|
||||
if (typeof varTarget === 'undefined') varTarget = 'this';
|
||||
if (NODE) {
|
||||
writeln(__+varTarget+'.buffer['+varOffset+'] = '+varValue+';');
|
||||
} else if (DATAVIEW) {
|
||||
writeln(__+varTarget+'.view.setUint8('+varValue+', '+varOffset+');');
|
||||
} else {
|
||||
writeln(__+varTarget+'.view['+varOffset+'] = '+varValue+';');
|
||||
}
|
||||
};
|
||||
|
||||
GET = function(varOffset, varTarget) { // with varTarget referencing a ByteBuffer
|
||||
if (typeof varOffset === 'undefined') varOffset = 'offset';
|
||||
if (typeof varTarget === 'undefined') varTarget = 'this';
|
||||
if (NODE) {
|
||||
write(varTarget+'.buffer['+varOffset+']');
|
||||
} else if (DATAVIEW) {
|
||||
write(varTarget+'.view.getUint8('+varOffset+')');
|
||||
} else {
|
||||
write(varTarget+'.view['+varOffset+']');
|
||||
}
|
||||
};
|
||||
//?.
|
58
node_modules/bytebuffer/src/methods/append.js
generated
vendored
Normal file
58
node_modules/bytebuffer/src/methods/append.js
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended
|
||||
* data's length.
|
||||
//? if (NODE) {
|
||||
* @param {!ByteBuffer|!Buffer|!ArrayBuffer|!Uint8Array|string} source Data to append. If `source` is a ByteBuffer, its
|
||||
* offsets will be modified according to the performed read operation.
|
||||
//? } else {
|
||||
* @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string} source Data to append. If `source` is a ByteBuffer, its offsets
|
||||
* will be modified according to the performed read operation.
|
||||
//? }
|
||||
* @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8")
|
||||
* @param {number=} offset Offset to append at. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
* @example A relative `<01 02>03.append(<04 05>)` will result in `<01 02 04 05>, 04 05|`
|
||||
* @example An absolute `<01 02>03.append(04 05>, 1)` will result in `<01 04>05, 04 05|`
|
||||
*/
|
||||
ByteBufferPrototype.append = function(source, encoding, offset) {
|
||||
if (typeof encoding === 'number' || typeof encoding !== 'string') {
|
||||
offset = encoding;
|
||||
encoding = undefined;
|
||||
}
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
if (!(source instanceof ByteBuffer))
|
||||
source = ByteBuffer.wrap(source, encoding);
|
||||
var length = source.limit - source.offset;
|
||||
if (length <= 0) return this; // Nothing to append
|
||||
//? ENSURE_CAPACITY('length');
|
||||
//? if (NODE)
|
||||
source.buffer.copy(this.buffer, offset, source.offset, source.limit);
|
||||
//? else if (DATAVIEW)
|
||||
new Uint8Array(this.buffer, offset).set(new Uint8Array(source.buffer).subarray(source.offset, source.limit));
|
||||
//? else
|
||||
this.view.set(source.view.subarray(source.offset, source.limit), offset);
|
||||
source.offset += length;
|
||||
//? RELATIVE('length');
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents at and after the
|
||||
specified offset up to the length of this ByteBuffer's data.
|
||||
* @param {!ByteBuffer} target Target ByteBuffer
|
||||
* @param {number=} offset Offset to append to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
* @see ByteBuffer#append
|
||||
*/
|
||||
ByteBufferPrototype.appendTo = function(target, offset) {
|
||||
target.append(this, offset);
|
||||
return this;
|
||||
};
|
||||
|
12
node_modules/bytebuffer/src/methods/assert.js
generated
vendored
Normal file
12
node_modules/bytebuffer/src/methods/assert.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Enables or disables assertions of argument types and offsets. Assertions are enabled by default but you can opt to
|
||||
* disable them if your code already makes sure that everything is valid.
|
||||
* @param {boolean} assert `true` to enable assertions, otherwise `false`
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.assert = function(assert) {
|
||||
this.noAssert = !assert;
|
||||
return this;
|
||||
};
|
||||
|
8
node_modules/bytebuffer/src/methods/capacity.js
generated
vendored
Normal file
8
node_modules/bytebuffer/src/methods/capacity.js
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Gets the capacity of this ByteBuffer's backing buffer.
|
||||
* @returns {number} Capacity of the backing buffer
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.capacity = function() {
|
||||
return /*?= CAPACITY */;
|
||||
};
|
13
node_modules/bytebuffer/src/methods/clear.js
generated
vendored
Normal file
13
node_modules/bytebuffer/src/methods/clear.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Clears this ByteBuffer's offsets by setting {@link ByteBuffer#offset} to `0` and {@link ByteBuffer#limit} to the
|
||||
* backing buffer's capacity. Discards {@link ByteBuffer#markedOffset}.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.clear = function() {
|
||||
this.offset = 0;
|
||||
this.limit = /*?= CAPACITY */;
|
||||
this.markedOffset = -1;
|
||||
return this;
|
||||
};
|
||||
|
34
node_modules/bytebuffer/src/methods/clone.js
generated
vendored
Normal file
34
node_modules/bytebuffer/src/methods/clone.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for {@link ByteBuffer#offset},
|
||||
* {@link ByteBuffer#markedOffset} and {@link ByteBuffer#limit}.
|
||||
* @param {boolean=} copy Whether to copy the backing buffer or to return another view on the same, defaults to `false`
|
||||
* @returns {!ByteBuffer} Cloned instance
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.clone = function(copy) {
|
||||
var bb = new ByteBuffer(0, this.littleEndian, this.noAssert);
|
||||
if (copy) {
|
||||
//? if (NODE) {
|
||||
var buffer = new Buffer(this.buffer.length);
|
||||
this.buffer.copy(buffer);
|
||||
bb.buffer = buffer;
|
||||
//? } else {
|
||||
bb.buffer = new ArrayBuffer(this.buffer.byteLength);
|
||||
//? if (DATAVIEW) {
|
||||
new Uint8Array(bb.buffer).set(this.buffer);
|
||||
bb.view = new DataView(bb.buffer);
|
||||
//? } else {
|
||||
bb.view = new Uint8Array(bb.buffer);
|
||||
//? }
|
||||
//? }
|
||||
} else {
|
||||
bb.buffer = this.buffer;
|
||||
//? if (!NODE)
|
||||
bb.view = this.view;
|
||||
}
|
||||
bb.offset = this.offset;
|
||||
bb.markedOffset = this.markedOffset;
|
||||
bb.limit = this.limit;
|
||||
return bb;
|
||||
};
|
||||
|
49
node_modules/bytebuffer/src/methods/compact.js
generated
vendored
Normal file
49
node_modules/bytebuffer/src/methods/compact.js
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Compacts this ByteBuffer to be backed by a {@link ByteBuffer#buffer} of its contents' length. Contents are the bytes
|
||||
* between {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. Will set `offset = 0` and `limit = capacity` and
|
||||
* adapt {@link ByteBuffer#markedOffset} to the same relative position if set.
|
||||
* @param {number=} begin Offset to start at, defaults to {@link ByteBuffer#offset}
|
||||
* @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.compact = function(begin, end) {
|
||||
if (typeof begin === 'undefined') begin = this.offset;
|
||||
if (typeof end === 'undefined') end = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE();
|
||||
}
|
||||
if (begin === 0 && end === /*?= CAPACITY */)
|
||||
return this; // Already compacted
|
||||
var len = end - begin;
|
||||
if (len === 0) {
|
||||
this.buffer = EMPTY_BUFFER;
|
||||
//? if (!NODE)
|
||||
this.view = null;
|
||||
if (this.markedOffset >= 0) this.markedOffset -= begin;
|
||||
this.offset = 0;
|
||||
this.limit = 0;
|
||||
return this;
|
||||
}
|
||||
//? if (NODE) {
|
||||
var buffer = new Buffer(len);
|
||||
this.buffer.copy(buffer, 0, begin, end);
|
||||
this.buffer = buffer;
|
||||
//? } else if (DATAVIEW) {
|
||||
var buffer = new ArrayBuffer(len);
|
||||
new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(begin, end));
|
||||
this.buffer = buffer;
|
||||
this.view = new DataView(buffer);
|
||||
//? } else {
|
||||
var buffer = new ArrayBuffer(len);
|
||||
var view = new Uint8Array(buffer);
|
||||
view.set(this.view.subarray(begin, end));
|
||||
this.buffer = buffer;
|
||||
this.view = view;
|
||||
//? }
|
||||
if (this.markedOffset >= 0) this.markedOffset -= begin;
|
||||
this.offset = 0;
|
||||
this.limit = len;
|
||||
return this;
|
||||
};
|
||||
|
73
node_modules/bytebuffer/src/methods/copy.js
generated
vendored
Normal file
73
node_modules/bytebuffer/src/methods/copy.js
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Creates a copy of this ByteBuffer's contents. Contents are the bytes between {@link ByteBuffer#offset} and
|
||||
* {@link ByteBuffer#limit}.
|
||||
* @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}.
|
||||
* @param {number=} end End offset, defaults to {@link ByteBuffer#limit}.
|
||||
* @returns {!ByteBuffer} Copy
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.copy = function(begin, end) {
|
||||
if (typeof begin === 'undefined') begin = this.offset;
|
||||
if (typeof end === 'undefined') end = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE();
|
||||
}
|
||||
if (begin === end)
|
||||
return new ByteBuffer(0, this.littleEndian, this.noAssert);
|
||||
var capacity = end - begin,
|
||||
bb = new ByteBuffer(capacity, this.littleEndian, this.noAssert);
|
||||
bb.offset = 0;
|
||||
bb.limit = capacity;
|
||||
if (bb.markedOffset >= 0) bb.markedOffset -= begin;
|
||||
this.copyTo(bb, 0, begin, end);
|
||||
return bb;
|
||||
};
|
||||
|
||||
/**
|
||||
* Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between {@link ByteBuffer#offset} and
|
||||
* {@link ByteBuffer#limit}.
|
||||
* @param {!ByteBuffer} target Target ByteBuffer
|
||||
* @param {number=} targetOffset Offset to copy to. Will use and increase the target's {@link ByteBuffer#offset}
|
||||
* by the number of bytes copied if omitted.
|
||||
* @param {number=} sourceOffset Offset to start copying from. Will use and increase {@link ByteBuffer#offset} by the
|
||||
* number of bytes copied if omitted.
|
||||
* @param {number=} sourceLimit Offset to end copying from, defaults to {@link ByteBuffer#limit}
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.copyTo = function(target, targetOffset, sourceOffset, sourceLimit) {
|
||||
var relative,
|
||||
targetRelative;
|
||||
if (!this.noAssert) {
|
||||
if (!ByteBuffer.isByteBuffer(target))
|
||||
throw TypeError("Illegal target: Not a ByteBuffer");
|
||||
}
|
||||
targetOffset = (targetRelative = typeof targetOffset === 'undefined') ? target.offset : targetOffset | 0;
|
||||
sourceOffset = (relative = typeof sourceOffset === 'undefined') ? this.offset : sourceOffset | 0;
|
||||
sourceLimit = typeof sourceLimit === 'undefined' ? this.limit : sourceLimit | 0;
|
||||
|
||||
//? var TARGET_CAPACITY = NODE ? 'target.buffer.length' : 'target.buffer.byteLength';
|
||||
if (targetOffset < 0 || targetOffset > /*?= TARGET_CAPACITY */)
|
||||
throw RangeError("Illegal target range: 0 <= "+targetOffset+" <= "+/*?= TARGET_CAPACITY */);
|
||||
if (sourceOffset < 0 || sourceLimit > /*?= CAPACITY */)
|
||||
throw RangeError("Illegal source range: 0 <= "+sourceOffset+" <= "+/*?= CAPACITY */);
|
||||
|
||||
var len = sourceLimit - sourceOffset;
|
||||
if (len === 0)
|
||||
return target; // Nothing to copy
|
||||
|
||||
target.ensureCapacity(targetOffset + len);
|
||||
|
||||
//? if (NODE)
|
||||
this.buffer.copy(target.buffer, targetOffset, sourceOffset, sourceLimit);
|
||||
//? else if (DATAVIEW)
|
||||
new Uint8Array(target.buffer).set(new Uint8Array(this.buffer).subarray(sourceOffset, sourceLimit), targetOffset);
|
||||
//? else
|
||||
target.view.set(this.view.subarray(sourceOffset, sourceLimit), targetOffset);
|
||||
|
||||
if (relative) this.offset += len;
|
||||
if (targetRelative) target.offset += len;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
15
node_modules/bytebuffer/src/methods/ensureCapacity.js
generated
vendored
Normal file
15
node_modules/bytebuffer/src/methods/ensureCapacity.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Makes sure that this ByteBuffer is backed by a {@link ByteBuffer#buffer} of at least the specified capacity. If the
|
||||
* current capacity is exceeded, it will be doubled. If double the current capacity is less than the required capacity,
|
||||
* the required capacity will be used instead.
|
||||
* @param {number} capacity Required capacity
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.ensureCapacity = function(capacity) {
|
||||
var current = /*?= CAPACITY */;
|
||||
if (current < capacity)
|
||||
return this.resize((current *= 2) > capacity ? current : capacity);
|
||||
return this;
|
||||
};
|
||||
|
35
node_modules/bytebuffer/src/methods/fill.js
generated
vendored
Normal file
35
node_modules/bytebuffer/src/methods/fill.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between
|
||||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.
|
||||
* @param {number|string} value Byte value to fill with. If given as a string, the first character is used.
|
||||
* @param {number=} begin Begin offset. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted. defaults to {@link ByteBuffer#offset}.
|
||||
* @param {number=} end End offset, defaults to {@link ByteBuffer#limit}.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
* @example `someByteBuffer.clear().fill(0)` fills the entire backing buffer with zeroes
|
||||
*/
|
||||
ByteBufferPrototype.fill = function(value, begin, end) {
|
||||
//? RELATIVE(undefined, 'begin');
|
||||
if (typeof value === 'string' && value.length > 0)
|
||||
value = value.charCodeAt(0);
|
||||
if (typeof begin === 'undefined') begin = this.offset;
|
||||
if (typeof end === 'undefined') end = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value');
|
||||
//? ASSERT_RANGE();
|
||||
}
|
||||
if (begin >= end)
|
||||
return this; // Nothing to fill
|
||||
//? if (NODE) {
|
||||
this.buffer.fill(value, begin, end);
|
||||
begin = end;
|
||||
//? } else if (DATAVIEW) {
|
||||
while (begin < end) this.view.setUint8(begin++, value);
|
||||
//? } else {
|
||||
while (begin < end) this.view[begin++] = value;
|
||||
//? }
|
||||
if (relative) this.offset = begin;
|
||||
return this;
|
||||
};
|
||||
|
11
node_modules/bytebuffer/src/methods/flip.js
generated
vendored
Normal file
11
node_modules/bytebuffer/src/methods/flip.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Makes this ByteBuffer ready for a new sequence of write or relative read operations. Sets `limit = offset` and
|
||||
* `offset = 0`. Make sure always to flip a ByteBuffer when all relative read or write operations are complete.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.flip = function() {
|
||||
this.limit = this.offset;
|
||||
this.offset = 0;
|
||||
return this;
|
||||
};
|
17
node_modules/bytebuffer/src/methods/mark.js
generated
vendored
Normal file
17
node_modules/bytebuffer/src/methods/mark.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Marks an offset on this ByteBuffer to be used later.
|
||||
* @param {number=} offset Offset to mark. Defaults to {@link ByteBuffer#offset}.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @throws {TypeError} If `offset` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @see ByteBuffer#reset
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.mark = function(offset) {
|
||||
offset = typeof offset === 'undefined' ? this.offset : offset;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
this.markedOffset = offset;
|
||||
return this;
|
||||
};
|
36
node_modules/bytebuffer/src/methods/order.js
generated
vendored
Normal file
36
node_modules/bytebuffer/src/methods/order.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Sets the byte order.
|
||||
* @param {boolean} littleEndian `true` for little endian byte order, `false` for big endian
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.order = function(littleEndian) {
|
||||
if (!this.noAssert) {
|
||||
if (typeof littleEndian !== 'boolean')
|
||||
throw TypeError("Illegal littleEndian: Not a boolean");
|
||||
}
|
||||
this.littleEndian = !!littleEndian;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Switches (to) little endian byte order.
|
||||
* @param {boolean=} littleEndian Defaults to `true`, otherwise uses big endian
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.LE = function(littleEndian) {
|
||||
this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Switches (to) big endian byte order.
|
||||
* @param {boolean=} bigEndian Defaults to `true`, otherwise uses little endian
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.BE = function(bigEndian) {
|
||||
this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false;
|
||||
return this;
|
||||
};
|
87
node_modules/bytebuffer/src/methods/prepend.js
generated
vendored
Normal file
87
node_modules/bytebuffer/src/methods/prepend.js
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Prepends some data to this ByteBuffer. This will overwrite any contents before the specified offset up to the
|
||||
* prepended data's length. If there is not enough space available before the specified `offset`, the backing buffer
|
||||
* will be resized and its contents moved accordingly.
|
||||
//? if (NODE) {
|
||||
* @param {!ByteBuffer|string||!Buffer} source Data to prepend. If `source` is a ByteBuffer, its offset will be modified
|
||||
* according to the performed read operation.
|
||||
//? } else {
|
||||
* @param {!ByteBuffer|string|!ArrayBuffer} source Data to prepend. If `source` is a ByteBuffer, its offset will be
|
||||
* modified according to the performed read operation.
|
||||
//? }
|
||||
* @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8")
|
||||
* @param {number=} offset Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes
|
||||
* prepended if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
* @example A relative `00<01 02 03>.prepend(<04 05>)` results in `<04 05 01 02 03>, 04 05|`
|
||||
* @example An absolute `00<01 02 03>.prepend(<04 05>, 2)` results in `04<05 02 03>, 04 05|`
|
||||
*/
|
||||
ByteBufferPrototype.prepend = function(source, encoding, offset) {
|
||||
if (typeof encoding === 'number' || typeof encoding !== 'string') {
|
||||
offset = encoding;
|
||||
encoding = undefined;
|
||||
}
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
if (!(source instanceof ByteBuffer))
|
||||
source = ByteBuffer.wrap(source, encoding);
|
||||
var len = source.limit - source.offset;
|
||||
if (len <= 0) return this; // Nothing to prepend
|
||||
var diff = len - offset;
|
||||
if (diff > 0) { // Not enough space before offset, so resize + move
|
||||
//? if (NODE) {
|
||||
var buffer = new Buffer(this.buffer.length + diff);
|
||||
this.buffer.copy(buffer, len, offset, this.buffer.length);
|
||||
this.buffer = buffer;
|
||||
//? } else if (DATAVIEW) {
|
||||
var buffer = new ArrayBuffer(this.buffer.byteLength + diff);
|
||||
var arrayView = new Uint8Array(buffer);
|
||||
arrayView.set(new Uint8Array(this.buffer).subarray(offset, this.buffer.byteLength), len);
|
||||
this.buffer = buffer;
|
||||
this.view = new DataView(buffer);
|
||||
//? } else {
|
||||
var buffer = new ArrayBuffer(this.buffer.byteLength + diff);
|
||||
var view = new Uint8Array(buffer);
|
||||
view.set(this.view.subarray(offset, this.buffer.byteLength), len);
|
||||
this.buffer = buffer;
|
||||
this.view = view;
|
||||
//? }
|
||||
this.offset += diff;
|
||||
if (this.markedOffset >= 0) this.markedOffset += diff;
|
||||
this.limit += diff;
|
||||
offset += diff;
|
||||
}/*? if (!NODE) { */ else {
|
||||
var arrayView = new Uint8Array(this.buffer);
|
||||
}
|
||||
//? }
|
||||
//? if (NODE)
|
||||
source.buffer.copy(this.buffer, offset - len, source.offset, source.limit);
|
||||
//? else if (DATAVIEW)
|
||||
arrayView.set(new Uint8Array(source.buffer).subarray(source.offset, source.limit), offset - len);
|
||||
//? else
|
||||
this.view.set(source.view.subarray(source.offset, source.limit), offset - len);
|
||||
|
||||
source.offset = source.limit;
|
||||
if (relative)
|
||||
this.offset -= len;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepends this ByteBuffer to another ByteBuffer. This will overwrite any contents before the specified offset up to the
|
||||
* prepended data's length. If there is not enough space available before the specified `offset`, the backing buffer
|
||||
* will be resized and its contents moved accordingly.
|
||||
* @param {!ByteBuffer} target Target ByteBuffer
|
||||
* @param {number=} offset Offset to prepend at. Will use and decrease {@link ByteBuffer#offset} by the number of bytes
|
||||
* prepended if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
* @see ByteBuffer#prepend
|
||||
*/
|
||||
ByteBufferPrototype.prependTo = function(target, offset) {
|
||||
target.prepend(this, offset);
|
||||
return this;
|
||||
};
|
16
node_modules/bytebuffer/src/methods/printDebug.js
generated
vendored
Normal file
16
node_modules/bytebuffer/src/methods/printDebug.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
//? if (DEBUG) {
|
||||
/**
|
||||
* Prints debug information about this ByteBuffer's contents.
|
||||
* @param {function(string)=} out Output function to call, defaults to console.log
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.printDebug = function(out) {
|
||||
if (typeof out !== 'function') out = console.log.bind(console);
|
||||
out(
|
||||
this.toString()+"\n"+
|
||||
"-------------------------------------------------------------------\n"+
|
||||
this.toDebug(/* columns */ true)
|
||||
);
|
||||
};
|
||||
|
||||
//? }
|
9
node_modules/bytebuffer/src/methods/remaining.js
generated
vendored
Normal file
9
node_modules/bytebuffer/src/methods/remaining.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Gets the number of remaining readable bytes. Contents are the bytes between {@link ByteBuffer#offset} and
|
||||
* {@link ByteBuffer#limit}, so this returns `limit - offset`.
|
||||
* @returns {number} Remaining readable bytes. May be negative if `offset > limit`.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.remaining = function() {
|
||||
return this.limit - this.offset;
|
||||
};
|
17
node_modules/bytebuffer/src/methods/reset.js
generated
vendored
Normal file
17
node_modules/bytebuffer/src/methods/reset.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Resets this ByteBuffer's {@link ByteBuffer#offset}. If an offset has been marked through {@link ByteBuffer#mark}
|
||||
* before, `offset` will be set to {@link ByteBuffer#markedOffset}, which will then be discarded. If no offset has been
|
||||
* marked, sets `offset = 0`.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @see ByteBuffer#mark
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.reset = function() {
|
||||
if (this.markedOffset >= 0) {
|
||||
this.offset = this.markedOffset;
|
||||
this.markedOffset = -1;
|
||||
} else {
|
||||
this.offset = 0;
|
||||
}
|
||||
return this;
|
||||
};
|
39
node_modules/bytebuffer/src/methods/resize.js
generated
vendored
Normal file
39
node_modules/bytebuffer/src/methods/resize.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Resizes this ByteBuffer to be backed by a buffer of at least the given capacity. Will do nothing if already that
|
||||
* large or larger.
|
||||
* @param {number} capacity Capacity required
|
||||
* @returns {!ByteBuffer} this
|
||||
* @throws {TypeError} If `capacity` is not a number
|
||||
* @throws {RangeError} If `capacity < 0`
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.resize = function(capacity) {
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('capacity');
|
||||
if (capacity < 0)
|
||||
throw RangeError("Illegal capacity: 0 <= "+capacity);
|
||||
}
|
||||
//? if (NODE) {
|
||||
if (this.buffer.length < capacity) {
|
||||
var buffer = new Buffer(capacity);
|
||||
this.buffer.copy(buffer);
|
||||
this.buffer = buffer;
|
||||
}
|
||||
//? } else {
|
||||
if (this.buffer.byteLength < capacity) {
|
||||
//? if (DATAVIEW) {
|
||||
var buffer = new ArrayBuffer(capacity);
|
||||
new Uint8Array(buffer).set(new Uint8Array(this.buffer));
|
||||
this.buffer = buffer;
|
||||
this.view = new DataView(buffer);
|
||||
//? } else {
|
||||
var buffer = new ArrayBuffer(capacity);
|
||||
var view = new Uint8Array(buffer);
|
||||
view.set(this.view);
|
||||
this.buffer = buffer;
|
||||
this.view = view;
|
||||
//? }
|
||||
}
|
||||
//? }
|
||||
return this;
|
||||
};
|
25
node_modules/bytebuffer/src/methods/reverse.js
generated
vendored
Normal file
25
node_modules/bytebuffer/src/methods/reverse.js
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Reverses this ByteBuffer's contents.
|
||||
* @param {number=} begin Offset to start at, defaults to {@link ByteBuffer#offset}
|
||||
* @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.reverse = function(begin, end) {
|
||||
if (typeof begin === 'undefined') begin = this.offset;
|
||||
if (typeof end === 'undefined') end = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE();
|
||||
}
|
||||
if (begin === end)
|
||||
return this; // Nothing to reverse
|
||||
//? if (NODE)
|
||||
Array.prototype.reverse.call(this.buffer.slice(begin, end));
|
||||
//? else if (DATAVIEW) {
|
||||
Array.prototype.reverse.call(new Uint8Array(this.buffer).subarray(begin, end));
|
||||
this.view = new DataView(this.buffer); // FIXME: Why exactly is this necessary?
|
||||
//? } else {
|
||||
Array.prototype.reverse.call(this.view.subarray(begin, end));
|
||||
//? }
|
||||
return this;
|
||||
};
|
19
node_modules/bytebuffer/src/methods/skip.js
generated
vendored
Normal file
19
node_modules/bytebuffer/src/methods/skip.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Skips the next `length` bytes. This will just advance
|
||||
* @param {number} length Number of bytes to skip. May also be negative to move the offset back.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.skip = function(length) {
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('length');
|
||||
}
|
||||
var offset = this.offset + length;
|
||||
if (!this.noAssert) {
|
||||
if (offset < 0 || offset > /*?= CAPACITY */)
|
||||
throw RangeError("Illegal length: 0 <= "+this.offset+" + "+length+" <= "+/*?= CAPACITY */);
|
||||
}
|
||||
this.offset = offset;
|
||||
return this;
|
||||
};
|
||||
|
18
node_modules/bytebuffer/src/methods/slice.js
generated
vendored
Normal file
18
node_modules/bytebuffer/src/methods/slice.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Slices this ByteBuffer by creating a cloned instance with `offset = begin` and `limit = end`.
|
||||
* @param {number=} begin Begin offset, defaults to {@link ByteBuffer#offset}.
|
||||
* @param {number=} end End offset, defaults to {@link ByteBuffer#limit}.
|
||||
* @returns {!ByteBuffer} Clone of this ByteBuffer with slicing applied, backed by the same {@link ByteBuffer#buffer}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.slice = function(begin, end) {
|
||||
if (typeof begin === 'undefined') begin = this.offset;
|
||||
if (typeof end === 'undefined') end = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE();
|
||||
}
|
||||
var bb = this.clone();
|
||||
bb.offset = begin;
|
||||
bb.limit = end;
|
||||
return bb;
|
||||
};
|
13
node_modules/bytebuffer/src/methods/static/accessor.js
generated
vendored
Normal file
13
node_modules/bytebuffer/src/methods/static/accessor.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Gets the accessor type.
|
||||
* @returns {Function} `Buffer` under node.js, `Uint8Array` respectively `DataView` in the browser (classes)
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.accessor = function() {
|
||||
//? if (NODE)
|
||||
return Buffer;
|
||||
//? else if (DATAVIEW)
|
||||
return DataView;
|
||||
//? else
|
||||
return Uint8Array;
|
||||
};
|
14
node_modules/bytebuffer/src/methods/static/allocate.js
generated
vendored
Normal file
14
node_modules/bytebuffer/src/methods/static/allocate.js
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Allocates a new ByteBuffer backed by a buffer of the specified capacity.
|
||||
* @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}.
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_NOASSERT}.
|
||||
* @returns {!ByteBuffer}
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.allocate = function(capacity, littleEndian, noAssert) {
|
||||
return new ByteBuffer(capacity, littleEndian, noAssert);
|
||||
};
|
||||
|
55
node_modules/bytebuffer/src/methods/static/concat.js
generated
vendored
Normal file
55
node_modules/bytebuffer/src/methods/static/concat.js
generated
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Concatenates multiple ByteBuffers into one.
|
||||
//? if (NODE) {
|
||||
* @param {!Array.<!ByteBuffer|!Buffer|!ArrayBuffer|!Uint8Array|string>} buffers Buffers to concatenate
|
||||
//? } else {
|
||||
* @param {!Array.<!ByteBuffer|!ArrayBuffer|!Uint8Array|string>} buffers Buffers to concatenate
|
||||
//? }
|
||||
* @param {(string|boolean)=} encoding String encoding if `buffers` contains a string ("base64", "hex", "binary",
|
||||
* defaults to "utf8")
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order for the resulting ByteBuffer. Defaults
|
||||
* to {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @param {boolean=} noAssert Whether to skip assertions of offsets and values for the resulting ByteBuffer. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_NOASSERT}.
|
||||
* @returns {!ByteBuffer} Concatenated ByteBuffer
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.concat = function(buffers, encoding, littleEndian, noAssert) {
|
||||
if (typeof encoding === 'boolean' || typeof encoding !== 'string') {
|
||||
noAssert = littleEndian;
|
||||
littleEndian = encoding;
|
||||
encoding = undefined;
|
||||
}
|
||||
var capacity = 0;
|
||||
for (var i=0, k=buffers.length, length; i<k; ++i) {
|
||||
if (!ByteBuffer.isByteBuffer(buffers[i]))
|
||||
buffers[i] = ByteBuffer.wrap(buffers[i], encoding);
|
||||
length = buffers[i].limit - buffers[i].offset;
|
||||
if (length > 0) capacity += length;
|
||||
}
|
||||
if (capacity === 0)
|
||||
return new ByteBuffer(0, littleEndian, noAssert);
|
||||
var bb = new ByteBuffer(capacity, littleEndian, noAssert),
|
||||
bi;
|
||||
//? if (!NODE && DATAVIEW)
|
||||
var view = new Uint8Array(bb.buffer);
|
||||
i=0; while (i<k) {
|
||||
bi = buffers[i++];
|
||||
length = bi.limit - bi.offset;
|
||||
if (length <= 0) continue;
|
||||
//? if (NODE) {
|
||||
bi.buffer.copy(bb.buffer, bb.offset, bi.offset, bi.limit);
|
||||
bb.offset += length;
|
||||
//? } else {
|
||||
//? if (DATAVIEW)
|
||||
view.set(new Uint8Array(bi.buffer).subarray(bi.offset, bi.limit), bb.offset);
|
||||
//? else
|
||||
bb.view.set(bi.view.subarray(bi.offset, bi.limit), bb.offset);
|
||||
bb.offset += length;
|
||||
//? }
|
||||
}
|
||||
bb.limit = bb.offset;
|
||||
bb.offset = 0;
|
||||
return bb;
|
||||
};
|
||||
|
9
node_modules/bytebuffer/src/methods/static/isByteBuffer.js
generated
vendored
Normal file
9
node_modules/bytebuffer/src/methods/static/isByteBuffer.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Tests if the specified type is a ByteBuffer.
|
||||
* @param {*} bb ByteBuffer to test
|
||||
* @returns {boolean} `true` if it is a ByteBuffer, otherwise `false`
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.isByteBuffer = function(bb) {
|
||||
return (bb && bb["__isByteBuffer__"]) === true;
|
||||
};
|
11
node_modules/bytebuffer/src/methods/static/type.js
generated
vendored
Normal file
11
node_modules/bytebuffer/src/methods/static/type.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Gets the backing buffer type.
|
||||
* @returns {Function} `Buffer` under node.js, `ArrayBuffer` in the browser (classes)
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.type = function() {
|
||||
//? if (NODE)
|
||||
return Buffer;
|
||||
//? else
|
||||
return ArrayBuffer;
|
||||
};
|
125
node_modules/bytebuffer/src/methods/static/wrap.js
generated
vendored
Normal file
125
node_modules/bytebuffer/src/methods/static/wrap.js
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
/**
|
||||
* Wraps a buffer or a string. Sets the allocated ByteBuffer's {@link ByteBuffer#offset} to `0` and its
|
||||
* {@link ByteBuffer#limit} to the length of the wrapped data.
|
||||
//? if (NODE) {
|
||||
* @param {!ByteBuffer|!Buffer|!ArrayBuffer|!Uint8Array|string|!Array.<number>} buffer Anything that can be wrapped
|
||||
//? } else {
|
||||
* @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string|!Array.<number>} buffer Anything that can be wrapped
|
||||
//? }
|
||||
* @param {(string|boolean)=} encoding String encoding if `buffer` is a string ("base64", "hex", "binary", defaults to
|
||||
* "utf8")
|
||||
* @param {boolean=} littleEndian Whether to use little or big endian byte order. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_ENDIAN}.
|
||||
* @param {boolean=} noAssert Whether to skip assertions of offsets and values. Defaults to
|
||||
* {@link ByteBuffer.DEFAULT_NOASSERT}.
|
||||
* @returns {!ByteBuffer} A ByteBuffer wrapping `buffer`
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.wrap = function(buffer, encoding, littleEndian, noAssert) {
|
||||
if (typeof encoding !== 'string') {
|
||||
noAssert = littleEndian;
|
||||
littleEndian = encoding;
|
||||
encoding = undefined;
|
||||
}
|
||||
if (typeof buffer === 'string') {
|
||||
if (typeof encoding === 'undefined')
|
||||
encoding = "utf8";
|
||||
switch (encoding) {
|
||||
//? if (BASE64) {
|
||||
case "base64":
|
||||
return ByteBuffer.fromBase64(buffer, littleEndian);
|
||||
//? } if (HEX) {
|
||||
case "hex":
|
||||
return ByteBuffer.fromHex(buffer, littleEndian);
|
||||
//? } if (BINARY) {
|
||||
case "binary":
|
||||
return ByteBuffer.fromBinary(buffer, littleEndian);
|
||||
//? } if (UTF8) {
|
||||
case "utf8":
|
||||
return ByteBuffer.fromUTF8(buffer, littleEndian);
|
||||
//? } if (DEBUG) {
|
||||
case "debug":
|
||||
return ByteBuffer.fromDebug(buffer, littleEndian);
|
||||
//? }
|
||||
default:
|
||||
throw Error("Unsupported encoding: "+encoding);
|
||||
}
|
||||
}
|
||||
if (buffer === null || typeof buffer !== 'object')
|
||||
throw TypeError("Illegal buffer");
|
||||
var bb;
|
||||
if (ByteBuffer.isByteBuffer(buffer)) {
|
||||
bb = ByteBufferPrototype.clone.call(buffer);
|
||||
bb.markedOffset = -1;
|
||||
return bb;
|
||||
}
|
||||
//? if (NODE) {
|
||||
var i = 0,
|
||||
k = 0,
|
||||
b;
|
||||
if (buffer instanceof Uint8Array) { // Extract bytes from Uint8Array
|
||||
b = new Buffer(buffer.length);
|
||||
if (memcpy) { // Fast
|
||||
memcpy(b, 0, buffer.buffer, buffer.byteOffset, buffer.byteOffset + buffer.length);
|
||||
} else { // Slow
|
||||
for (i=0, k=buffer.length; i<k; ++i)
|
||||
b[i] = buffer[i];
|
||||
}
|
||||
buffer = b;
|
||||
} else if (buffer instanceof ArrayBuffer) { // Convert ArrayBuffer to Buffer
|
||||
b = new Buffer(buffer.byteLength);
|
||||
if (memcpy) { // Fast
|
||||
memcpy(b, 0, buffer, 0, buffer.byteLength);
|
||||
} else { // Slow
|
||||
buffer = new Uint8Array(buffer);
|
||||
for (i=0, k=buffer.length; i<k; ++i) {
|
||||
b[i] = buffer[i];
|
||||
}
|
||||
}
|
||||
buffer = b;
|
||||
} else if (!(buffer instanceof Buffer)) { // Create from octets if it is an error, otherwise fail
|
||||
if (Object.prototype.toString.call(buffer) !== "[object Array]")
|
||||
throw TypeError("Illegal buffer");
|
||||
buffer = new Buffer(buffer);
|
||||
}
|
||||
bb = new ByteBuffer(0, littleEndian, noAssert);
|
||||
if (buffer.length > 0) { // Avoid references to more than one EMPTY_BUFFER
|
||||
bb.buffer = buffer;
|
||||
bb.limit = buffer.length;
|
||||
}
|
||||
//? } else {
|
||||
if (buffer instanceof Uint8Array) { // Extract ArrayBuffer from Uint8Array
|
||||
bb = new ByteBuffer(0, littleEndian, noAssert);
|
||||
if (buffer.length > 0) { // Avoid references to more than one EMPTY_BUFFER
|
||||
bb.buffer = buffer.buffer;
|
||||
bb.offset = buffer.byteOffset;
|
||||
bb.limit = buffer.byteOffset + buffer.byteLength;
|
||||
//? if (DATAVIEW)
|
||||
bb.view = new DataView(buffer.buffer);
|
||||
//? else
|
||||
bb.view = new Uint8Array(buffer.buffer);
|
||||
}
|
||||
} else if (buffer instanceof ArrayBuffer) { // Reuse ArrayBuffer
|
||||
bb = new ByteBuffer(0, littleEndian, noAssert);
|
||||
if (buffer.byteLength > 0) {
|
||||
bb.buffer = buffer;
|
||||
bb.offset = 0;
|
||||
bb.limit = buffer.byteLength;
|
||||
//? if (DATAVIEW)
|
||||
bb.view = buffer.byteLength > 0 ? new DataView(buffer) : null;
|
||||
//? else
|
||||
bb.view = buffer.byteLength > 0 ? new Uint8Array(buffer) : null;
|
||||
}
|
||||
} else if (Object.prototype.toString.call(buffer) === "[object Array]") { // Create from octets
|
||||
bb = new ByteBuffer(buffer.length, littleEndian, noAssert);
|
||||
bb.limit = buffer.length;
|
||||
for (var i=0; i<buffer.length; ++i)
|
||||
//? if (DATAVIEW)
|
||||
bb.view.setUint8(i, buffer[i]);
|
||||
//? else
|
||||
bb.view[i] = buffer[i];
|
||||
} else
|
||||
throw TypeError("Illegal buffer"); // Otherwise fail
|
||||
//? }
|
||||
return bb;
|
||||
};
|
77
node_modules/bytebuffer/src/methods/toBuffer.js
generated
vendored
Normal file
77
node_modules/bytebuffer/src/methods/toBuffer.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between
|
||||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.
|
||||
* @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory if
|
||||
* possible. Defaults to `false`
|
||||
//? if (NODE) {
|
||||
* @returns {!Buffer} Contents as a Buffer
|
||||
//? } else {
|
||||
* @returns {!ArrayBuffer} Contents as an ArrayBuffer
|
||||
//? }
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.toBuffer = function(forceCopy) {
|
||||
var offset = this.offset,
|
||||
limit = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE('offset', 'limit');
|
||||
}
|
||||
//? if (NODE) {
|
||||
if (forceCopy) {
|
||||
var buffer = new Buffer(limit - offset);
|
||||
this.buffer.copy(buffer, 0, offset, limit);
|
||||
return buffer;
|
||||
} else {
|
||||
if (offset === 0 && limit === this.buffer.length)
|
||||
return this.buffer;
|
||||
else
|
||||
return this.buffer.slice(offset, limit);
|
||||
}
|
||||
//? } else {
|
||||
// NOTE: It's not possible to have another ArrayBuffer reference the same memory as the backing buffer. This is
|
||||
// possible with Uint8Array#subarray only, but we have to return an ArrayBuffer by contract. So:
|
||||
if (!forceCopy && offset === 0 && limit === this.buffer.byteLength)
|
||||
return this.buffer;
|
||||
if (offset === limit)
|
||||
return EMPTY_BUFFER;
|
||||
var buffer = new ArrayBuffer(limit - offset);
|
||||
new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(offset, limit), 0);
|
||||
return buffer;
|
||||
//? }
|
||||
};
|
||||
|
||||
//? if (NODE) {
|
||||
/**
|
||||
* Returns a copy of the backing buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between
|
||||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}.
|
||||
* @returns {!ArrayBuffer} Contents as an ArrayBuffer
|
||||
*/
|
||||
ByteBufferPrototype.toArrayBuffer = function() {
|
||||
var offset = this.offset,
|
||||
limit = this.limit;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_RANGE('offset', 'limit');
|
||||
}
|
||||
var ab = new ArrayBuffer(limit - offset);
|
||||
if (memcpy) { // Fast
|
||||
memcpy(ab, 0, this.buffer, offset, limit);
|
||||
} else { // Slow
|
||||
var dst = new Uint8Array(ab);
|
||||
for (var i=offset; i<limit; ++i)
|
||||
dst[i-offset] = this.buffer[i];
|
||||
}
|
||||
return ab;
|
||||
};
|
||||
//? } else {
|
||||
/**
|
||||
* Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between
|
||||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. This is an alias of {@link ByteBuffer#toBuffer}.
|
||||
* @function
|
||||
* @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory.
|
||||
* Defaults to `false`
|
||||
* @returns {!ArrayBuffer} Contents as an ArrayBuffer
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.toArrayBuffer = ByteBufferPrototype.toBuffer;
|
||||
//? }
|
||||
|
43
node_modules/bytebuffer/src/methods/toString.js
generated
vendored
Normal file
43
node_modules/bytebuffer/src/methods/toString.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Converts the ByteBuffer's contents to a string.
|
||||
* @param {string=} encoding Output encoding. Returns an informative string representation if omitted but also allows
|
||||
* direct conversion to "utf8", "hex", "base64" and "binary" encoding. "debug" returns a hex representation with
|
||||
* highlighted offsets.
|
||||
* @param {number=} begin Offset to begin at, defaults to {@link ByteBuffer#offset}
|
||||
* @param {number=} end Offset to end at, defaults to {@link ByteBuffer#limit}
|
||||
* @returns {string} String representation
|
||||
* @throws {Error} If `encoding` is invalid
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.toString = function(encoding, begin, end) {
|
||||
if (typeof encoding === 'undefined')
|
||||
return "ByteBuffer/*?= NODE ? 'NB' : 'AB'+(DATAVIEW ? '_DataView' : '') */(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";
|
||||
if (typeof encoding === 'number')
|
||||
encoding = "utf8",
|
||||
begin = encoding,
|
||||
end = begin;
|
||||
switch (encoding) {
|
||||
//? if (ENCODINGS) {
|
||||
//? if (UTF8) {
|
||||
case "utf8":
|
||||
return this.toUTF8(begin, end);
|
||||
//? } if (BASE64) {
|
||||
case "base64":
|
||||
return this.toBase64(begin, end);
|
||||
//? } if (HEX) {
|
||||
case "hex":
|
||||
return this.toHex(begin, end);
|
||||
//? } if (BINARY) {
|
||||
case "binary":
|
||||
return this.toBinary(begin, end);
|
||||
//? } if (DEBUG) {
|
||||
case "debug":
|
||||
return this.toDebug();
|
||||
case "columns":
|
||||
return this.toColumns();
|
||||
//? }
|
||||
//? } // ENCODINGS
|
||||
default:
|
||||
throw Error("Unsupported encoding: "+encoding);
|
||||
}
|
||||
};
|
89
node_modules/bytebuffer/src/types/bytes/bitset.js
generated
vendored
Normal file
89
node_modules/bytebuffer/src/types/bytes/bitset.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Writes the array as a bitset.
|
||||
* @param {Array<boolean>} value Array of booleans to write
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `length` if omitted.
|
||||
* @returns {!ByteBuffer}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeBitSet = function(value, offset) {
|
||||
//? RELATIVE()
|
||||
if (!this.noAssert) {
|
||||
if (!(value instanceof Array))
|
||||
throw TypeError("Illegal BitSet: Not an array");
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
|
||||
var start = offset,
|
||||
bits = value.length,
|
||||
bytes = (bits >> 3),
|
||||
bit = 0,
|
||||
k;
|
||||
|
||||
offset += this.writeVarint32(bits,offset);
|
||||
|
||||
while(bytes--) {
|
||||
k = (!!value[bit++] & 1) |
|
||||
((!!value[bit++] & 1) << 1) |
|
||||
((!!value[bit++] & 1) << 2) |
|
||||
((!!value[bit++] & 1) << 3) |
|
||||
((!!value[bit++] & 1) << 4) |
|
||||
((!!value[bit++] & 1) << 5) |
|
||||
((!!value[bit++] & 1) << 6) |
|
||||
((!!value[bit++] & 1) << 7);
|
||||
this.writeByte(k,offset++);
|
||||
}
|
||||
|
||||
if(bit < bits) {
|
||||
var m = 0; k = 0;
|
||||
while(bit < bits) k = k | ((!!value[bit++] & 1) << (m++));
|
||||
this.writeByte(k,offset++);
|
||||
}
|
||||
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
return offset - start;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a BitSet as an array of booleans.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `length` if omitted.
|
||||
* @returns {Array<boolean>
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readBitSet = function(offset) {
|
||||
//? RELATIVE()
|
||||
|
||||
var ret = this.readVarint32(offset),
|
||||
bits = ret.value,
|
||||
bytes = (bits >> 3),
|
||||
bit = 0,
|
||||
value = [],
|
||||
k;
|
||||
|
||||
offset += ret.length;
|
||||
|
||||
while(bytes--) {
|
||||
k = this.readByte(offset++);
|
||||
value[bit++] = !!(k & 0x01);
|
||||
value[bit++] = !!(k & 0x02);
|
||||
value[bit++] = !!(k & 0x04);
|
||||
value[bit++] = !!(k & 0x08);
|
||||
value[bit++] = !!(k & 0x10);
|
||||
value[bit++] = !!(k & 0x20);
|
||||
value[bit++] = !!(k & 0x40);
|
||||
value[bit++] = !!(k & 0x80);
|
||||
}
|
||||
|
||||
if(bit < bits) {
|
||||
var m = 0;
|
||||
k = this.readByte(offset++);
|
||||
while(bit < bits) value[bit++] = !!((k >> (m++)) & 1);
|
||||
}
|
||||
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
}
|
||||
return value;
|
||||
}
|
34
node_modules/bytebuffer/src/types/bytes/bytes.js
generated
vendored
Normal file
34
node_modules/bytebuffer/src/types/bytes/bytes.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Reads the specified number of bytes.
|
||||
* @param {number} length Number of bytes to read
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `length` if omitted.
|
||||
* @returns {!ByteBuffer}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readBytes = function(length, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET('length');
|
||||
}
|
||||
var slice = this.slice(offset, offset + length);
|
||||
//? RELATIVE('length');
|
||||
return slice;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a payload of bytes. This is an alias of {@link ByteBuffer#append}.
|
||||
* @function
|
||||
//? if (NODE) {
|
||||
* @param {!ByteBuffer|!Buffer|!ArrayBuffer|!Uint8Array|string} source Data to write. If `source` is a ByteBuffer, its
|
||||
* offsets will be modified according to the performed read operation.
|
||||
//? } else {
|
||||
* @param {!ByteBuffer|!ArrayBuffer|!Uint8Array|string} source Data to write. If `source` is a ByteBuffer, its offsets
|
||||
* will be modified according to the performed read operation.
|
||||
//? }
|
||||
* @param {(string|number)=} encoding Encoding if `data` is a string ("base64", "hex", "binary", defaults to "utf8")
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeBytes = ByteBufferPrototype.append;
|
81
node_modules/bytebuffer/src/types/floats/float32.js
generated
vendored
Normal file
81
node_modules/bytebuffer/src/types/floats/float32.js
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
//? if (FLOAT32) {
|
||||
// types/floats/float32
|
||||
//? if (!NODE && !DATAVIEW) {
|
||||
|
||||
//? include("ieee754.js");
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Writes a 32bit float.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeFloat32 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
if (typeof value !== 'number')
|
||||
throw TypeError("Illegal value: "+value+" (not a number)");
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(4);
|
||||
//? if (NODE) { // FIXME: Is there any way to inline the following in a sane way?
|
||||
this.littleEndian
|
||||
? this.buffer.writeFloatLE(value, offset, true)
|
||||
: this.buffer.writeFloatBE(value, offset, true);
|
||||
//? } else if (DATAVIEW)
|
||||
this.view.setFloat32(offset, value, this.littleEndian);
|
||||
//? else
|
||||
ieee754_write(this.view, value, offset, this.littleEndian, 23, 4);
|
||||
//? RELATIVE(4);
|
||||
return this;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Writes a 32bit float. This is an alias of {@link ByteBuffer#writeFloat32}.
|
||||
* @function
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeFloat = ByteBufferPrototype.writeFloat32;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Reads a 32bit float.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readFloat32 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(4);
|
||||
}
|
||||
//? if (NODE) {
|
||||
var value = this.littleEndian
|
||||
? this.buffer.readFloatLE(offset, true)
|
||||
: this.buffer.readFloatBE(offset, true);
|
||||
//? } else if (DATAVIEW)
|
||||
var value = this.view.getFloat32(offset, this.littleEndian);
|
||||
//? else
|
||||
var value = ieee754_read(this.view, offset, this.littleEndian, 23, 4);
|
||||
//? RELATIVE(4);
|
||||
return value;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Reads a 32bit float. This is an alias of {@link ByteBuffer#readFloat32}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readFloat = ByteBufferPrototype.readFloat32;
|
||||
//? }
|
||||
|
||||
//? }
|
77
node_modules/bytebuffer/src/types/floats/float64.js
generated
vendored
Normal file
77
node_modules/bytebuffer/src/types/floats/float64.js
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
//? if (FLOAT64) {
|
||||
// types/floats/float64
|
||||
|
||||
/**
|
||||
* Writes a 64bit float.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeFloat64 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
if (typeof value !== 'number')
|
||||
throw TypeError("Illegal value: "+value+" (not a number)");
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(8);
|
||||
//? if (NODE) {
|
||||
this.littleEndian
|
||||
? this.buffer.writeDoubleLE(value, offset, true)
|
||||
: this.buffer.writeDoubleBE(value, offset, true);
|
||||
//? } else if (DATAVIEW)
|
||||
this.view.setFloat64(offset, value, this.littleEndian);
|
||||
//? else
|
||||
ieee754_write(this.view, value, offset, this.littleEndian, 52, 8);
|
||||
//? RELATIVE(8);
|
||||
return this;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Writes a 64bit float. This is an alias of {@link ByteBuffer#writeFloat64}.
|
||||
* @function
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeDouble = ByteBufferPrototype.writeFloat64;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Reads a 64bit float.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readFloat64 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(8);
|
||||
}
|
||||
//? if (NODE) {
|
||||
var value = this.littleEndian
|
||||
? this.buffer.readDoubleLE(offset, true)
|
||||
: this.buffer.readDoubleBE(offset, true);
|
||||
//? } else if (DATAVIEW)
|
||||
var value = this.view.getFloat64(offset, this.littleEndian);
|
||||
//? else
|
||||
var value = ieee754_read(this.view, offset, this.littleEndian, 52, 8);
|
||||
//? RELATIVE(8);
|
||||
return value;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Reads a 64bit float. This is an alias of {@link ByteBuffer#readFloat64}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {number}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readDouble = ByteBufferPrototype.readFloat64;
|
||||
//? }
|
||||
|
||||
//? }
|
130
node_modules/bytebuffer/src/types/floats/ieee754.js
generated
vendored
Normal file
130
node_modules/bytebuffer/src/types/floats/ieee754.js
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
ieee754 - https://github.com/feross/ieee754
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Feross Aboukhadijeh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Reads an IEEE754 float from a byte array.
|
||||
* @param {!Array} buffer
|
||||
* @param {number} offset
|
||||
* @param {boolean} isLE
|
||||
* @param {number} mLen
|
||||
* @param {number} nBytes
|
||||
* @returns {number}
|
||||
* @inner
|
||||
*/
|
||||
function ieee754_read(buffer, offset, isLE, mLen, nBytes) {
|
||||
var e, m,
|
||||
eLen = nBytes * 8 - mLen - 1,
|
||||
eMax = (1 << eLen) - 1,
|
||||
eBias = eMax >> 1,
|
||||
nBits = -7,
|
||||
i = isLE ? (nBytes - 1) : 0,
|
||||
d = isLE ? -1 : 1,
|
||||
s = buffer[offset + i];
|
||||
|
||||
i += d;
|
||||
|
||||
e = s & ((1 << (-nBits)) - 1);
|
||||
s >>= (-nBits);
|
||||
nBits += eLen;
|
||||
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
||||
|
||||
m = e & ((1 << (-nBits)) - 1);
|
||||
e >>= (-nBits);
|
||||
nBits += mLen;
|
||||
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
||||
|
||||
if (e === 0) {
|
||||
e = 1 - eBias;
|
||||
} else if (e === eMax) {
|
||||
return m ? NaN : ((s ? -1 : 1) * Infinity);
|
||||
} else {
|
||||
m = m + Math.pow(2, mLen);
|
||||
e = e - eBias;
|
||||
}
|
||||
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an IEEE754 float to a byte array.
|
||||
* @param {!Array} buffer
|
||||
* @param {number} value
|
||||
* @param {number} offset
|
||||
* @param {boolean} isLE
|
||||
* @param {number} mLen
|
||||
* @param {number} nBytes
|
||||
* @inner
|
||||
*/
|
||||
function ieee754_write(buffer, value, offset, isLE, mLen, nBytes) {
|
||||
var e, m, c,
|
||||
eLen = nBytes * 8 - mLen - 1,
|
||||
eMax = (1 << eLen) - 1,
|
||||
eBias = eMax >> 1,
|
||||
rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
|
||||
i = isLE ? 0 : (nBytes - 1),
|
||||
d = isLE ? 1 : -1,
|
||||
s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
||||
|
||||
value = Math.abs(value);
|
||||
|
||||
if (isNaN(value) || value === Infinity) {
|
||||
m = isNaN(value) ? 1 : 0;
|
||||
e = eMax;
|
||||
} else {
|
||||
e = Math.floor(Math.log(value) / Math.LN2);
|
||||
if (value * (c = Math.pow(2, -e)) < 1) {
|
||||
e--;
|
||||
c *= 2;
|
||||
}
|
||||
if (e + eBias >= 1) {
|
||||
value += rt / c;
|
||||
} else {
|
||||
value += rt * Math.pow(2, 1 - eBias);
|
||||
}
|
||||
if (value * c >= 2) {
|
||||
e++;
|
||||
c /= 2;
|
||||
}
|
||||
|
||||
if (e + eBias >= eMax) {
|
||||
m = 0;
|
||||
e = eMax;
|
||||
} else if (e + eBias >= 1) {
|
||||
m = (value * c - 1) * Math.pow(2, mLen);
|
||||
e = e + eBias;
|
||||
} else {
|
||||
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
||||
e = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
||||
|
||||
e = (e << mLen) | m;
|
||||
eLen += mLen;
|
||||
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
||||
|
||||
buffer[offset + i - d] |= s * 128;
|
||||
}
|
167
node_modules/bytebuffer/src/types/ints/int16.js
generated
vendored
Normal file
167
node_modules/bytebuffer/src/types/ints/int16.js
generated
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
//? if (INT16) {
|
||||
// types/ints/int16
|
||||
|
||||
/**
|
||||
* Writes a 16bit signed integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @throws {TypeError} If `offset` or `value` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeInt16 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(2);
|
||||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view';
|
||||
if (this.littleEndian) {
|
||||
/*?= dst */[offset+1] = (value & 0xFF00) >>> 8;
|
||||
/*?= dst */[offset ] = value & 0x00FF;
|
||||
} else {
|
||||
/*?= dst */[offset] = (value & 0xFF00) >>> 8;
|
||||
/*?= dst */[offset+1] = value & 0x00FF;
|
||||
}
|
||||
//? } else
|
||||
this.view.setInt16(offset, value, this.littleEndian);
|
||||
//? RELATIVE(2);
|
||||
return this;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Writes a 16bit signed integer. This is an alias of {@link ByteBuffer#writeInt16}.
|
||||
* @function
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @throws {TypeError} If `offset` or `value` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeShort = ByteBufferPrototype.writeInt16;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Reads a 16bit signed integer.
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @throws {TypeError} If `offset` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readInt16 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(2);
|
||||
}
|
||||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view';
|
||||
var value = 0;
|
||||
if (this.littleEndian) {
|
||||
value = /*?= dst */[offset ];
|
||||
value |= /*?= dst */[offset+1] << 8;
|
||||
} else {
|
||||
value = /*?= dst */[offset ] << 8;
|
||||
value |= /*?= dst */[offset+1];
|
||||
}
|
||||
if ((value & 0x8000) === 0x8000) value = -(0xFFFF - value + 1); // Cast to signed
|
||||
//? } else
|
||||
var value = this.view.getInt16(offset, this.littleEndian);
|
||||
//? RELATIVE(2);
|
||||
return value;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Reads a 16bit signed integer. This is an alias of {@link ByteBuffer#readInt16}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @throws {TypeError} If `offset` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readShort = ByteBufferPrototype.readInt16;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Writes a 16bit unsigned integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @throws {TypeError} If `offset` or `value` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUint16 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value', true);
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(2);
|
||||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view';
|
||||
if (this.littleEndian) {
|
||||
/*?= dst */[offset+1] = (value & 0xFF00) >>> 8;
|
||||
/*?= dst */[offset ] = value & 0x00FF;
|
||||
} else {
|
||||
/*?= dst */[offset] = (value & 0xFF00) >>> 8;
|
||||
/*?= dst */[offset+1] = value & 0x00FF;
|
||||
}
|
||||
//? } else
|
||||
this.view.setUint16(offset, value, this.littleEndian);
|
||||
//? RELATIVE(2);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a 16bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint16}.
|
||||
* @function
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @throws {TypeError} If `offset` or `value` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUInt16 = ByteBufferPrototype.writeUint16;
|
||||
|
||||
/**
|
||||
* Reads a 16bit unsigned integer.
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @throws {TypeError} If `offset` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUint16 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(2);
|
||||
}
|
||||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view';
|
||||
var value = 0;
|
||||
if (this.littleEndian) {
|
||||
value = /*?= dst */[offset ];
|
||||
value |= /*?= dst */[offset+1] << 8;
|
||||
} else {
|
||||
value = /*?= dst */[offset ] << 8;
|
||||
value |= /*?= dst */[offset+1];
|
||||
}
|
||||
//? } else
|
||||
var value = this.view.getUint16(offset, this.littleEndian);
|
||||
//? RELATIVE(2);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a 16bit unsigned integer. This is an alias of {@link ByteBuffer#readUint16}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @throws {TypeError} If `offset` is not a valid number
|
||||
* @throws {RangeError} If `offset` is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUInt16 = ByteBufferPrototype.readUint16;
|
||||
|
||||
//? }
|
125
node_modules/bytebuffer/src/types/ints/int32.js
generated
vendored
Normal file
125
node_modules/bytebuffer/src/types/ints/int32.js
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
//? if (INT32) {
|
||||
// types/ints/int32
|
||||
|
||||
/**
|
||||
* Writes a 32bit signed integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeInt32 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(4);
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
//? WRITE_UINT32_ARRAY();
|
||||
//? } else
|
||||
this.view.setInt32(offset, value, this.littleEndian);
|
||||
//? RELATIVE(4);
|
||||
return this;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Writes a 32bit signed integer. This is an alias of {@link ByteBuffer#writeInt32}.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeInt = ByteBufferPrototype.writeInt32;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Reads a 32bit signed integer.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readInt32 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(4);
|
||||
}
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
var value = 0;
|
||||
//? READ_UINT32_ARRAY();
|
||||
value |= 0; // Cast to signed
|
||||
//? } else
|
||||
var value = this.view.getInt32(offset, this.littleEndian);
|
||||
//? RELATIVE(4);
|
||||
return value;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Reads a 32bit signed integer. This is an alias of {@link ByteBuffer#readInt32}.
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readInt = ByteBufferPrototype.readInt32;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Writes a 32bit unsigned integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUint32 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value', true);
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(4);
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
//? WRITE_UINT32_ARRAY();
|
||||
//? } else
|
||||
this.view.setUint32(offset, value, this.littleEndian);
|
||||
//? RELATIVE(4);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a 32bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint32}.
|
||||
* @function
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUInt32 = ByteBufferPrototype.writeUint32;
|
||||
|
||||
/**
|
||||
* Reads a 32bit unsigned integer.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUint32 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(4);
|
||||
}
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
var value = 0;
|
||||
//? READ_UINT32_ARRAY();
|
||||
//? } else
|
||||
var value = this.view.getUint32(offset, this.littleEndian);
|
||||
//? RELATIVE(4);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a 32bit unsigned integer. This is an alias of {@link ByteBuffer#readUint32}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUInt32 = ByteBufferPrototype.readUint32;
|
||||
|
||||
//? }
|
194
node_modules/bytebuffer/src/types/ints/int64.js
generated
vendored
Normal file
194
node_modules/bytebuffer/src/types/ints/int64.js
generated
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
//? if (INT64) {
|
||||
// types/ints/int64
|
||||
|
||||
if (Long) {
|
||||
|
||||
/**
|
||||
* Writes a 64bit signed integer.
|
||||
* @param {number|!Long} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeInt64 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_LONG('value');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? LONG('value');
|
||||
//? ENSURE_CAPACITY(8);
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
var lo = value.low,
|
||||
hi = value.high;
|
||||
if (this.littleEndian) {
|
||||
//? WRITE_UINT32_ARRAY('lo', undefined, undefined, true);
|
||||
offset += 4;
|
||||
//? WRITE_UINT32_ARRAY('hi', undefined, undefined, true);
|
||||
} else {
|
||||
//? WRITE_UINT32_ARRAY('hi', undefined, undefined, false);
|
||||
offset += 4;
|
||||
//? WRITE_UINT32_ARRAY('lo', undefined, undefined, false);
|
||||
}
|
||||
//? } else {
|
||||
if (this.littleEndian) {
|
||||
this.view.setInt32(offset , value.low , true);
|
||||
this.view.setInt32(offset+4, value.high, true);
|
||||
} else {
|
||||
this.view.setInt32(offset , value.high, false);
|
||||
this.view.setInt32(offset+4, value.low , false);
|
||||
}
|
||||
//? }
|
||||
//? RELATIVE(8);
|
||||
return this;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Writes a 64bit signed integer. This is an alias of {@link ByteBuffer#writeInt64}.
|
||||
* @param {number|!Long} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeLong = ByteBufferPrototype.writeInt64;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Reads a 64bit signed integer.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readInt64 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(8);
|
||||
}
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
var lo = 0,
|
||||
hi = 0;
|
||||
if (this.littleEndian) {
|
||||
//? READ_UINT32_ARRAY('lo', undefined, undefined, true);
|
||||
offset += 4;
|
||||
//? READ_UINT32_ARRAY('hi', undefined, undefined, true);
|
||||
} else {
|
||||
//? READ_UINT32_ARRAY('hi', undefined, undefined, false);
|
||||
offset += 4;
|
||||
//? READ_UINT32_ARRAY('lo', undefined, undefined, false);
|
||||
}
|
||||
var value = new Long(lo, hi, false);
|
||||
//? } else {
|
||||
var value = this.littleEndian
|
||||
? new Long(this.view.getInt32(offset , true ), this.view.getInt32(offset+4, true ), false)
|
||||
: new Long(this.view.getInt32(offset+4, false), this.view.getInt32(offset , false), false);
|
||||
//? }
|
||||
//? RELATIVE(8);
|
||||
return value;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Reads a 64bit signed integer. This is an alias of {@link ByteBuffer#readInt64}.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readLong = ByteBufferPrototype.readInt64;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Writes a 64bit unsigned integer.
|
||||
* @param {number|!Long} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUint64 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_LONG('value');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? LONG('value');
|
||||
//? ENSURE_CAPACITY(8);
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
var lo = value.low,
|
||||
hi = value.high;
|
||||
if (this.littleEndian) {
|
||||
//? WRITE_UINT32_ARRAY('lo', undefined, undefined, true);
|
||||
offset += 4;
|
||||
//? WRITE_UINT32_ARRAY('hi', undefined, undefined, true);
|
||||
} else {
|
||||
//? WRITE_UINT32_ARRAY('hi', undefined, undefined, false);
|
||||
offset += 4;
|
||||
//? WRITE_UINT32_ARRAY('lo', undefined, undefined, false);
|
||||
}
|
||||
//? } else {
|
||||
if (this.littleEndian) {
|
||||
this.view.setInt32(offset , value.low , true);
|
||||
this.view.setInt32(offset+4, value.high, true);
|
||||
} else {
|
||||
this.view.setInt32(offset , value.high, false);
|
||||
this.view.setInt32(offset+4, value.low , false);
|
||||
}
|
||||
//? }
|
||||
//? RELATIVE(8);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a 64bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint64}.
|
||||
* @function
|
||||
* @param {number|!Long} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUInt64 = ByteBufferPrototype.writeUint64;
|
||||
|
||||
/**
|
||||
* Reads a 64bit unsigned integer.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUint64 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(8);
|
||||
}
|
||||
//? if (NODE || !DATAVIEW) {
|
||||
var lo = 0,
|
||||
hi = 0;
|
||||
if (this.littleEndian) {
|
||||
//? READ_UINT32_ARRAY('lo', undefined, undefined, true);
|
||||
offset += 4;
|
||||
//? READ_UINT32_ARRAY('hi', undefined, undefined, true);
|
||||
} else {
|
||||
//? READ_UINT32_ARRAY('hi', undefined, undefined, false);
|
||||
offset += 4;
|
||||
//? READ_UINT32_ARRAY('lo', undefined, undefined, false);
|
||||
}
|
||||
var value = new Long(lo, hi, true);
|
||||
//? } else {
|
||||
var value = this.littleEndian
|
||||
? new Long(this.view.getInt32(offset , true ), this.view.getInt32(offset+4, true ), true)
|
||||
: new Long(this.view.getInt32(offset+4, false), this.view.getInt32(offset , false), true);
|
||||
//? }
|
||||
//? RELATIVE(8);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a 64bit unsigned integer. This is an alias of {@link ByteBuffer#readUint64}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `8` if omitted.
|
||||
* @returns {!Long}
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUInt64 = ByteBufferPrototype.readUint64;
|
||||
|
||||
} // Long
|
||||
|
||||
//? }
|
137
node_modules/bytebuffer/src/types/ints/int8.js
generated
vendored
Normal file
137
node_modules/bytebuffer/src/types/ints/int8.js
generated
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
//? if (INT8) {
|
||||
// types/ints/int8
|
||||
|
||||
/**
|
||||
* Writes an 8bit signed integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeInt8 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(1);
|
||||
//? if (NODE)
|
||||
this.buffer[offset] = value;
|
||||
//? else if (DATAVIEW)
|
||||
this.view.setInt8(offset, value);
|
||||
//? else
|
||||
this.view[offset] = value;
|
||||
//? RELATIVE(1);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes an 8bit signed integer. This is an alias of {@link ByteBuffer#writeInt8}.
|
||||
* @function
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeByte = ByteBufferPrototype.writeInt8;
|
||||
|
||||
/**
|
||||
* Reads an 8bit signed integer.
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readInt8 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(1);
|
||||
}
|
||||
//? if (NODE) {
|
||||
var value = this.buffer[offset];
|
||||
if ((value & 0x80) === 0x80) value = -(0xFF - value + 1); // Cast to signed
|
||||
//? } else if (DATAVIEW) {
|
||||
var value = this.view.getInt8(offset);
|
||||
//? } else {
|
||||
var value = this.view[offset];
|
||||
if ((value & 0x80) === 0x80) value = -(0xFF - value + 1); // Cast to signed
|
||||
//? }
|
||||
//? RELATIVE(1);
|
||||
return value;
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Reads an 8bit signed integer. This is an alias of {@link ByteBuffer#readInt8}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readByte = ByteBufferPrototype.readInt8;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Writes an 8bit unsigned integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUint8 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value', true);
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? ENSURE_CAPACITY(1);
|
||||
//? if (NODE)
|
||||
this.buffer[offset] = value;
|
||||
//? else if (DATAVIEW)
|
||||
this.view.setUint8(offset, value);
|
||||
//? else
|
||||
this.view[offset] = value;
|
||||
//? RELATIVE(1);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes an 8bit unsigned integer. This is an alias of {@link ByteBuffer#writeUint8}.
|
||||
* @function
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {!ByteBuffer} this
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUInt8 = ByteBufferPrototype.writeUint8;
|
||||
|
||||
/**
|
||||
* Reads an 8bit unsigned integer.
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUint8 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(1);
|
||||
}
|
||||
//? if (NODE)
|
||||
var value = this.buffer[offset];
|
||||
//? else if (DATAVIEW)
|
||||
var value = this.view.getUint8(offset);
|
||||
//? else
|
||||
var value = this.view[offset];
|
||||
//? RELATIVE(1);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads an 8bit unsigned integer. This is an alias of {@link ByteBuffer#readUint8}.
|
||||
* @function
|
||||
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted.
|
||||
* @returns {number} Value read
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUInt8 = ByteBufferPrototype.readUint8;
|
||||
|
||||
//? }
|
110
node_modules/bytebuffer/src/types/strings/cstring.js
generated
vendored
Normal file
110
node_modules/bytebuffer/src/types/strings/cstring.js
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
//? if (CSTRING) {
|
||||
// types/strings/cstring
|
||||
|
||||
/**
|
||||
* Writes a NULL-terminated UTF8 encoded string. For this to work the specified string must not contain any NULL
|
||||
* characters itself.
|
||||
* @param {string} str String to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* contained in `str` + 1 if omitted.
|
||||
* @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeCString = function(str, offset) {
|
||||
//? RELATIVE();
|
||||
var i,
|
||||
k = str.length;
|
||||
if (!this.noAssert) {
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("Illegal str: Not a string");
|
||||
for (i=0; i<k; ++i) {
|
||||
if (str.charCodeAt(i) === 0)
|
||||
throw RangeError("Illegal str: Contains NULL-characters");
|
||||
}
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
// UTF8 strings do not contain zero bytes in between except for the zero character, so:
|
||||
//? if (NODE) {
|
||||
k = Buffer.byteLength(str, "utf8");
|
||||
//? ENSURE_CAPACITY('k+1');
|
||||
offset += this.buffer.write(str, offset, k, "utf8");
|
||||
this.buffer[offset++] = 0;
|
||||
//? } else {
|
||||
k = utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
||||
//? ENSURE_CAPACITY('k+1');
|
||||
utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
||||
//? if (DATAVIEW)
|
||||
this.view.setUint8(offset++, b);
|
||||
//? else
|
||||
this.view[offset++] = b;
|
||||
}.bind(this));
|
||||
//? if (DATAVIEW)
|
||||
this.view.setUint8(offset++, 0);
|
||||
//? else
|
||||
this.view[offset++] = 0;
|
||||
//? }
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
return k;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a NULL-terminated UTF8 encoded string. For this to work the string read must not contain any NULL characters
|
||||
* itself.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string
|
||||
* read and the actual number of bytes read.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readCString = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(1);
|
||||
}
|
||||
var start = offset,
|
||||
temp;
|
||||
// UTF8 strings do not contain zero bytes in between except for the zero character itself, so:
|
||||
//? if (NODE) {
|
||||
do {
|
||||
if (offset >= this.buffer.length)
|
||||
throw RangeError("Index out of range: "+offset+" <= "+this.buffer.length);
|
||||
temp = this.buffer[offset++];
|
||||
} while (temp !== 0);
|
||||
var str = this.buffer.toString("utf8", start, offset-1);
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return str;
|
||||
} else {
|
||||
return {
|
||||
"string": str,
|
||||
"length": offset - start
|
||||
};
|
||||
}
|
||||
//? } else { // getUint8 asserts on its own
|
||||
var sd, b = -1;
|
||||
utfx.decodeUTF8toUTF16(function() {
|
||||
if (b === 0) return null;
|
||||
if (offset >= this.limit)
|
||||
throw RangeError("Illegal range: Truncated data, "+offset+" < "+this.limit);
|
||||
//? if (DATAVIEW)
|
||||
b = this.view.getUint8(offset++);
|
||||
//? else
|
||||
b = this.view[offset++];
|
||||
return b === 0 ? null : b;
|
||||
}.bind(this), sd = stringDestination(), true);
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return sd();
|
||||
} else {
|
||||
return {
|
||||
"string": sd(),
|
||||
"length": offset - start
|
||||
};
|
||||
}
|
||||
//? }
|
||||
};
|
||||
|
||||
//? }
|
81
node_modules/bytebuffer/src/types/strings/istring.js
generated
vendored
Normal file
81
node_modules/bytebuffer/src/types/strings/istring.js
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
//? if (ISTRING) {
|
||||
// types/strings/istring
|
||||
|
||||
/**
|
||||
* Writes a length as uint32 prefixed UTF8 encoded string.
|
||||
* @param {string} str String to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer|number} `this` if `offset` is omitted, else the actual number of bytes written
|
||||
* @expose
|
||||
* @see ByteBuffer#writeVarint32
|
||||
*/
|
||||
ByteBufferPrototype.writeIString = function(str, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("Illegal str: Not a string");
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
var start = offset,
|
||||
k;
|
||||
//? if (NODE) {
|
||||
k = Buffer.byteLength(str, "utf8");
|
||||
//? ENSURE_CAPACITY('4+k');
|
||||
//? WRITE_UINT32_ARRAY('k');
|
||||
offset += 4;
|
||||
offset += this.buffer.write(str, offset, k, "utf8");
|
||||
//? } else {
|
||||
k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];
|
||||
//? ENSURE_CAPACITY('4+k');
|
||||
//? if (DATAVIEW)
|
||||
this.view.setUint32(offset, k, this.littleEndian);
|
||||
//? else
|
||||
//? WRITE_UINT32_ARRAY('k');
|
||||
offset += 4;
|
||||
utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
||||
//? if (DATAVIEW)
|
||||
this.view.setUint8(offset++, b);
|
||||
//? else
|
||||
this.view[offset++] = b;
|
||||
}.bind(this));
|
||||
if (offset !== start + 4 + k)
|
||||
throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+4+k));
|
||||
//? }
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
return offset - start;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a length as uint32 prefixed UTF8 encoded string.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string
|
||||
* read and the actual number of bytes read.
|
||||
* @expose
|
||||
* @see ByteBuffer#readVarint32
|
||||
*/
|
||||
ByteBufferPrototype.readIString = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(4);
|
||||
}
|
||||
var start = offset;
|
||||
var len = this.readUint32(offset);
|
||||
var str = this.readUTF8String(len, ByteBuffer.METRICS_BYTES, offset += 4);
|
||||
offset += str['length'];
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return str['string'];
|
||||
} else {
|
||||
return {
|
||||
'string': str['string'],
|
||||
'length': offset - start
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
//? }
|
214
node_modules/bytebuffer/src/types/strings/utf8string.js
generated
vendored
Normal file
214
node_modules/bytebuffer/src/types/strings/utf8string.js
generated
vendored
Normal file
@ -0,0 +1,214 @@
|
||||
//? if (UTF8STRING && UTF8) {
|
||||
// types/strings/utf8string
|
||||
|
||||
/**
|
||||
* Metrics representing number of UTF8 characters. Evaluates to `c`.
|
||||
* @type {string}
|
||||
* @const
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.METRICS_CHARS = 'c';
|
||||
|
||||
/**
|
||||
* Metrics representing number of bytes. Evaluates to `b`.
|
||||
* @type {string}
|
||||
* @const
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.METRICS_BYTES = 'b';
|
||||
|
||||
/**
|
||||
* Writes an UTF8 encoded string.
|
||||
* @param {string} str String to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted.
|
||||
* @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeUTF8String = function(str, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
var k;
|
||||
//? if (NODE) {
|
||||
k = Buffer.byteLength(str, "utf8");
|
||||
//? ENSURE_CAPACITY('k');
|
||||
offset += this.buffer.write(str, offset, k, "utf8");
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
return k;
|
||||
//? } else {
|
||||
var start = offset;
|
||||
k = utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
||||
//? ENSURE_CAPACITY('k');
|
||||
utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
||||
//? if (DATAVIEW)
|
||||
this.view.setUint8(offset++, b);
|
||||
//? else
|
||||
this.view[offset++] = b;
|
||||
}.bind(this));
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
return offset - start;
|
||||
//? }
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Writes an UTF8 encoded string. This is an alias of {@link ByteBuffer#writeUTF8String}.
|
||||
* @function
|
||||
* @param {string} str String to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} if omitted.
|
||||
* @returns {!ByteBuffer|number} this if offset is omitted, else the actual number of bytes written.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeString = ByteBufferPrototype.writeUTF8String;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Calculates the number of UTF8 characters of a string. JavaScript itself uses UTF-16, so that a string's
|
||||
* `length` property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF.
|
||||
* @param {string} str String to calculate
|
||||
* @returns {number} Number of UTF8 characters
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.calculateUTF8Chars = function(str) {
|
||||
return utfx.calculateUTF16asUTF8(stringSource(str))[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the number of UTF8 bytes of a string.
|
||||
* @param {string} str String to calculate
|
||||
* @returns {number} Number of UTF8 bytes
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.calculateUTF8Bytes = function(str) {
|
||||
//? if (NODE) {
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("Illegal argument: "+(typeof str));
|
||||
return Buffer.byteLength(str, "utf8");
|
||||
//? } else
|
||||
return utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Calculates the number of UTF8 bytes of a string. This is an alias of {@link ByteBuffer.calculateUTF8Bytes}.
|
||||
* @function
|
||||
* @param {string} str String to calculate
|
||||
* @returns {number} Number of UTF8 bytes
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.calculateString = ByteBuffer.calculateUTF8Bytes;
|
||||
//? }
|
||||
|
||||
/**
|
||||
* Reads an UTF8 encoded string.
|
||||
* @param {number} length Number of characters or bytes to read.
|
||||
* @param {string=} metrics Metrics specifying what `length` is meant to count. Defaults to
|
||||
* {@link ByteBuffer.METRICS_CHARS}.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string
|
||||
* read and the actual number of bytes read.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readUTF8String = function(length, metrics, offset) {
|
||||
if (typeof metrics === 'number') {
|
||||
offset = metrics;
|
||||
metrics = undefined;
|
||||
}
|
||||
//? RELATIVE();
|
||||
if (typeof metrics === 'undefined') metrics = ByteBuffer.METRICS_CHARS;
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('length');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
var i = 0,
|
||||
start = offset,
|
||||
//? if (NODE)
|
||||
temp,
|
||||
sd;
|
||||
if (metrics === ByteBuffer.METRICS_CHARS) { // The same for node and the browser
|
||||
sd = stringDestination();
|
||||
utfx.decodeUTF8(function() {
|
||||
//? if (NODE)
|
||||
return i < length && offset < this.limit ? this.buffer[offset++] : null;
|
||||
//? else if (DATAVIEW)
|
||||
return i < length && offset < this.limit ? this.view.getUint8(offset++) : null;
|
||||
//? else
|
||||
return i < length && offset < this.limit ? this.view[offset++] : null;
|
||||
}.bind(this), function(cp) {
|
||||
++i; utfx.UTF8toUTF16(cp, sd);
|
||||
});
|
||||
if (i !== length)
|
||||
throw RangeError("Illegal range: Truncated data, "+i+" == "+length);
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return sd();
|
||||
} else {
|
||||
return {
|
||||
"string": sd(),
|
||||
"length": offset - start
|
||||
};
|
||||
}
|
||||
} else if (metrics === ByteBuffer.METRICS_BYTES) {
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET('length');
|
||||
}
|
||||
//? if (NODE) {
|
||||
temp = this.buffer.toString("utf8", offset, offset+length);
|
||||
if (relative) {
|
||||
this.offset += length;
|
||||
return temp;
|
||||
} else {
|
||||
return {
|
||||
'string': temp,
|
||||
'length': length
|
||||
};
|
||||
}
|
||||
//? } else {
|
||||
var k = offset + length;
|
||||
utfx.decodeUTF8toUTF16(function() {
|
||||
//? if (DATAVIEW)
|
||||
return offset < k ? this.view.getUint8(offset++) : null;
|
||||
//? else
|
||||
return offset < k ? this.view[offset++] : null;
|
||||
}.bind(this), sd = stringDestination(), this.noAssert);
|
||||
if (offset !== k)
|
||||
throw RangeError("Illegal range: Truncated data, "+offset+" == "+k);
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return sd();
|
||||
} else {
|
||||
return {
|
||||
'string': sd(),
|
||||
'length': offset - start
|
||||
};
|
||||
}
|
||||
//? }
|
||||
} else
|
||||
throw TypeError("Unsupported metrics: "+metrics);
|
||||
};
|
||||
//? if (ALIASES) {
|
||||
|
||||
/**
|
||||
* Reads an UTF8 encoded string. This is an alias of {@link ByteBuffer#readUTF8String}.
|
||||
* @function
|
||||
* @param {number} length Number of characters or bytes to read
|
||||
* @param {number=} metrics Metrics specifying what `n` is meant to count. Defaults to
|
||||
* {@link ByteBuffer.METRICS_CHARS}.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string
|
||||
* read and the actual number of bytes read.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readString = ByteBufferPrototype.readUTF8String;
|
||||
//? }
|
||||
|
||||
//? }
|
78
node_modules/bytebuffer/src/types/strings/vstring.js
generated
vendored
Normal file
78
node_modules/bytebuffer/src/types/strings/vstring.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
//? if (VSTRING && VARINTS && VARINT32) {
|
||||
// types/strings/vstring
|
||||
|
||||
/**
|
||||
* Writes a length as varint32 prefixed UTF8 encoded string.
|
||||
* @param {string} str String to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer|number} `this` if `offset` is omitted, else the actual number of bytes written
|
||||
* @expose
|
||||
* @see ByteBuffer#writeVarint32
|
||||
*/
|
||||
ByteBufferPrototype.writeVString = function(str, offset) {
|
||||
//? RELATIVE()
|
||||
if (!this.noAssert) {
|
||||
if (typeof str !== 'string')
|
||||
throw TypeError("Illegal str: Not a string");
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
var start = offset,
|
||||
k, l;
|
||||
//? if (NODE) {
|
||||
k = Buffer.byteLength(str, "utf8");
|
||||
l = ByteBuffer.calculateVarint32(k);
|
||||
//? ENSURE_CAPACITY('l+k');
|
||||
offset += this.writeVarint32(k, offset);
|
||||
offset += this.buffer.write(str, offset, k, "utf8");
|
||||
//? } else {
|
||||
k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];
|
||||
l = ByteBuffer.calculateVarint32(k);
|
||||
//? ENSURE_CAPACITY('l+k');
|
||||
offset += this.writeVarint32(k, offset);
|
||||
utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
||||
//? if (DATAVIEW)
|
||||
this.view.setUint8(offset++, b);
|
||||
//? else
|
||||
this.view[offset++] = b;
|
||||
}.bind(this));
|
||||
if (offset !== start+k+l)
|
||||
throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+k+l));
|
||||
//? }
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
return offset - start;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a length as varint32 prefixed UTF8 encoded string.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {string|!{string: string, length: number}} The string read if offset is omitted, else the string
|
||||
* read and the actual number of bytes read.
|
||||
* @expose
|
||||
* @see ByteBuffer#readVarint32
|
||||
*/
|
||||
ByteBufferPrototype.readVString = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(1);
|
||||
}
|
||||
var start = offset;
|
||||
var len = this.readVarint32(offset);
|
||||
var str = this.readUTF8String(len['value'], ByteBuffer.METRICS_BYTES, offset += len['length']);
|
||||
offset += str['length'];
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return str['string'];
|
||||
} else {
|
||||
return {
|
||||
'string': str['string'],
|
||||
'length': offset - start
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
//? }
|
164
node_modules/bytebuffer/src/types/varints/varint32.js
generated
vendored
Normal file
164
node_modules/bytebuffer/src/types/varints/varint32.js
generated
vendored
Normal file
@ -0,0 +1,164 @@
|
||||
//? if (VARINT32) {
|
||||
// types/varints/varint32
|
||||
|
||||
/**
|
||||
* Maximum number of bytes required to store a 32bit base 128 variable-length integer.
|
||||
* @type {number}
|
||||
* @const
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.MAX_VARINT32_BYTES = 5;
|
||||
|
||||
/**
|
||||
* Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer.
|
||||
* @param {number} value Value to encode
|
||||
* @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT32_BYTES}
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.calculateVarint32 = function(value) {
|
||||
// ref: src/google/protobuf/io/coded_stream.cc
|
||||
value = value >>> 0;
|
||||
if (value < 1 << 7 ) return 1;
|
||||
else if (value < 1 << 14) return 2;
|
||||
else if (value < 1 << 21) return 3;
|
||||
else if (value < 1 << 28) return 4;
|
||||
else return 5;
|
||||
};
|
||||
|
||||
/**
|
||||
* Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding.
|
||||
* @param {number} n Signed 32bit integer
|
||||
* @returns {number} Unsigned zigzag encoded 32bit integer
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.zigZagEncode32 = function(n) {
|
||||
return (((n |= 0) << 1) ^ (n >> 31)) >>> 0; // ref: src/google/protobuf/wire_format_lite.h
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a zigzag encoded signed 32bit integer.
|
||||
* @param {number} n Unsigned zigzag encoded 32bit integer
|
||||
* @returns {number} Signed 32bit integer
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.zigZagDecode32 = function(n) {
|
||||
return ((n >>> 1) ^ -(n & 1)) | 0; // // ref: src/google/protobuf/wire_format_lite.h
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a 32bit base 128 variable-length integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer|number} this if `offset` is omitted, else the actual number of bytes written
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeVarint32 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_INTEGER('value');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
var size = ByteBuffer.calculateVarint32(value),
|
||||
b;
|
||||
//? ENSURE_CAPACITY('size');
|
||||
value >>>= 0;
|
||||
while (value >= 0x80) {
|
||||
b = (value & 0x7f) | 0x80;
|
||||
//? if (NODE)
|
||||
this.buffer[offset++] = b;
|
||||
//? else if (DATAVIEW)
|
||||
this.view.setUint8(offset++, b);
|
||||
//? else
|
||||
this.view[offset++] = b;
|
||||
value >>>= 7;
|
||||
}
|
||||
//? if (NODE)
|
||||
this.buffer[offset++] = value;
|
||||
//? else if (DATAVIEW)
|
||||
this.view.setUint8(offset++, value);
|
||||
//? else
|
||||
this.view[offset++] = value;
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return this;
|
||||
}
|
||||
return size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a zig-zag encoded (signed) 32bit base 128 variable-length integer.
|
||||
* @param {number} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer|number} this if `offset` is omitted, else the actual number of bytes written
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeVarint32ZigZag = function(value, offset) {
|
||||
return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a 32bit base 128 variable-length integer.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read
|
||||
* and the actual number of bytes read.
|
||||
* @throws {Error} If it's not a valid varint. Has a property `truncated = true` if there is not enough data available
|
||||
* to fully decode the varint.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readVarint32 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(1);
|
||||
}
|
||||
var c = 0,
|
||||
value = 0 >>> 0,
|
||||
b;
|
||||
do {
|
||||
if (!this.noAssert && offset > this.limit) {
|
||||
var err = Error("Truncated");
|
||||
err['truncated'] = true;
|
||||
throw err;
|
||||
}
|
||||
//? if (NODE)
|
||||
b = this.buffer[offset++];
|
||||
//? else if (DATAVIEW)
|
||||
b = this.view.getUint8(offset++);
|
||||
//? else
|
||||
b = this.view[offset++];
|
||||
if (c < 5)
|
||||
value |= (b & 0x7f) << (7*c);
|
||||
++c;
|
||||
} while ((b & 0x80) !== 0);
|
||||
value |= 0;
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return value;
|
||||
}
|
||||
return {
|
||||
"value": value,
|
||||
"length": c
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a zig-zag encoded (signed) 32bit base 128 variable-length integer.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read
|
||||
* and the actual number of bytes read.
|
||||
* @throws {Error} If it's not a valid varint
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readVarint32ZigZag = function(offset) {
|
||||
var val = this.readVarint32(offset);
|
||||
if (typeof val === 'object')
|
||||
val["value"] = ByteBuffer.zigZagDecode32(val["value"]);
|
||||
else
|
||||
val = ByteBuffer.zigZagDecode32(val);
|
||||
return val;
|
||||
};
|
||||
|
||||
//? }
|
208
node_modules/bytebuffer/src/types/varints/varint64.js
generated
vendored
Normal file
208
node_modules/bytebuffer/src/types/varints/varint64.js
generated
vendored
Normal file
@ -0,0 +1,208 @@
|
||||
//? if (VARINT64) {
|
||||
// types/varints/varint64
|
||||
|
||||
if (Long) {
|
||||
|
||||
/**
|
||||
* Maximum number of bytes required to store a 64bit base 128 variable-length integer.
|
||||
* @type {number}
|
||||
* @const
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.MAX_VARINT64_BYTES = 10;
|
||||
|
||||
/**
|
||||
* Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer.
|
||||
* @param {number|!Long} value Value to encode
|
||||
* @returns {number} Number of bytes required. Capped to {@link ByteBuffer.MAX_VARINT64_BYTES}
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.calculateVarint64 = function(value) {
|
||||
//? LONG('value');
|
||||
// ref: src/google/protobuf/io/coded_stream.cc
|
||||
var part0 = value.toInt() >>> 0,
|
||||
part1 = value.shiftRightUnsigned(28).toInt() >>> 0,
|
||||
part2 = value.shiftRightUnsigned(56).toInt() >>> 0;
|
||||
if (part2 == 0) {
|
||||
if (part1 == 0) {
|
||||
if (part0 < 1 << 14)
|
||||
return part0 < 1 << 7 ? 1 : 2;
|
||||
else
|
||||
return part0 < 1 << 21 ? 3 : 4;
|
||||
} else {
|
||||
if (part1 < 1 << 14)
|
||||
return part1 < 1 << 7 ? 5 : 6;
|
||||
else
|
||||
return part1 < 1 << 21 ? 7 : 8;
|
||||
}
|
||||
} else
|
||||
return part2 < 1 << 7 ? 9 : 10;
|
||||
};
|
||||
|
||||
/**
|
||||
* Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding.
|
||||
* @param {number|!Long} value Signed long
|
||||
* @returns {!Long} Unsigned zigzag encoded long
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.zigZagEncode64 = function(value) {
|
||||
//? LONG('value', false);
|
||||
// ref: src/google/protobuf/wire_format_lite.h
|
||||
return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned();
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a zigzag encoded signed 64bit integer.
|
||||
* @param {!Long|number} value Unsigned zigzag encoded long or JavaScript number
|
||||
* @returns {!Long} Signed long
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.zigZagDecode64 = function(value) {
|
||||
//? LONG('value', false);
|
||||
// ref: src/google/protobuf/wire_format_lite.h
|
||||
return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned();
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a 64bit base 128 variable-length integer.
|
||||
* @param {number|Long} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer|number} `this` if offset is omitted, else the actual number of bytes written.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeVarint64 = function(value, offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_LONG('value');
|
||||
//? ASSERT_OFFSET();
|
||||
}
|
||||
//? LONG('value', false);
|
||||
var size = ByteBuffer.calculateVarint64(value),
|
||||
part0 = value.toInt() >>> 0,
|
||||
part1 = value.shiftRightUnsigned(28).toInt() >>> 0,
|
||||
part2 = value.shiftRightUnsigned(56).toInt() >>> 0;
|
||||
//? ENSURE_CAPACITY('size');
|
||||
switch (size) {
|
||||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view';
|
||||
case 10: /*?= dst */[offset+9] = (part2 >>> 7) & 0x01;
|
||||
case 9 : /*?= dst */[offset+8] = size !== 9 ? (part2 ) | 0x80 : (part2 ) & 0x7F;
|
||||
case 8 : /*?= dst */[offset+7] = size !== 8 ? (part1 >>> 21) | 0x80 : (part1 >>> 21) & 0x7F;
|
||||
case 7 : /*?= dst */[offset+6] = size !== 7 ? (part1 >>> 14) | 0x80 : (part1 >>> 14) & 0x7F;
|
||||
case 6 : /*?= dst */[offset+5] = size !== 6 ? (part1 >>> 7) | 0x80 : (part1 >>> 7) & 0x7F;
|
||||
case 5 : /*?= dst */[offset+4] = size !== 5 ? (part1 ) | 0x80 : (part1 ) & 0x7F;
|
||||
case 4 : /*?= dst */[offset+3] = size !== 4 ? (part0 >>> 21) | 0x80 : (part0 >>> 21) & 0x7F;
|
||||
case 3 : /*?= dst */[offset+2] = size !== 3 ? (part0 >>> 14) | 0x80 : (part0 >>> 14) & 0x7F;
|
||||
case 2 : /*?= dst */[offset+1] = size !== 2 ? (part0 >>> 7) | 0x80 : (part0 >>> 7) & 0x7F;
|
||||
case 1 : /*?= dst */[offset ] = size !== 1 ? (part0 ) | 0x80 : (part0 ) & 0x7F;
|
||||
//? } else {
|
||||
case 10: this.view.setUint8(offset+9, (part2 >>> 7) & 0x01);
|
||||
case 9 : this.view.setUint8(offset+8, size !== 9 ? (part2 ) | 0x80 : (part2 ) & 0x7F);
|
||||
case 8 : this.view.setUint8(offset+7, size !== 8 ? (part1 >>> 21) | 0x80 : (part1 >>> 21) & 0x7F);
|
||||
case 7 : this.view.setUint8(offset+6, size !== 7 ? (part1 >>> 14) | 0x80 : (part1 >>> 14) & 0x7F);
|
||||
case 6 : this.view.setUint8(offset+5, size !== 6 ? (part1 >>> 7) | 0x80 : (part1 >>> 7) & 0x7F);
|
||||
case 5 : this.view.setUint8(offset+4, size !== 5 ? (part1 ) | 0x80 : (part1 ) & 0x7F);
|
||||
case 4 : this.view.setUint8(offset+3, size !== 4 ? (part0 >>> 21) | 0x80 : (part0 >>> 21) & 0x7F);
|
||||
case 3 : this.view.setUint8(offset+2, size !== 3 ? (part0 >>> 14) | 0x80 : (part0 >>> 14) & 0x7F);
|
||||
case 2 : this.view.setUint8(offset+1, size !== 2 ? (part0 >>> 7) | 0x80 : (part0 >>> 7) & 0x7F);
|
||||
case 1 : this.view.setUint8(offset , size !== 1 ? (part0 ) | 0x80 : (part0 ) & 0x7F);
|
||||
//? }
|
||||
}
|
||||
if (relative) {
|
||||
this.offset += size;
|
||||
return this;
|
||||
} else {
|
||||
return size;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a zig-zag encoded 64bit base 128 variable-length integer.
|
||||
* @param {number|Long} value Value to write
|
||||
* @param {number=} offset Offset to write to. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* written if omitted.
|
||||
* @returns {!ByteBuffer|number} `this` if offset is omitted, else the actual number of bytes written.
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.writeVarint64ZigZag = function(value, offset) {
|
||||
return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a 64bit base 128 variable-length integer. Requires Long.js.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and
|
||||
* the actual number of bytes read.
|
||||
* @throws {Error} If it's not a valid varint
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readVarint64 = function(offset) {
|
||||
//? RELATIVE();
|
||||
if (!this.noAssert) {
|
||||
//? ASSERT_OFFSET(1);
|
||||
}
|
||||
// ref: src/google/protobuf/io/coded_stream.cc
|
||||
var start = offset,
|
||||
part0 = 0,
|
||||
part1 = 0,
|
||||
part2 = 0,
|
||||
b = 0;
|
||||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view';
|
||||
b = /*?= dst */[offset++]; part0 = (b & 0x7F) ; if ( b & 0x80 ) {
|
||||
b = /*?= dst */[offset++]; part0 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part0 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part0 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part1 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part1 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part1 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part1 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part2 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
b = /*?= dst */[offset++]; part2 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
||||
throw Error("Buffer overrun"); }}}}}}}}}}
|
||||
//? } else { // Asserts on its own
|
||||
b = this.view.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part0 |= (b & 0x7F) << 7; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part0 |= (b & 0x7F) << 14; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part0 |= (b & 0x7F) << 21; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part1 = (b & 0x7F) ; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part1 |= (b & 0x7F) << 7; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part1 |= (b & 0x7F) << 14; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part1 |= (b & 0x7F) << 21; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part2 = (b & 0x7F) ; if (b & 0x80) {
|
||||
b = this.view.getUint8(offset++); part2 |= (b & 0x7F) << 7; if (b & 0x80) {
|
||||
throw Error("Buffer overrun"); }}}}}}}}}}
|
||||
//? }
|
||||
var value = Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, false);
|
||||
if (relative) {
|
||||
this.offset = offset;
|
||||
return value;
|
||||
} else {
|
||||
return {
|
||||
'value': value,
|
||||
'length': offset-start
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reads a zig-zag encoded 64bit base 128 variable-length integer. Requires Long.js.
|
||||
* @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by the number of bytes
|
||||
* read if omitted.
|
||||
* @returns {!Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and
|
||||
* the actual number of bytes read.
|
||||
* @throws {Error} If it's not a valid varint
|
||||
* @expose
|
||||
*/
|
||||
ByteBufferPrototype.readVarint64ZigZag = function(offset) {
|
||||
var val = this.readVarint64(offset);
|
||||
if (val && val['value'] instanceof Long)
|
||||
val["value"] = ByteBuffer.zigZagDecode64(val["value"]);
|
||||
else
|
||||
val = ByteBuffer.zigZagDecode64(val);
|
||||
return val;
|
||||
};
|
||||
|
||||
} // Long
|
||||
|
||||
//? }
|
50
node_modules/bytebuffer/src/wrap-node.js
generated
vendored
Normal file
50
node_modules/bytebuffer/src/wrap-node.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright 2013-2014 Daniel Wirtz <dcode@dcode.io>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
//? NODE = true;
|
||||
|
||||
/**
|
||||
* @license bytebuffer.js (c) 2015 Daniel Wirtz <dcode@dcode.io>
|
||||
* Backing buffer / Accessor: node Buffer
|
||||
* Released under the Apache License, Version 2.0
|
||||
* see: https://github.com/dcodeIO/bytebuffer.js for details
|
||||
*/
|
||||
module.exports = (function() {
|
||||
"use strict";
|
||||
|
||||
var buffer = require("buffer"),
|
||||
Buffer = buffer["Buffer"],
|
||||
Long = require("long"),
|
||||
memcpy = null; try { memcpy = require("memcpy"); } catch (e) {}
|
||||
|
||||
//? include("ByteBuffer.js");
|
||||
|
||||
/**
|
||||
* node-memcpy. This is an optional binding dependency and may not be present.
|
||||
* @function
|
||||
* @param {!(Buffer|ArrayBuffer|Uint8Array)} target Destination
|
||||
* @param {number|!(Buffer|ArrayBuffer)} targetStart Destination start, defaults to 0.
|
||||
* @param {(!(Buffer|ArrayBuffer|Uint8Array)|number)=} source Source
|
||||
* @param {number=} sourceStart Source start, defaults to 0.
|
||||
* @param {number=} sourceEnd Source end, defaults to capacity.
|
||||
* @returns {number} Number of bytes copied
|
||||
* @throws {Error} If any index is out of bounds
|
||||
* @expose
|
||||
*/
|
||||
ByteBuffer.memcpy = memcpy;
|
||||
|
||||
return ByteBuffer;
|
||||
|
||||
})();
|
43
node_modules/bytebuffer/src/wrap.js
generated
vendored
Normal file
43
node_modules/bytebuffer/src/wrap.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
Copyright 2013-2014 Daniel Wirtz <dcode@dcode.io>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @license bytebuffer.js (c) 2015 Daniel Wirtz <dcode@dcode.io>
|
||||
//? if (DATAVIEW)
|
||||
* Backing buffer: ArrayBuffer, Accessor: DataView
|
||||
//? else
|
||||
* Backing buffer: ArrayBuffer, Accessor: Uint8Array
|
||||
* Released under the Apache License, Version 2.0
|
||||
* see: https://github.com/dcodeIO/bytebuffer.js for details
|
||||
*/
|
||||
(function(global, factory) {
|
||||
|
||||
/* AMD */ if (typeof define === 'function' && define["amd"])
|
||||
define(["long"], factory);
|
||||
/* CommonJS */ else if (typeof require === 'function' && typeof module === "object" && module && module["exports"])
|
||||
module['exports'] = (function() {
|
||||
var Long; try { Long = require("long"); } catch (e) {}
|
||||
return factory(Long);
|
||||
})();
|
||||
/* Global */ else
|
||||
(global["dcodeIO"] = global["dcodeIO"] || {})["ByteBuffer"] = factory(global["dcodeIO"]["Long"]);
|
||||
|
||||
})(this, function(Long) {
|
||||
"use strict";
|
||||
|
||||
//? include("bytebuffer.js");
|
||||
return ByteBuffer;
|
||||
});
|
Reference in New Issue
Block a user