Firebase Update
This commit is contained in:
88
express-server/node_modules/bytebuffer/src/encodings/base64.js
generated
vendored
Normal file
88
express-server/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
express-server/node_modules/bytebuffer/src/encodings/binary.js
generated
vendored
Normal file
74
express-server/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
express-server/node_modules/bytebuffer/src/encodings/debug.js
generated
vendored
Normal file
211
express-server/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
express-server/node_modules/bytebuffer/src/encodings/hex.js
generated
vendored
Normal file
75
express-server/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
express-server/node_modules/bytebuffer/src/encodings/impl/base64.js
generated
vendored
Normal file
3
express-server/node_modules/bytebuffer/src/encodings/impl/base64.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
// encodings/impl/base64
|
||||
|
||||
// TODO
|
65
express-server/node_modules/bytebuffer/src/encodings/impl/binary.js
generated
vendored
Normal file
65
express-server/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
express-server/node_modules/bytebuffer/src/encodings/impl/debug.js
generated
vendored
Normal file
3
express-server/node_modules/bytebuffer/src/encodings/impl/debug.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
// encodings/impl/debug
|
||||
|
||||
// TODO
|
101
express-server/node_modules/bytebuffer/src/encodings/impl/hex.js
generated
vendored
Normal file
101
express-server/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
express-server/node_modules/bytebuffer/src/encodings/impl/utf8.js
generated
vendored
Normal file
126
express-server/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
express-server/node_modules/bytebuffer/src/encodings/utf8.js
generated
vendored
Normal file
71
express-server/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;
|
||||
};
|
||||
|
||||
//? }
|
Reference in New Issue
Block a user