bytebuffer
Advanced tools
Comparing version 3.5.5 to 4.0.0
{ | ||
"name": "bytebuffer", | ||
"version": "3.5.5", | ||
"version": "4.0.0", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
@@ -5,0 +5,0 @@ "description": "A full-featured ByteBuffer implementation using typed arrays.", |
/* | ||
ByteBuffer.js (c) 2013-2014 Daniel Wirtz <dcode@dcode.io> | ||
This version of ByteBuffer.js uses an ArrayBuffer as its backing buffer which is accessed through a DataView and is | ||
compatible with modern browsers. | ||
ByteBuffer.js (c) 2015 Daniel Wirtz <dcode@dcode.io> | ||
[BUILD] ByteBufferAB - Backing buffer: ArrayBuffer, Accessor: Uint8Array | ||
Released under the Apache License, Version 2.0 | ||
see: https://github.com/dcodeIO/ByteBuffer.js for details | ||
*/ | ||
(function(s){function u(k){function g(a,b,c){"undefined"===typeof a&&(a=g.DEFAULT_CAPACITY);"undefined"===typeof b&&(b=g.DEFAULT_ENDIAN);"undefined"===typeof c&&(c=g.DEFAULT_NOASSERT);if(!c){a|=0;if(0>a)throw RangeError("Illegal capacity");b=!!b;c=!!c}this.buffer=0===a?s:new ArrayBuffer(a);this.view=0===a?null:new DataView(this.buffer);this.offset=0;this.markedOffset=-1;this.limit=a;this.littleEndian="undefined"!==typeof b?!!b:!1;this.noAssert=!!c}function m(a){var b=0;return function(){return b< | ||
a.length?a.charCodeAt(b++):null}}function t(){var a=[],b=[];return function(){if(0===arguments.length)return b.join("")+u.apply(String,a);1024<a.length+arguments.length&&(b.push(u.apply(String,a)),a.length=0);Array.prototype.push.apply(a,arguments)}}g.VERSION="3.5.5";g.LITTLE_ENDIAN=!0;g.BIG_ENDIAN=!1;g.DEFAULT_CAPACITY=16;g.DEFAULT_ENDIAN=g.BIG_ENDIAN;g.DEFAULT_NOASSERT=!1;g.Long=k||null;var e=g.prototype,s=new ArrayBuffer(0),u=String.fromCharCode;g.allocate=function(a,b,c){return new g(a,b,c)}; | ||
g.concat=function(a,b,c,d){if("boolean"===typeof b||"string"!==typeof b)d=c,c=b,b=void 0;for(var f=0,n=0,h=a.length,e;n<h;++n)g.isByteBuffer(a[n])||(a[n]=g.wrap(a[n],b)),e=a[n].limit-a[n].offset,0<e&&(f+=e);if(0===f)return new g(0,c,d);b=new g(f,c,d);d=new Uint8Array(b.buffer);for(n=0;n<h;)c=a[n++],e=c.limit-c.offset,0>=e||(d.set((new Uint8Array(c.buffer)).subarray(c.offset,c.limit),b.offset),b.offset+=e);b.limit=b.offset;b.offset=0;return b};g.isByteBuffer=function(a){return!0===(a&&a instanceof | ||
g)};g.type=function(){return ArrayBuffer};g.wrap=function(a,b,c,d){"string"!==typeof b&&(d=c,c=b,b=void 0);if("string"===typeof a)switch("undefined"===typeof b&&(b="utf8"),b){case "base64":return g.fromBase64(a,c);case "hex":return g.fromHex(a,c);case "binary":return g.fromBinary(a,c);case "utf8":return g.fromUTF8(a,c);case "debug":return g.fromDebug(a,c);default:throw Error("Unsupported encoding: "+b);}if(null===a||"object"!==typeof a)throw TypeError("Illegal buffer");if(g.isByteBuffer(a))return b= | ||
e.clone.call(a),b.markedOffset=-1,b;if(a instanceof Uint8Array)b=new g(0,c,d),0<a.length&&(b.buffer=a.buffer,b.offset=a.byteOffset,b.limit=a.byteOffset+a.length,b.view=0<a.length?new DataView(a.buffer):null);else if(a instanceof ArrayBuffer)b=new g(0,c,d),0<a.byteLength&&(b.buffer=a,b.offset=0,b.limit=a.byteLength,b.view=0<a.byteLength?new DataView(a):null);else if("[object Array]"===Object.prototype.toString.call(a))for(b=new g(a.length,c,d),b.limit=a.length,i=0;i<a.length;++i)b.view.setUint8(i, | ||
a[i]);else throw TypeError("Illegal buffer");return b};e.writeInt8=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=1;var d=this.buffer.byteLength;b>d&&this.resize((d*= | ||
2)>b?d:b);this.view.setInt8(b-1,a);c&&(this.offset+=1);return this};e.writeByte=e.writeInt8;e.readInt8=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}a=this.view.getInt8(a);b&&(this.offset+=1);return a};e.readByte=e.readInt8;e.writeUint8=function(a,b){var c= | ||
"undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=1;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view.setUint8(b-1,a);c&&(this.offset+=1);return this};e.readUint8= | ||
function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}a=this.view.getUint8(a);b&&(this.offset+=1);return a};e.writeInt16=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+ | ||
a+" (not an integer)");a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=2;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view.setInt16(b-2,a,this.littleEndian);c&&(this.offset+=2);return this};e.writeShort=e.writeInt16;e.readInt16=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!== | ||
typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+2) <= "+this.buffer.byteLength);}a=this.view.getInt16(a,this.littleEndian);b&&(this.offset+=2);return a};e.readShort=e.readInt16;e.writeUint16=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a>>>=0;if("number"!==typeof b|| | ||
0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=2;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view.setUint16(b-2,a,this.littleEndian);c&&(this.offset+=2);return this};e.readUint16=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)"); | ||
a>>>=0;if(0>a||a+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+2) <= "+this.buffer.byteLength);}a=this.view.getUint16(a,this.littleEndian);b&&(this.offset+=2);return a};e.writeInt32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+ | ||
b+" (+0) <= "+this.buffer.byteLength);}b+=4;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view.setInt32(b-4,a,this.littleEndian);c&&(this.offset+=4);return this};e.writeInt=e.writeInt32;e.readInt32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength); | ||
}a=this.view.getInt32(a,this.littleEndian);b&&(this.offset+=4);return a};e.readInt=e.readInt32;e.writeUint32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+= | ||
4;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view.setUint32(b-4,a,this.littleEndian);c&&(this.offset+=4);return this};e.readUint32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength);}a=this.view.getUint32(a,this.littleEndian);b&&(this.offset+= | ||
4);return a};k&&(e.writeInt64=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"===typeof a)a=k.fromNumber(a);else if("string"===typeof a)a=k.fromString(a);else if(!(a&&a instanceof k))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength); | ||
}"number"===typeof a?a=k.fromNumber(a):"string"===typeof a&&(a=k.fromString(a));b+=8;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=8;this.littleEndian?(this.view.setInt32(b,a.low,!0),this.view.setInt32(b+4,a.high,!0)):(this.view.setInt32(b,a.high,!1),this.view.setInt32(b+4,a.low,!1));c&&(this.offset+=8);return this},e.writeLong=e.writeInt64,e.readInt64=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+ | ||
a+" (not an integer)");a>>>=0;if(0>a||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength);}a=this.littleEndian?new k(this.view.getInt32(a,!0),this.view.getInt32(a+4,!0),!1):new k(this.view.getInt32(a+4,!1),this.view.getInt32(a,!1),!1);b&&(this.offset+=8);return a},e.readLong=e.readInt64,e.writeUint64=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"===typeof a)a=k.fromNumber(a);else if("string"===typeof a)a= | ||
k.fromString(a);else if(!(a&&a instanceof k))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}"number"===typeof a?a=k.fromNumber(a):"string"===typeof a&&(a=k.fromString(a));b+=8;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=8;this.littleEndian?(this.view.setInt32(b, | ||
a.low,!0),this.view.setInt32(b+4,a.high,!0)):(this.view.setInt32(b,a.high,!1),this.view.setInt32(b+4,a.low,!1));c&&(this.offset+=8);return this},e.readUint64=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength);}a=this.littleEndian?new k(this.view.getInt32(a,!0),this.view.getInt32(a+ | ||
4,!0),!0):new k(this.view.getInt32(a+4,!1),this.view.getInt32(a,!1),!0);b&&(this.offset+=8);return a});e.writeFloat32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a)throw TypeError("Illegal value: "+a+" (not a number)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=4;var d=this.buffer.byteLength; | ||
b>d&&this.resize((d*=2)>b?d:b);this.view.setFloat32(b-4,a,this.littleEndian);c&&(this.offset+=4);return this};e.writeFloat=e.writeFloat32;e.readFloat32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength);}a=this.view.getFloat32(a,this.littleEndian);b&&(this.offset+= | ||
4);return a};e.readFloat=e.readFloat32;e.writeFloat64=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a)throw TypeError("Illegal value: "+a+" (not a number)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=8;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view.setFloat64(b- | ||
8,a,this.littleEndian);c&&(this.offset+=8);return this};e.writeDouble=e.writeFloat64;e.readFloat64=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength);}a=this.view.getFloat64(a,this.littleEndian);b&&(this.offset+=8);return a};e.readDouble=e.readFloat64;g.MAX_VARINT32_BYTES= | ||
5;g.calculateVarint32=function(a){a>>>=0;return 128>a?1:16384>a?2:2097152>a?3:268435456>a?4:5};g.zigZagEncode32=function(a){return((a|=0)<<1^a>>31)>>>0};g.zigZagDecode32=function(a){return a>>>1^-(a&1)|0};e.writeVarint32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b|| | ||
b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}var d=g.calculateVarint32(a);b+=d;var f=this.buffer.byteLength;b>f&&this.resize((f*=2)>b?f:b);b-=d;this.view.setUint8(b,d=a|128);a>>>=0;128<=a?(d=a>>7|128,this.view.setUint8(b+1,d),16384<=a?(d=a>>14|128,this.view.setUint8(b+2,d),2097152<=a?(d=a>>21|128,this.view.setUint8(b+3,d),268435456<=a?(this.view.setUint8(b+4,a>>28&15),d=5):(this.view.setUint8(b+3,d&127),d=4)):(this.view.setUint8(b+2,d& | ||
127),d=3)):(this.view.setUint8(b+1,d&127),d=2)):(this.view.setUint8(b,d&127),d=1);return c?(this.offset+=d,this):d};e.writeVarint32ZigZag=function(a,b){return this.writeVarint32(g.zigZagEncode32(a),b)};e.readVarint32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength); | ||
}var c=0,d=0,f;do{f=a+c;if(!this.noAssert&&f>this.limit)throw a=Error("Truncated"),a.truncated=!0,a;f=this.view.getUint8(f);5>c&&(d|=(f&127)<<7*c>>>0);++c}while(128===(f&128));d|=0;return b?(this.offset+=c,d):{value:d,length:c}};e.readVarint32ZigZag=function(a){a=this.readVarint32(a);"object"===typeof a?a.value=g.zigZagDecode32(a.value):a=g.zigZagDecode32(a);return a};k&&(g.MAX_VARINT64_BYTES=10,g.calculateVarint64=function(a){"number"===typeof a?a=k.fromNumber(a):"string"===typeof a&&(a=k.fromString(a)); | ||
var b=a.toInt()>>>0,c=a.shiftRightUnsigned(28).toInt()>>>0;a=a.shiftRightUnsigned(56).toInt()>>>0;return 0==a?0==c?16384>b?128>b?1:2:2097152>b?3:4:16384>c?128>c?5:6:2097152>c?7:8:128>a?9:10},g.zigZagEncode64=function(a){"number"===typeof a?a=k.fromNumber(a,!1):"string"===typeof a?a=k.fromString(a,!1):!1!==a.unsigned&&(a=a.toSigned());return a.shiftLeft(1).xor(a.shiftRight(63)).toUnsigned()},g.zigZagDecode64=function(a){"number"===typeof a?a=k.fromNumber(a,!1):"string"===typeof a?a=k.fromString(a, | ||
!1):!1!==a.unsigned&&(a=a.toSigned());return a.shiftRightUnsigned(1).xor(a.and(k.ONE).toSigned().negate()).toSigned()},e.writeVarint64=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"===typeof a)a=k.fromNumber(a);else if("string"===typeof a)a=k.fromString(a);else if(!(a&&a instanceof k))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b|| | ||
b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}"number"===typeof a?a=k.fromNumber(a,!1):"string"===typeof a?a=k.fromString(a,!1):!1!==a.unsigned&&(a=a.toSigned());var d=g.calculateVarint64(a),f=a.toInt()>>>0,e=a.shiftRightUnsigned(28).toInt()>>>0,h=a.shiftRightUnsigned(56).toInt()>>>0;b+=d;var r=this.buffer.byteLength;b>r&&this.resize((r*=2)>b?r:b);b-=d;switch(d){case 10:this.view.setUint8(b+9,h>>>7&1);case 9:this.view.setUint8(b+8,9!==d? | ||
h|128:h&127);case 8:this.view.setUint8(b+7,8!==d?e>>>21|128:e>>>21&127);case 7:this.view.setUint8(b+6,7!==d?e>>>14|128:e>>>14&127);case 6:this.view.setUint8(b+5,6!==d?e>>>7|128:e>>>7&127);case 5:this.view.setUint8(b+4,5!==d?e|128:e&127);case 4:this.view.setUint8(b+3,4!==d?f>>>21|128:f>>>21&127);case 3:this.view.setUint8(b+2,3!==d?f>>>14|128:f>>>14&127);case 2:this.view.setUint8(b+1,2!==d?f>>>7|128:f>>>7&127);case 1:this.view.setUint8(b,1!==d?f|128:f&127)}return c?(this.offset+=d,this):d},e.writeVarint64ZigZag= | ||
function(a,b){return this.writeVarint64(g.zigZagEncode64(a),b)},e.readVarint64=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}var c=a,d=0,f=0,e=0,h=0,h=this.view.getUint8(a++),d=h&127;if(h&128&&(h=this.view.getUint8(a++),d|=(h&127)<<7,h&128&&(h=this.view.getUint8(a++), | ||
d|=(h&127)<<14,h&128&&(h=this.view.getUint8(a++),d|=(h&127)<<21,h&128&&(h=this.view.getUint8(a++),f=h&127,h&128&&(h=this.view.getUint8(a++),f|=(h&127)<<7,h&128&&(h=this.view.getUint8(a++),f|=(h&127)<<14,h&128&&(h=this.view.getUint8(a++),f|=(h&127)<<21,h&128&&(h=this.view.getUint8(a++),e=h&127,h&128&&(h=this.view.getUint8(a++),e|=(h&127)<<7,h&128))))))))))throw Error("Buffer overrun");d=k.fromBits(d|f<<28,f>>>4|e<<24,!1);return b?(this.offset=a,d):{value:d,length:a-c}},e.readVarint64ZigZag=function(a){(a= | ||
this.readVarint64(a))&&a.value instanceof k?a.value=g.zigZagDecode64(a.value):a=g.zigZagDecode64(a);return a});e.writeCString=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);var d,f=a.length;if(!this.noAssert){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");for(d=0;d<f;++d)if(0===a.charCodeAt(d))throw RangeError("Illegal str: Contains NULL-characters");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+ | ||
b+" (+0) <= "+this.buffer.byteLength);}f=l.a(m(a))[1];b+=f+1;d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=f+1;l.c(m(a),function(a){this.view.setUint8(b++,a)}.bind(this));this.view.setUint8(b++,0);return c?(this.offset=b,this):f};e.readCString=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+ | ||
a+" (+1) <= "+this.buffer.byteLength);}var c=a,d,f=-1;l.b(function(){if(0===f)return null;if(a>=this.limit)throw RangeError("Illegal range: Truncated data, "+a+" < "+this.limit);return 0===(f=this.view.getUint8(a++))?null:f}.bind(this),d=t(),!0);return b?(this.offset=a,d()):{string:d(),length:a-c}};e.writeIString=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+ | ||
b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}var d=b,f;f=l.a(m(a),this.noAssert)[1];b+=4+f;var e=this.buffer.byteLength;b>e&&this.resize((e*=2)>b?e:b);b-=4+f;this.view.setUint32(b,f,this.littleEndian);b+=4;l.c(m(a),function(a){this.view.setUint8(b++,a)}.bind(this));if(b!==d+4+f)throw RangeError("Illegal range: Truncated data, "+b+" == "+(b+4+f));return c?(this.offset=b,this):b-d};e.readIString=function(a){var b= | ||
"undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength);}var c=0,d=a,c=this.view.getUint32(a,this.littleEndian);a+=4;var f=a+c;l.b(function(){return a<f?this.view.getUint8(a++):null}.bind(this),c=t(),this.noAssert);c=c();return b?(this.offset=a,c):{string:c,length:a-d}};g.METRICS_CHARS= | ||
"c";g.METRICS_BYTES="b";e.writeUTF8String=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}var d,f=b;d=l.a(m(a))[1];b+=d;var e=this.buffer.byteLength;b>e&&this.resize((e*=2)>b?e:b);b-=d;l.c(m(a),function(a){this.view.setUint8(b++,a)}.bind(this));return c?(this.offset= | ||
b,this):b-f};e.writeString=e.writeUTF8String;g.calculateUTF8Chars=function(a){return l.a(m(a))[0]};g.calculateUTF8Bytes=function(a){return l.a(m(a))[1]};e.readUTF8String=function(a,b,c){"number"===typeof b&&(c=b,b=void 0);var d="undefined"===typeof c;d&&(c=this.offset);"undefined"===typeof b&&(b=g.METRICS_CHARS);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal length: "+a+" (not an integer)");a|=0;if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+c+" (not an integer)"); | ||
c>>>=0;if(0>c||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength);}var f=0,e=c,h;if(b===g.METRICS_CHARS){h=t();l.g(function(){return f<a&&c<this.limit?this.view.getUint8(c++):null}.bind(this),function(a){++f;l.e(a,h)}.bind(this));if(f!==a)throw RangeError("Illegal range: Truncated data, "+f+" == "+a);return d?(this.offset=c,h()):{string:h(),length:c-e}}if(b===g.METRICS_BYTES){if(!this.noAssert){if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+ | ||
c+" (not an integer)");c>>>=0;if(0>c||c+a>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+"+a+") <= "+this.buffer.byteLength);}var r=c+a;l.b(function(){return c<r?this.view.getUint8(c++):null}.bind(this),h=t(),this.noAssert);if(c!==r)throw RangeError("Illegal range: Truncated data, "+c+" == "+r);return d?(this.offset=c,h()):{string:h(),length:c-e}}throw TypeError("Unsupported metrics: "+b);};e.readString=e.readUTF8String;e.writeVString=function(a,b){var c="undefined"===typeof b; | ||
c&&(b=this.offset);if(!this.noAssert){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}var d=b,f,e;f=l.a(m(a),this.noAssert)[1];e=g.calculateVarint32(f);b+=e+f;var h=this.buffer.byteLength;b>h&&this.resize((h*=2)>b?h:b);b-=e+f;b+=this.writeVarint32(f,b);l.c(m(a),function(a){this.view.setUint8(b++, | ||
a)}.bind(this));if(b!==d+f+e)throw RangeError("Illegal range: Truncated data, "+b+" == "+(b+f+e));return c?(this.offset=b,this):b-d};e.readVString=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}var c=this.readVarint32(a),d=a;a+=c.length;var c=c.value,f=a+c, | ||
c=t();l.b(function(){return a<f?this.view.getUint8(a++):null}.bind(this),c,this.noAssert);c=c();return b?(this.offset=a,c):{string:c,length:a-d}};e.append=function(a,b,c){if("number"===typeof b||"string"!==typeof b)c=b,b=void 0;var d="undefined"===typeof c;d&&(c=this.offset);if(!this.noAssert){if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+c+" (not an integer)");c>>>=0;if(0>c||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength); | ||
}a instanceof g||(a=g.wrap(a,b));b=a.limit-a.offset;if(0>=b)return this;c+=b;var f=this.buffer.byteLength;c>f&&this.resize((f*=2)>c?f:c);(new Uint8Array(this.buffer,c-b)).set((new Uint8Array(a.buffer)).subarray(a.offset,a.limit));a.offset+=b;d&&(this.offset+=b);return this};e.appendTo=function(a,b){a.append(this,b);return this};e.assert=function(a){this.noAssert=!a;return this};e.capacity=function(){return this.buffer.byteLength};e.clear=function(){this.offset=0;this.limit=this.buffer.byteLength; | ||
this.markedOffset=-1;return this};e.clone=function(a){var b=new g(0,this.littleEndian,this.noAssert);a?(a=new ArrayBuffer(this.buffer.byteLength),(new Uint8Array(a)).set(this.buffer),b.buffer=a,b.view=new DataView(a)):(b.buffer=this.buffer,b.view=this.view);b.offset=this.offset;b.markedOffset=this.markedOffset;b.limit=this.limit;return b};e.compact=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer"); | ||
a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}if(0===a&&b===this.buffer.byteLength)return this;var c=b-a;if(0===c)return this.buffer=s,this.view=null,0<=this.markedOffset&&(this.markedOffset-=a),this.limit=this.offset=0,this;var d=new ArrayBuffer(c);(new Uint8Array(d)).set((new Uint8Array(this.buffer)).subarray(a,b));this.buffer=d; | ||
this.view=new DataView(d);0<=this.markedOffset&&(this.markedOffset-=a);this.offset=0;this.limit=c;return this};e.copy=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength); | ||
}if(a===b)return new g(0,this.littleEndian,this.noAssert);var c=b-a,d=new g(c,this.littleEndian,this.noAssert);d.offset=0;d.limit=c;0<=d.markedOffset&&(d.markedOffset-=a);this.copyTo(d,0,a,b);return d};e.copyTo=function(a,b,c,d){var f,e;if(!this.noAssert&&!g.isByteBuffer(a))throw TypeError("Illegal target: Not a ByteBuffer");b=(e="undefined"===typeof b)?a.offset:b|0;c=(f="undefined"===typeof c)?this.offset:c|0;d="undefined"===typeof d?this.limit:d|0;if(0>b||b>a.buffer.byteLength)throw RangeError("Illegal target range: 0 <= "+ | ||
b+" <= "+a.buffer.byteLength);if(0>c||d>this.buffer.byteLength)throw RangeError("Illegal source range: 0 <= "+c+" <= "+this.buffer.byteLength);var h=d-c;if(0===h)return a;a.ensureCapacity(b+h);(new Uint8Array(a.buffer)).set((new Uint8Array(this.buffer)).subarray(c,d),b);f&&(this.offset+=h);e&&(a.offset+=h);return this};e.ensureCapacity=function(a){var b=this.buffer.byteLength;return b<a?this.resize((b*=2)>a?b:a):this};e.fill=function(a,b,c){var d="undefined"===typeof b;d&&(b=this.offset);"string"=== | ||
typeof a&&0<a.length&&(a=a.charCodeAt(0));"undefined"===typeof b&&(b=this.offset);"undefined"===typeof c&&(c=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal begin: Not an integer");b>>>=0;if("number"!==typeof c||0!==c%1)throw TypeError("Illegal end: Not an integer");c>>>=0;if(0>b||b>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+b+" <= "+c+" <= "+ | ||
this.buffer.byteLength);}if(b>=c)return this;for(;b<c;)this.view.setUint8(b++,a);d&&(this.offset=b);return this};e.flip=function(){this.limit=this.offset;this.offset=0;return this};e.mark=function(a){a="undefined"===typeof a?this.offset:a;if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+0) <= "+this.buffer.byteLength);}this.markedOffset=a;return this}; | ||
e.order=function(a){if(!this.noAssert&&"boolean"!==typeof a)throw TypeError("Illegal littleEndian: Not a boolean");this.littleEndian=!!a;return this};e.LE=function(a){this.littleEndian="undefined"!==typeof a?!!a:!0;return this};e.BE=function(a){this.littleEndian="undefined"!==typeof a?!a:!1;return this};e.prepend=function(a,b,c){if("number"===typeof b||"string"!==typeof b)c=b,b=void 0;var d="undefined"===typeof c;d&&(c=this.offset);if(!this.noAssert){if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+ | ||
c+" (not an integer)");c>>>=0;if(0>c||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength);}a instanceof g||(a=g.wrap(a,b));b=a.limit-a.offset;if(0>=b)return this;var f=b-c,e;if(0<f){var h=new ArrayBuffer(this.buffer.byteLength+f);e=new Uint8Array(h);e.set((new Uint8Array(this.buffer)).subarray(c,this.buffer.byteLength),b);this.buffer=h;this.view=new DataView(h);this.offset+=f;0<=this.markedOffset&&(this.markedOffset+=f);this.limit+=f;c+=f}else e= | ||
new Uint8Array(this.buffer);e.set((new Uint8Array(a.buffer)).subarray(a.offset,a.limit),c-b);a.offset=a.limit;d&&(this.offset-=b);return this};e.prependTo=function(a,b){a.prepend(this,b);return this};e.printDebug=function(a){"function"!==typeof a&&(a=console.log.bind(console));a(this.toString()+"\n-------------------------------------------------------------------\n"+this.toDebug(!0))};e.remaining=function(){return this.limit-this.offset};e.reset=function(){0<=this.markedOffset?(this.offset=this.markedOffset, | ||
this.markedOffset=-1):this.offset=0;return this};e.resize=function(a){if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal capacity: "+a+" (not an integer)");a|=0;if(0>a)throw RangeError("Illegal capacity: 0 <= "+a);}this.buffer.byteLength<a&&(a=new ArrayBuffer(a),(new Uint8Array(a)).set(new Uint8Array(this.buffer)),this.buffer=a,this.view=new DataView(a));return this};e.reverse=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!== | ||
typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}if(a===b)return this;Array.prototype.reverse.call((new Uint8Array(this.buffer)).subarray(a,b));this.view=new DataView(this.buffer);return this};e.skip=function(a){if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal length: "+ | ||
a+" (not an integer)");a|=0}var b=this.offset+a;if(!this.noAssert&&(0>b||b>this.buffer.byteLength))throw RangeError("Illegal length: 0 <= "+this.offset+" + "+a+" <= "+this.buffer.byteLength);this.offset=b;return this};e.slice=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer"); | ||
b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}var c=this.clone();c.offset=a;c.limit=b;return c};e.toBuffer=function(a){var b=this.offset,c=this.limit;if(b>c)var d=b,b=c,c=d;if(!this.noAssert){if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: Not an integer");b>>>=0;if("number"!==typeof c||0!==c%1)throw TypeError("Illegal limit: Not an integer");c>>>=0;if(0>b||b>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+ | ||
b+" <= "+c+" <= "+this.buffer.byteLength);}if(!a&&0===b&&c===this.buffer.byteLength)return this.buffer;if(b===c)return s;a=new ArrayBuffer(c-b);(new Uint8Array(a)).set((new Uint8Array(this.buffer)).subarray(b,c),0);return a};e.toArrayBuffer=e.toBuffer;e.toString=function(a,b,c){if("undefined"===typeof a)return"ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";"number"===typeof a&&(c=b=a="utf8");switch(a){case "utf8":return this.toUTF8(b, | ||
c);case "base64":return this.toBase64(b,c);case "hex":return this.toHex(b,c);case "binary":return this.toBinary(b,c);case "debug":return this.toDebug();case "columns":return this.m();default:throw Error("Unsupported encoding: "+a);}};var v=function(){for(var a={},b=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47],c=[],d=0,f=b.length;d< | ||
f;++d)c[b[d]]=d;a.i=function(a,c){for(var d,f;null!==(d=a());)c(b[d>>2&63]),f=(d&3)<<4,null!==(d=a())?(f|=d>>4&15,c(b[(f|d>>4&15)&63]),f=(d&15)<<2,null!==(d=a())?(c(b[(f|d>>6&3)&63]),c(b[d&63])):(c(b[f&63]),c(61))):(c(b[f&63]),c(61),c(61))};a.h=function(a,b){function d(a){throw Error("Illegal character code: "+a);}for(var f,e,g;null!==(f=a());)if(e=c[f],"undefined"===typeof e&&d(f),null!==(f=a())&&(g=c[f],"undefined"===typeof g&&d(f),b(e<<2>>>0|(g&48)>>4),null!==(f=a()))){e=c[f];if("undefined"=== | ||
typeof e)if(61===f)break;else d(f);b((g&15)<<4>>>0|(e&60)>>2);if(null!==(f=a())){g=c[f];if("undefined"===typeof g)if(61===f)break;else d(f);b((e&3)<<6>>>0|g)}}};a.test=function(a){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(a)};return a}();e.toBase64=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b|| | ||
0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}var c;v.i(function(){return a<b?this.view.getUint8(a++):null}.bind(this),c=t());return c()};g.fromBase64=function(a,b,c){if(!c){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");if(0!==a.length%4)throw TypeError("Illegal str: Length not a multiple of 4");}var d=new g(a.length/4*3,b,c),f=0;v.h(m(a),function(a){d.view.setUint8(f++, | ||
a)});d.limit=f;return d};g.btoa=function(a){return g.fromBinary(a).toBase64()};g.atob=function(a){return g.fromBase64(a).toBinary()};e.toBinary=function(a,b){a="undefined"===typeof a?this.offset:a;b="undefined"===typeof b?this.limit:b;if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+ | ||
a+" <= "+b+" <= "+this.buffer.byteLength);}if(a===b)return"";for(var c=[],d=[];a<b;)c.push(this.view.getUint8(a++)),1024<=c.length&&(d.push(String.fromCharCode.apply(String,c)),c=[]);return d.join("")+String.fromCharCode.apply(String,c)};g.fromBinary=function(a,b,c){if(!c&&"string"!==typeof a)throw TypeError("Illegal str: Not a string");for(var d=0,f=a.length,e=new g(f,b,c);d<f;){b=a.charCodeAt(d);if(!c&&255<b)throw RangeError("Illegal charCode at "+d+": 0 <= "+b+" <= 255");e.view.setUint8(d++,b)}e.limit= | ||
f;return e};e.toDebug=function(a){for(var b=-1,c=this.buffer.byteLength,d,f="",e="",g="";b<c;){-1!==b&&(d=this.view.getUint8(b),f=16>d?f+("0"+d.toString(16).toUpperCase()):f+d.toString(16).toUpperCase(),a&&(e+=32<d&&127>d?String.fromCharCode(d):"."));++b;if(a&&0<b&&0===b%16&&b!==c){for(;51>f.length;)f+=" ";g+=f+e+"\n";f=e=""}f=b===this.offset&&b===this.limit?f+(b===this.markedOffset?"!":"|"):b===this.offset?f+(b===this.markedOffset?"[":"<"):b===this.limit?f+(b===this.markedOffset?"]":">"):f+(b=== | ||
this.markedOffset?"'":a||0!==b&&b!==c?" ":"")}if(a&&" "!==f){for(;51>f.length;)f+=" ";g+=f+e+"\n"}return a?g:f};g.fromDebug=function(a,b,c){var d=a.length;b=new g((d+1)/3|0,b,c);for(var f=0,e=0,h,k=!1,l=!1,m=!1,q=!1,p=!1;f<d;){switch(h=a.charAt(f++)){case "!":if(!c){if(l||m||q){p=!0;break}l=m=q=!0}b.offset=b.markedOffset=b.limit=e;k=!1;break;case "|":if(!c){if(l||q){p=!0;break}l=q=!0}b.offset=b.limit=e;k=!1;break;case "[":if(!c){if(l||m){p=!0;break}l=m=!0}b.offset=b.markedOffset=e;k=!1;break;case "<":if(!c){if(l){p= | ||
!0;break}l=!0}b.offset=e;k=!1;break;case "]":if(!c){if(q||m){p=!0;break}q=m=!0}b.limit=b.markedOffset=e;k=!1;break;case ">":if(!c){if(q){p=!0;break}q=!0}b.limit=e;k=!1;break;case "'":if(!c){if(m){p=!0;break}m=!0}b.markedOffset=e;k=!1;break;case " ":k=!1;break;default:if(!c&&k){p=!0;break}h=parseInt(h+a.charAt(f++),16);if(!c&&(isNaN(h)||0>h||255<h))throw TypeError("Illegal str: Not a debug encoded string");b.view.setUint8(e++,h);k=!0}if(p)throw TypeError("Illegal str: Invalid symbol at "+f);}if(!c){if(!l|| | ||
!q)throw TypeError("Illegal str: Missing offset or limit");if(e<b.buffer.byteLength)throw TypeError("Illegal str: Not a debug encoded string (is it hex?) "+e+" < "+d);}return b};e.toHex=function(a,b){a="undefined"===typeof a?this.offset:a;b="undefined"===typeof b?this.limit:b;if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+ | ||
a+" <= "+b+" <= "+this.buffer.byteLength);}for(var c=Array(b-a),d;a<b;)d=this.view.getUint8(a++),16>d?c.push("0",d.toString(16)):c.push(d.toString(16));return c.join("")};g.fromHex=function(a,b,c){if(!c){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");if(0!==a.length%2)throw TypeError("Illegal str: Length not a multiple of 2");}var d=a.length;b=new g(d/2|0,b);for(var f,e=0,h=0;e<d;e+=2){f=parseInt(a.substring(e,e+2),16);if(!c&&(!isFinite(f)||0>f||255<f))throw TypeError("Illegal str: Contains non-hex characters"); | ||
b.view.setUint8(h++,f)}b.limit=h;return b};var l=function(){var a={k:1114111,j:function(a,c){var d=null;"number"===typeof a&&(d=a,a=function(){return null});for(;null!==d||null!==(d=a());)128>d?c(d&127):(2048>d?c(d>>6&31|192):(65536>d?c(d>>12&15|224):(c(d>>18&7|240),c(d>>12&63|128)),c(d>>6&63|128)),c(d&63|128)),d=null},g:function(a,c){function d(a){a=a.slice(0,a.indexOf(null));var b=Error(a.toString());b.name="TruncatedError";b.bytes=a;throw b;}for(var e,g,h,k;null!==(e=a());)if(0===(e&128))c(e); | ||
else if(192===(e&224))null===(g=a())&&d([e,g]),c((e&31)<<6|g&63);else if(224===(e&240))null!==(g=a())&&null!==(h=a())||d([e,g,h]),c((e&15)<<12|(g&63)<<6|h&63);else if(240===(e&248))null!==(g=a())&&null!==(h=a())&&null!==(k=a())||d([e,g,h,k]),c((e&7)<<18|(g&63)<<12|(h&63)<<6|k&63);else throw RangeError("Illegal starting byte: "+e);},d:function(a,c){for(var d,e=null;null!==(d=null!==e?e:a());)55296<=d&&57343>=d&&null!==(e=a())&&56320<=e&&57343>=e?(c(1024*(d-55296)+e-56320+65536),e=null):c(d);null!== | ||
e&&c(e)},e:function(a,c){var d=null;"number"===typeof a&&(d=a,a=function(){return null});for(;null!==d||null!==(d=a());)65535>=d?c(d):(d-=65536,c((d>>10)+55296),c(d%1024+56320)),d=null},c:function(b,c){a.d(b,function(b){a.j(b,c)})},b:function(b,c){a.g(b,function(b){a.e(b,c)})},f:function(a){return 128>a?1:2048>a?2:65536>a?3:4},l:function(b){for(var c,d=0;null!==(c=b());)d+=a.f(c);return d},a:function(b){var c=0,d=0;a.d(b,function(b){++c;d+=a.f(b)});return[c,d]}};return a}();e.toUTF8=function(a,b){"undefined"=== | ||
typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}var c;try{l.b(function(){return a<b?this.view.getUint8(a++):null}.bind(this),c=t())}catch(d){if(a!==b)throw RangeError("Illegal range: Truncated data, "+ | ||
a+" != "+b);}return c()};g.fromUTF8=function(a,b,c){if(!c&&"string"!==typeof a)throw TypeError("Illegal str: Not a string");var d=new g(l.a(m(a),!0)[1],b,c),e=0;l.c(m(a),function(a){d.view.setUint8(e++,a)});d.limit=e;return d};return g}"function"===typeof require&&"object"===typeof module&&module&&"object"===typeof exports&&exports?module.exports=function(){var k;try{k=require("long")}catch(g){}return u(k)}():"function"===typeof define&&define.amd?define("ByteBuffer",["Long"],function(k){return u(k)}): | ||
(s.dcodeIO=s.dcodeIO||{}).ByteBuffer=u(s.dcodeIO.Long)})(this); | ||
function u(k){function g(a,b,c){"undefined"===typeof a&&(a=g.DEFAULT_CAPACITY);"undefined"===typeof b&&(b=g.DEFAULT_ENDIAN);"undefined"===typeof c&&(c=g.DEFAULT_NOASSERT);if(!c){a|=0;if(0>a)throw RangeError("Illegal capacity");b=!!b;c=!!c}this.buffer=0===a?v:new ArrayBuffer(a);this.view=0===a?null:new Uint8Array(this.buffer);this.offset=0;this.markedOffset=-1;this.limit=a;this.littleEndian="undefined"!==typeof b?!!b:!1;this.noAssert=!!c}function m(a){var b=0;return function(){return b<a.length?a.charCodeAt(b++): | ||
null}}function s(){var a=[],b=[];return function(){if(0===arguments.length)return b.join("")+w.apply(String,a);1024<a.length+arguments.length&&(b.push(w.apply(String,a)),a.length=0);Array.prototype.push.apply(a,arguments)}}function x(a,b,c,d,e){var n;n=8*e-d-1;var h=(1<<n)-1,f=h>>1,g=-7;e=c?e-1:0;var q=c?-1:1,k=a[b+e];e+=q;c=k&(1<<-g)-1;k>>=-g;for(g+=n;0<g;c=256*c+a[b+e],e+=q,g-=8);n=c&(1<<-g)-1;c>>=-g;for(g+=d;0<g;n=256*n+a[b+e],e+=q,g-=8);if(0===c)c=1-f;else{if(c===h)return n?NaN:Infinity*(k?-1: | ||
1);n+=Math.pow(2,d);c-=f}return(k?-1:1)*n*Math.pow(2,c-d)}function z(a,b,c,d,e,n){var f,g=8*n-e-1,t=(1<<g)-1,k=t>>1,y=23===e?Math.pow(2,-24)-Math.pow(2,-77):0;n=d?0:n-1;var l=d?1:-1,m=0>b||0===b&&0>1/b?1:0;b=Math.abs(b);isNaN(b)||Infinity===b?(b=isNaN(b)?1:0,d=t):(d=Math.floor(Math.log(b)/Math.LN2),1>b*(f=Math.pow(2,-d))&&(d--,f*=2),b=1<=d+k?b+y/f:b+y*Math.pow(2,1-k),2<=b*f&&(d++,f/=2),d+k>=t?(b=0,d=t):1<=d+k?(b=(b*f-1)*Math.pow(2,e),d+=k):(b=b*Math.pow(2,k-1)*Math.pow(2,e),d=0));for(;8<=e;a[c+n]= | ||
b&255,n+=l,b/=256,e-=8);d=d<<e|b;for(g+=e;0<g;a[c+n]=d&255,n+=l,d/=256,g-=8);a[c+n-l]|=128*m}g.VERSION="4.0.0";g.LITTLE_ENDIAN=!0;g.BIG_ENDIAN=!1;g.DEFAULT_CAPACITY=16;g.DEFAULT_ENDIAN=g.BIG_ENDIAN;g.DEFAULT_NOASSERT=!1;g.Long=k||null;var f=g.prototype;Object.defineProperty(f,"__isByteBuffer__",{value:!0,enumerable:!1,configurable:!1});var v=new ArrayBuffer(0),w=String.fromCharCode;g.accessor=function(){return Uint8Array};g.allocate=function(a,b,c){return new g(a,b,c)};g.concat=function(a,b,c,d){if("boolean"=== | ||
typeof b||"string"!==typeof b)d=c,c=b,b=void 0;for(var e=0,f=0,h=a.length,p;f<h;++f)g.isByteBuffer(a[f])||(a[f]=g.wrap(a[f],b)),p=a[f].limit-a[f].offset,0<p&&(e+=p);if(0===e)return new g(0,c,d);b=new g(e,c,d);for(f=0;f<h;)c=a[f++],p=c.limit-c.offset,0>=p||(b.view.set(c.view.subarray(c.offset,c.limit),b.offset),b.offset+=p);b.limit=b.offset;b.offset=0;return b};g.isByteBuffer=function(a){return!0===(a&&a.__isByteBuffer__)};g.type=function(){return ArrayBuffer};g.wrap=function(a,b,c,d){"string"!==typeof b&& | ||
(d=c,c=b,b=void 0);if("string"===typeof a)switch("undefined"===typeof b&&(b="utf8"),b){case "base64":return g.fromBase64(a,c);case "hex":return g.fromHex(a,c);case "binary":return g.fromBinary(a,c);case "utf8":return g.fromUTF8(a,c);case "debug":return g.fromDebug(a,c);default:throw Error("Unsupported encoding: "+b);}if(null===a||"object"!==typeof a)throw TypeError("Illegal buffer");if(g.isByteBuffer(a))return b=f.clone.call(a),b.markedOffset=-1,b;if(a instanceof Uint8Array)b=new g(0,c,d),0<a.length&& | ||
(b.buffer=a.buffer,b.offset=a.byteOffset,b.limit=a.byteOffset+a.byteLength,b.view=new Uint8Array(a.buffer));else if(a instanceof ArrayBuffer)b=new g(0,c,d),0<a.byteLength&&(b.buffer=a,b.offset=0,b.limit=a.byteLength,b.view=0<a.byteLength?new Uint8Array(a):null);else if("[object Array]"===Object.prototype.toString.call(a))for(b=new g(a.length,c,d),b.limit=a.length,c=0;c<a.length;++c)b.view[c]=a[c];else throw TypeError("Illegal buffer");return b};f.readBytes=function(a,b){var c="undefined"===typeof b; | ||
c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+a>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+"+a+") <= "+this.buffer.byteLength);}var d=this.slice(b,b+a);c&&(this.offset+=a);return d};f.writeBytes=f.append;f.writeInt8=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)"); | ||
a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=1;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view[b-1]=a;c&&(this.offset+=1);return this};f.writeByte=f.writeInt8;f.readInt8=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+ | ||
a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}a=this.view[a];128===(a&128)&&(a=-(255-a+1));b&&(this.offset+=1);return a};f.readByte=f.readInt8;f.writeUint8=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+ | ||
" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=1;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);this.view[b-1]=a;c&&(this.offset+=1);return this};f.writeUInt8=f.writeUint8;f.readUint8=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+ | ||
a+" (+1) <= "+this.buffer.byteLength);}a=this.view[a];b&&(this.offset+=1);return a};f.readUInt8=f.readUint8;f.writeInt16=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength); | ||
}b+=2;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=2;this.littleEndian?(this.view[b+1]=(a&65280)>>>8,this.view[b]=a&255):(this.view[b]=(a&65280)>>>8,this.view[b+1]=a&255);c&&(this.offset+=2);return this};f.writeShort=f.writeInt16;f.readInt16=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+ | ||
a+" (+2) <= "+this.buffer.byteLength);}var c=0;this.littleEndian?(c=this.view[a],c|=this.view[a+1]<<8):(c=this.view[a]<<8,c|=this.view[a+1]);32768===(c&32768)&&(c=-(65535-c+1));b&&(this.offset+=2);return c};f.readShort=f.readInt16;f.writeUint16=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)"); | ||
b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=2;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=2;this.littleEndian?(this.view[b+1]=(a&65280)>>>8,this.view[b]=a&255):(this.view[b]=(a&65280)>>>8,this.view[b+1]=a&255);c&&(this.offset+=2);return this};f.writeUInt16=f.writeUint16;f.readUint16=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+ | ||
a+" (not an integer)");a>>>=0;if(0>a||a+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+2) <= "+this.buffer.byteLength);}var c=0;this.littleEndian?(c=this.view[a],c|=this.view[a+1]<<8):(c=this.view[a]<<8,c|=this.view[a+1]);b&&(this.offset+=2);return c};f.readUInt16=f.readUint16;f.writeInt32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|=0;if("number"!== | ||
typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=4;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=4;this.littleEndian?(this.view[b+3]=a>>>24&255,this.view[b+2]=a>>>16&255,this.view[b+1]=a>>>8&255,this.view[b]=a&255):(this.view[b]=a>>>24&255,this.view[b+1]=a>>>16&255,this.view[b+2]=a>>>8&255,this.view[b+3]=a&255);c&&(this.offset+=4); | ||
return this};f.writeInt=f.writeInt32;f.readInt32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength);}var c=0;this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0):(c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+ | ||
3],c+=this.view[a]<<24>>>0);b&&(this.offset+=4);return c|0};f.readInt=f.readInt32;f.writeUint32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=4;var d=this.buffer.byteLength; | ||
b>d&&this.resize((d*=2)>b?d:b);b-=4;this.littleEndian?(this.view[b+3]=a>>>24&255,this.view[b+2]=a>>>16&255,this.view[b+1]=a>>>8&255,this.view[b]=a&255):(this.view[b]=a>>>24&255,this.view[b+1]=a>>>16&255,this.view[b+2]=a>>>8&255,this.view[b+3]=a&255);c&&(this.offset+=4);return this};f.writeUInt32=f.writeUint32;f.readUint32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0> | ||
a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength);}var c=0;this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0):(c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+=this.view[a]<<24>>>0);b&&(this.offset+=4);return c};f.readUInt32=f.readUint32;k&&(f.writeInt64=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"===typeof a)a=k.fromNumber(a); | ||
else if("string"===typeof a)a=k.fromString(a);else if(!(a&&a instanceof k))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}"number"===typeof a?a=k.fromNumber(a):"string"===typeof a&&(a=k.fromString(a));b+=8;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=8; | ||
var d=a.low,e=a.high;this.littleEndian?(this.view[b+3]=d>>>24&255,this.view[b+2]=d>>>16&255,this.view[b+1]=d>>>8&255,this.view[b]=d&255,b+=4,this.view[b+3]=e>>>24&255,this.view[b+2]=e>>>16&255,this.view[b+1]=e>>>8&255,this.view[b]=e&255):(this.view[b]=e>>>24&255,this.view[b+1]=e>>>16&255,this.view[b+2]=e>>>8&255,this.view[b+3]=e&255,b+=4,this.view[b]=d>>>24&255,this.view[b+1]=d>>>16&255,this.view[b+2]=d>>>8&255,this.view[b+3]=d&255);c&&(this.offset+=8);return this},f.writeLong=f.writeInt64,f.readInt64= | ||
function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength);}var c=0,d=0;this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0,a+=4,d=this.view[a+2]<<16,d|=this.view[a+1]<<8,d|=this.view[a],d+=this.view[a+3]<<24>>>0):(d=this.view[a+ | ||
1]<<16,d|=this.view[a+2]<<8,d|=this.view[a+3],d+=this.view[a]<<24>>>0,a+=4,c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+=this.view[a]<<24>>>0);a=new k(c,d,!1);b&&(this.offset+=8);return a},f.readLong=f.readInt64,f.writeUint64=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"===typeof a)a=k.fromNumber(a);else if("string"===typeof a)a=k.fromString(a);else if(!(a&&a instanceof k))throw TypeError("Illegal value: "+a+" (not an integer or Long)"); | ||
if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}"number"===typeof a?a=k.fromNumber(a):"string"===typeof a&&(a=k.fromString(a));b+=8;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=8;var d=a.low,e=a.high;this.littleEndian?(this.view[b+3]=d>>>24&255,this.view[b+2]=d>>>16&255,this.view[b+1]=d>>>8&255,this.view[b]=d&255,b+=4, | ||
this.view[b+3]=e>>>24&255,this.view[b+2]=e>>>16&255,this.view[b+1]=e>>>8&255,this.view[b]=e&255):(this.view[b]=e>>>24&255,this.view[b+1]=e>>>16&255,this.view[b+2]=e>>>8&255,this.view[b+3]=e&255,b+=4,this.view[b]=d>>>24&255,this.view[b+1]=d>>>16&255,this.view[b+2]=d>>>8&255,this.view[b+3]=d&255);c&&(this.offset+=8);return this},f.writeUInt64=f.writeUint64,f.readUint64=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+ | ||
a+" (not an integer)");a>>>=0;if(0>a||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength);}var c=0,d=0;this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0,a+=4,d=this.view[a+2]<<16,d|=this.view[a+1]<<8,d|=this.view[a],d+=this.view[a+3]<<24>>>0):(d=this.view[a+1]<<16,d|=this.view[a+2]<<8,d|=this.view[a+3],d+=this.view[a]<<24>>>0,a+=4,c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+= | ||
this.view[a]<<24>>>0);a=new k(c,d,!0);b&&(this.offset+=8);return a},f.readUInt64=f.readUint64);f.writeFloat32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a)throw TypeError("Illegal value: "+a+" (not a number)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=4;var d=this.buffer.byteLength; | ||
b>d&&this.resize((d*=2)>b?d:b);z(this.view,a,b-4,this.littleEndian,23,4);c&&(this.offset+=4);return this};f.writeFloat=f.writeFloat32;f.readFloat32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength);}a=x(this.view,a,this.littleEndian,23,4);b&&(this.offset+=4);return a}; | ||
f.readFloat=f.readFloat32;f.writeFloat64=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a)throw TypeError("Illegal value: "+a+" (not a number)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}b+=8;var d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);z(this.view,a,b-8,this.littleEndian, | ||
52,8);c&&(this.offset+=8);return this};f.writeDouble=f.writeFloat64;f.readFloat64=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+8) <= "+this.buffer.byteLength);}a=x(this.view,a,this.littleEndian,52,8);b&&(this.offset+=8);return a};f.readDouble=f.readFloat64;g.MAX_VARINT32_BYTES=5;g.calculateVarint32= | ||
function(a){a>>>=0;return 128>a?1:16384>a?2:2097152>a?3:268435456>a?4:5};g.zigZagEncode32=function(a){return((a|=0)<<1^a>>31)>>>0};g.zigZagDecode32=function(a){return a>>>1^-(a&1)|0};f.writeVarint32=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+ | ||
b+" (+0) <= "+this.buffer.byteLength);}var d=g.calculateVarint32(a);b+=d;var e=this.buffer.byteLength;b>e&&this.resize((e*=2)>b?e:b);b-=d;this.view[b]=d=a|128;a>>>=0;128<=a?(d=a>>7|128,this.view[b+1]=d,16384<=a?(d=a>>14|128,this.view[b+2]=d,2097152<=a?(d=a>>21|128,this.view[b+3]=d,268435456<=a?(this.view[b+4]=a>>28&15,d=5):(this.view[b+3]=d&127,d=4)):(this.view[b+2]=d&127,d=3)):(this.view[b+1]=d&127,d=2)):(this.view[b]=d&127,d=1);return c?(this.offset+=d,this):d};f.writeVarint32ZigZag=function(a, | ||
b){return this.writeVarint32(g.zigZagEncode32(a),b)};f.readVarint32=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}var c=0,d=0,e;do{e=a+c;if(!this.noAssert&&e>this.limit)throw a=Error("Truncated"),a.truncated=!0,a;e=this.view[e];5>c&&(d|=(e&127)<<7*c>>>0);++c}while(128=== | ||
(e&128));d|=0;return b?(this.offset+=c,d):{value:d,length:c}};f.readVarint32ZigZag=function(a){a=this.readVarint32(a);"object"===typeof a?a.value=g.zigZagDecode32(a.value):a=g.zigZagDecode32(a);return a};k&&(g.MAX_VARINT64_BYTES=10,g.calculateVarint64=function(a){"number"===typeof a?a=k.fromNumber(a):"string"===typeof a&&(a=k.fromString(a));var b=a.toInt()>>>0,c=a.shiftRightUnsigned(28).toInt()>>>0;a=a.shiftRightUnsigned(56).toInt()>>>0;return 0==a?0==c?16384>b?128>b?1:2:2097152>b?3:4:16384>c?128> | ||
c?5:6:2097152>c?7:8:128>a?9:10},g.zigZagEncode64=function(a){"number"===typeof a?a=k.fromNumber(a,!1):"string"===typeof a?a=k.fromString(a,!1):!1!==a.unsigned&&(a=a.toSigned());return a.shiftLeft(1).xor(a.shiftRight(63)).toUnsigned()},g.zigZagDecode64=function(a){"number"===typeof a?a=k.fromNumber(a,!1):"string"===typeof a?a=k.fromString(a,!1):!1!==a.unsigned&&(a=a.toSigned());return a.shiftRightUnsigned(1).xor(a.and(k.ONE).toSigned().negate()).toSigned()},f.writeVarint64=function(a,b){var c="undefined"=== | ||
typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"===typeof a)a=k.fromNumber(a);else if("string"===typeof a)a=k.fromString(a);else if(!(a&&a instanceof k))throw TypeError("Illegal value: "+a+" (not an integer or Long)");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}"number"===typeof a?a=k.fromNumber(a,!1):"string"===typeof a? | ||
a=k.fromString(a,!1):!1!==a.unsigned&&(a=a.toSigned());var d=g.calculateVarint64(a),e=a.toInt()>>>0,f=a.shiftRightUnsigned(28).toInt()>>>0,h=a.shiftRightUnsigned(56).toInt()>>>0;b+=d;var p=this.buffer.byteLength;b>p&&this.resize((p*=2)>b?p:b);b-=d;switch(d){case 10:this.view[b+9]=h>>>7&1;case 9:this.view[b+8]=9!==d?h|128:h&127;case 8:this.view[b+7]=8!==d?f>>>21|128:f>>>21&127;case 7:this.view[b+6]=7!==d?f>>>14|128:f>>>14&127;case 6:this.view[b+5]=6!==d?f>>>7|128:f>>>7&127;case 5:this.view[b+4]=5!== | ||
d?f|128:f&127;case 4:this.view[b+3]=4!==d?e>>>21|128:e>>>21&127;case 3:this.view[b+2]=3!==d?e>>>14|128:e>>>14&127;case 2:this.view[b+1]=2!==d?e>>>7|128:e>>>7&127;case 1:this.view[b]=1!==d?e|128:e&127}return c?(this.offset+=d,this):d},f.writeVarint64ZigZag=function(a,b){return this.writeVarint64(g.zigZagEncode64(a),b)},f.readVarint64=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)"); | ||
a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}var c=a,d=0,e=0,f=0,h=0,h=this.view[a++],d=h&127;if(h&128&&(h=this.view[a++],d|=(h&127)<<7,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++],d|=(h&127)<<14,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++],d|=(h&127)<<21,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++],e=h&127,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++], | ||
e|=(h&127)<<7,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++],e|=(h&127)<<14,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++],e|=(h&127)<<21,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++],f=h&127,h&128||this.noAssert&&"undefined"===typeof h)&&(h=this.view[a++],f|=(h&127)<<7,h&128||this.noAssert&&"undefined"===typeof h))throw Error("Buffer overrun");d=k.fromBits(d|e<<28,e>>>4|f<<24,!1);return b?(this.offset=a,d):{value:d,length:a-c}},f.readVarint64ZigZag= | ||
function(a){(a=this.readVarint64(a))&&a.value instanceof k?a.value=g.zigZagDecode64(a.value):a=g.zigZagDecode64(a);return a});f.writeCString=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);var d,e=a.length;if(!this.noAssert){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");for(d=0;d<e;++d)if(0===a.charCodeAt(d))throw RangeError("Illegal str: Contains NULL-characters");if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0; | ||
if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}e=l.a(m(a))[1];b+=e+1;d=this.buffer.byteLength;b>d&&this.resize((d*=2)>b?d:b);b-=e+1;l.c(m(a),function(a){this.view[b++]=a}.bind(this));this.view[b++]=0;return c?(this.offset=b,this):e};f.readCString=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+ | ||
1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}var c=a,d,e=-1;l.b(function(){if(0===e)return null;if(a>=this.limit)throw RangeError("Illegal range: Truncated data, "+a+" < "+this.limit);e=this.view[a++];return 0===e?null:e}.bind(this),d=s(),!0);return b?(this.offset=a,d()):{string:d(),length:a-c}};f.writeIString=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("string"!==typeof a)throw TypeError("Illegal str: Not a string"); | ||
if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}var d=b,e;e=l.a(m(a),this.noAssert)[1];b+=4+e;var f=this.buffer.byteLength;b>f&&this.resize((f*=2)>b?f:b);b-=4+e;this.littleEndian?(this.view[b+3]=e>>>24&255,this.view[b+2]=e>>>16&255,this.view[b+1]=e>>>8&255,this.view[b]=e&255):(this.view[b]=e>>>24&255,this.view[b+1]=e>>>16&255,this.view[b+ | ||
2]=e>>>8&255,this.view[b+3]=e&255);b+=4;l.c(m(a),function(a){this.view[b++]=a}.bind(this));if(b!==d+4+e)throw RangeError("Illegal range: Truncated data, "+b+" == "+(b+4+e));return c?(this.offset=b,this):b-d};f.readIString=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+4) <= "+this.buffer.byteLength); | ||
}var c=0,d=a;this.littleEndian?(c=this.view[a+2]<<16,c|=this.view[a+1]<<8,c|=this.view[a],c+=this.view[a+3]<<24>>>0):(c=this.view[a+1]<<16,c|=this.view[a+2]<<8,c|=this.view[a+3],c+=this.view[a]<<24>>>0);a+=4;var e=a+c;l.b(function(){return a<e?this.view[a++]:null}.bind(this),c=s(),this.noAssert);c=c();return b?(this.offset=a,c):{string:c,length:a-d}};g.METRICS_CHARS="c";g.METRICS_BYTES="b";f.writeUTF8String=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("number"!== | ||
typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}var d,e=b;d=l.a(m(a))[1];b+=d;var f=this.buffer.byteLength;b>f&&this.resize((f*=2)>b?f:b);b-=d;l.c(m(a),function(a){this.view[b++]=a}.bind(this));return c?(this.offset=b,this):b-e};f.writeString=f.writeUTF8String;g.calculateUTF8Chars=function(a){return l.a(m(a))[0]};g.calculateUTF8Bytes=function(a){return l.a(m(a))[1]}; | ||
g.calculateString=g.calculateUTF8Bytes;f.readUTF8String=function(a,b,c){"number"===typeof b&&(c=b,b=void 0);var d="undefined"===typeof c;d&&(c=this.offset);"undefined"===typeof b&&(b=g.METRICS_CHARS);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal length: "+a+" (not an integer)");a|=0;if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+c+" (not an integer)");c>>>=0;if(0>c||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+ | ||
this.buffer.byteLength);}var e=0,f=c,h;if(b===g.METRICS_CHARS){h=s();l.f(function(){return e<a&&c<this.limit?this.view[c++]:null}.bind(this),function(a){++e;l.e(a,h)});if(e!==a)throw RangeError("Illegal range: Truncated data, "+e+" == "+a);return d?(this.offset=c,h()):{string:h(),length:c-f}}if(b===g.METRICS_BYTES){if(!this.noAssert){if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+c+" (not an integer)");c>>>=0;if(0>c||c+a>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+ | ||
c+" (+"+a+") <= "+this.buffer.byteLength);}var p=c+a;l.b(function(){return c<p?this.view[c++]:null}.bind(this),h=s(),this.noAssert);if(c!==p)throw RangeError("Illegal range: Truncated data, "+c+" == "+p);return d?(this.offset=c,h()):{string:h(),length:c-f}}throw TypeError("Unsupported metrics: "+b);};f.readString=f.readUTF8String;f.writeVString=function(a,b){var c="undefined"===typeof b;c&&(b=this.offset);if(!this.noAssert){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");if("number"!== | ||
typeof b||0!==b%1)throw TypeError("Illegal offset: "+b+" (not an integer)");b>>>=0;if(0>b||b+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+b+" (+0) <= "+this.buffer.byteLength);}var d=b,e,f;e=l.a(m(a),this.noAssert)[1];f=g.calculateVarint32(e);b+=f+e;var h=this.buffer.byteLength;b>h&&this.resize((h*=2)>b?h:b);b-=f+e;b+=this.writeVarint32(e,b);l.c(m(a),function(a){this.view[b++]=a}.bind(this));if(b!==d+e+f)throw RangeError("Illegal range: Truncated data, "+b+" == "+(b+e+f));return c? | ||
(this.offset=b,this):b-d};f.readVString=function(a){var b="undefined"===typeof a;b&&(a=this.offset);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+1) <= "+this.buffer.byteLength);}var c=this.readVarint32(a),d=a;a+=c.length;var c=c.value,e=a+c,c=s();l.b(function(){return a<e?this.view[a++]:null}.bind(this),c,this.noAssert);c=c();return b?(this.offset= | ||
a,c):{string:c,length:a-d}};f.append=function(a,b,c){if("number"===typeof b||"string"!==typeof b)c=b,b=void 0;var d="undefined"===typeof c;d&&(c=this.offset);if(!this.noAssert){if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+c+" (not an integer)");c>>>=0;if(0>c||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength);}a instanceof g||(a=g.wrap(a,b));b=a.limit-a.offset;if(0>=b)return this;c+=b;var e=this.buffer.byteLength;c>e&&this.resize((e*= | ||
2)>c?e:c);this.view.set(a.view.subarray(a.offset,a.limit),c-b);a.offset+=b;d&&(this.offset+=b);return this};f.appendTo=function(a,b){a.append(this,b);return this};f.assert=function(a){this.noAssert=!a;return this};f.capacity=function(){return this.buffer.byteLength};f.clear=function(){this.offset=0;this.limit=this.buffer.byteLength;this.markedOffset=-1;return this};f.clone=function(a){var b=new g(0,this.littleEndian,this.noAssert);a?(b.buffer=new ArrayBuffer(this.buffer.byteLength),b.view=new Uint8Array(b.buffer)): | ||
(b.buffer=this.buffer,b.view=this.view);b.offset=this.offset;b.markedOffset=this.markedOffset;b.limit=this.limit;return b};f.compact=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+ | ||
b+" <= "+this.buffer.byteLength);}if(0===a&&b===this.buffer.byteLength)return this;var c=b-a;if(0===c)return this.buffer=v,this.view=null,0<=this.markedOffset&&(this.markedOffset-=a),this.limit=this.offset=0,this;var d=new ArrayBuffer(c),e=new Uint8Array(d);e.set(this.view.subarray(a,b));this.buffer=d;this.view=e;0<=this.markedOffset&&(this.markedOffset-=a);this.offset=0;this.limit=c;return this};f.copy=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!== | ||
typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}if(a===b)return new g(0,this.littleEndian,this.noAssert);var c=b-a,d=new g(c,this.littleEndian,this.noAssert);d.offset=0;d.limit=c;0<=d.markedOffset&&(d.markedOffset-=a);this.copyTo(d,0,a,b);return d};f.copyTo=function(a, | ||
b,c,d){var e,f;if(!this.noAssert&&!g.isByteBuffer(a))throw TypeError("Illegal target: Not a ByteBuffer");b=(f="undefined"===typeof b)?a.offset:b|0;c=(e="undefined"===typeof c)?this.offset:c|0;d="undefined"===typeof d?this.limit:d|0;if(0>b||b>a.buffer.byteLength)throw RangeError("Illegal target range: 0 <= "+b+" <= "+a.buffer.byteLength);if(0>c||d>this.buffer.byteLength)throw RangeError("Illegal source range: 0 <= "+c+" <= "+this.buffer.byteLength);var h=d-c;if(0===h)return a;a.ensureCapacity(b+h); | ||
a.view.set(this.view.subarray(c,d),b);e&&(this.offset+=h);f&&(a.offset+=h);return this};f.ensureCapacity=function(a){var b=this.buffer.byteLength;return b<a?this.resize((b*=2)>a?b:a):this};f.fill=function(a,b,c){var d="undefined"===typeof b;d&&(b=this.offset);"string"===typeof a&&0<a.length&&(a=a.charCodeAt(0));"undefined"===typeof b&&(b=this.offset);"undefined"===typeof c&&(c=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal value: "+a+" (not an integer)");a|= | ||
0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal begin: Not an integer");b>>>=0;if("number"!==typeof c||0!==c%1)throw TypeError("Illegal end: Not an integer");c>>>=0;if(0>b||b>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+b+" <= "+c+" <= "+this.buffer.byteLength);}if(b>=c)return this;for(;b<c;)this.view[b++]=a;d&&(this.offset=b);return this};f.flip=function(){this.limit=this.offset;this.offset=0;return this};f.mark=function(a){a="undefined"===typeof a?this.offset:a; | ||
if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal offset: "+a+" (not an integer)");a>>>=0;if(0>a||a+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+a+" (+0) <= "+this.buffer.byteLength);}this.markedOffset=a;return this};f.order=function(a){if(!this.noAssert&&"boolean"!==typeof a)throw TypeError("Illegal littleEndian: Not a boolean");this.littleEndian=!!a;return this};f.LE=function(a){this.littleEndian="undefined"!==typeof a?!!a:!0;return this};f.BE=function(a){this.littleEndian= | ||
"undefined"!==typeof a?!a:!1;return this};f.prepend=function(a,b,c){if("number"===typeof b||"string"!==typeof b)c=b,b=void 0;var d="undefined"===typeof c;d&&(c=this.offset);if(!this.noAssert){if("number"!==typeof c||0!==c%1)throw TypeError("Illegal offset: "+c+" (not an integer)");c>>>=0;if(0>c||c+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+c+" (+0) <= "+this.buffer.byteLength);}a instanceof g||(a=g.wrap(a,b));b=a.limit-a.offset;if(0>=b)return this;var e=b-c;if(0<e){var f=new ArrayBuffer(this.buffer.byteLength+ | ||
e),h=new Uint8Array(f);h.set(this.view.subarray(c,this.buffer.byteLength),b);this.buffer=f;this.view=h;this.offset+=e;0<=this.markedOffset&&(this.markedOffset+=e);this.limit+=e;c+=e}else new Uint8Array(this.buffer);this.view.set(a.view.subarray(a.offset,a.limit),c-b);a.offset=a.limit;d&&(this.offset-=b);return this};f.prependTo=function(a,b){a.prepend(this,b);return this};f.printDebug=function(a){"function"!==typeof a&&(a=console.log.bind(console));a(this.toString()+"\n-------------------------------------------------------------------\n"+ | ||
this.toDebug(!0))};f.remaining=function(){return this.limit-this.offset};f.reset=function(){0<=this.markedOffset?(this.offset=this.markedOffset,this.markedOffset=-1):this.offset=0;return this};f.resize=function(a){if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal capacity: "+a+" (not an integer)");a|=0;if(0>a)throw RangeError("Illegal capacity: 0 <= "+a);}if(this.buffer.byteLength<a){a=new ArrayBuffer(a);var b=new Uint8Array(a);b.set(this.view);this.buffer=a;this.view=b}return this}; | ||
f.reverse=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}if(a===b)return this;Array.prototype.reverse.call(this.view.subarray(a,b));return this}; | ||
f.skip=function(a){if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal length: "+a+" (not an integer)");a|=0}var b=this.offset+a;if(!this.noAssert&&(0>b||b>this.buffer.byteLength))throw RangeError("Illegal length: 0 <= "+this.offset+" + "+a+" <= "+this.buffer.byteLength);this.offset=b;return this};f.slice=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer"); | ||
a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}var c=this.clone();c.offset=a;c.limit=b;return c};f.toBuffer=function(a){var b=this.offset,c=this.limit;if(!this.noAssert){if("number"!==typeof b||0!==b%1)throw TypeError("Illegal offset: Not an integer");b>>>=0;if("number"!==typeof c||0!==c%1)throw TypeError("Illegal limit: Not an integer"); | ||
c>>>=0;if(0>b||b>c||c>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+b+" <= "+c+" <= "+this.buffer.byteLength);}if(!a&&0===b&&c===this.buffer.byteLength)return this.buffer;if(b===c)return v;a=new ArrayBuffer(c-b);(new Uint8Array(a)).set((new Uint8Array(this.buffer)).subarray(b,c),0);return a};f.toArrayBuffer=f.toBuffer;f.toString=function(a,b,c){if("undefined"===typeof a)return"ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+ | ||
")";"number"===typeof a&&(c=b=a="utf8");switch(a){case "utf8":return this.toUTF8(b,c);case "base64":return this.toBase64(b,c);case "hex":return this.toHex(b,c);case "binary":return this.toBinary(b,c);case "debug":return this.toDebug();case "columns":return this.m();default:throw Error("Unsupported encoding: "+a);}};var A=function(){for(var a={},b=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115, | ||
116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47],c=[],d=0,e=b.length;d<e;++d)c[b[d]]=d;a.h=function(a,c){for(var d,e;null!==(d=a());)c(b[d>>2&63]),e=(d&3)<<4,null!==(d=a())?(e|=d>>4&15,c(b[(e|d>>4&15)&63]),e=(d&15)<<2,null!==(d=a())?(c(b[(e|d>>6&3)&63]),c(b[d&63])):(c(b[e&63]),c(61))):(c(b[e&63]),c(61),c(61))};a.g=function(a,b){function d(a){throw Error("Illegal character code: "+a);}for(var e,f,g;null!==(e=a());)if(f=c[e],"undefined"===typeof f&&d(e),null!==(e=a())&&(g=c[e],"undefined"=== | ||
typeof g&&d(e),b(f<<2>>>0|(g&48)>>4),null!==(e=a()))){f=c[e];if("undefined"===typeof f)if(61===e)break;else d(e);b((g&15)<<4>>>0|(f&60)>>2);if(null!==(e=a())){g=c[e];if("undefined"===typeof g)if(61===e)break;else d(e);b((f&3)<<6>>>0|g)}}};a.test=function(a){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(a)};return a}();f.toBase64=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!== | ||
a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}var c;A.h(function(){return a<b?this.view[a++]:null}.bind(this),c=s());return c()};g.fromBase64=function(a,b,c){if(!c){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");if(0!==a.length%4)throw TypeError("Illegal str: Length not a multiple of 4"); | ||
}var d=new g(a.length/4*3,b,c),e=0;A.g(m(a),function(a){d.view[e++]=a});d.limit=e;return d};g.btoa=function(a){return g.fromBinary(a).toBase64()};g.atob=function(a){return g.fromBase64(a).toBinary()};f.toBinary=function(a,b){a="undefined"===typeof a?this.offset:a;b="undefined"===typeof b?this.limit:b;if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a|| | ||
a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}if(a===b)return"";for(var c=[],d=[];a<b;)c.push(this.view[a++]),1024<=c.length&&(d.push(String.fromCharCode.apply(String,c)),c=[]);return d.join("")+String.fromCharCode.apply(String,c)};g.fromBinary=function(a,b,c){if(!c&&"string"!==typeof a)throw TypeError("Illegal str: Not a string");for(var d=0,e=a.length,f=new g(e,b,c);d<e;){b=a.charCodeAt(d);if(!c&&255<b)throw RangeError("Illegal charCode at "+ | ||
d+": 0 <= "+b+" <= 255");f.view[d++]=b}f.limit=e;return f};f.toDebug=function(a){for(var b=-1,c=this.buffer.byteLength,d,e="",f="",g="";b<c;){-1!==b&&(d=this.view[b],e=16>d?e+("0"+d.toString(16).toUpperCase()):e+d.toString(16).toUpperCase(),a&&(f+=32<d&&127>d?String.fromCharCode(d):"."));++b;if(a&&0<b&&0===b%16&&b!==c){for(;51>e.length;)e+=" ";g+=e+f+"\n";e=f=""}e=b===this.offset&&b===this.limit?e+(b===this.markedOffset?"!":"|"):b===this.offset?e+(b===this.markedOffset?"[":"<"):b===this.limit?e+(b=== | ||
this.markedOffset?"]":">"):e+(b===this.markedOffset?"'":a||0!==b&&b!==c?" ":"")}if(a&&" "!==e){for(;51>e.length;)e+=" ";g+=e+f+"\n"}return a?g:e};g.fromDebug=function(a,b,c){var d=a.length;b=new g((d+1)/3|0,b,c);for(var e=0,f=0,h,k=!1,l=!1,q=!1,m=!1,r=!1;e<d;){switch(h=a.charAt(e++)){case "!":if(!c){if(l||q||m){r=!0;break}l=q=m=!0}b.offset=b.markedOffset=b.limit=f;k=!1;break;case "|":if(!c){if(l||m){r=!0;break}l=m=!0}b.offset=b.limit=f;k=!1;break;case "[":if(!c){if(l||q){r=!0;break}l=q=!0}b.offset= | ||
b.markedOffset=f;k=!1;break;case "<":if(!c){if(l){r=!0;break}l=!0}b.offset=f;k=!1;break;case "]":if(!c){if(m||q){r=!0;break}m=q=!0}b.limit=b.markedOffset=f;k=!1;break;case ">":if(!c){if(m){r=!0;break}m=!0}b.limit=f;k=!1;break;case "'":if(!c){if(q){r=!0;break}q=!0}b.markedOffset=f;k=!1;break;case " ":k=!1;break;default:if(!c&&k){r=!0;break}h=parseInt(h+a.charAt(e++),16);if(!c&&(isNaN(h)||0>h||255<h))throw TypeError("Illegal str: Not a debug encoded string");b.view[f++]=h;k=!0}if(r)throw TypeError("Illegal str: Invalid symbol at "+ | ||
e);}if(!c){if(!l||!m)throw TypeError("Illegal str: Missing offset or limit");if(f<b.buffer.byteLength)throw TypeError("Illegal str: Not a debug encoded string (is it hex?) "+f+" < "+d);}return b};f.toHex=function(a,b){a="undefined"===typeof a?this.offset:a;b="undefined"===typeof b?this.limit:b;if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b|| | ||
b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength);}for(var c=Array(b-a),d;a<b;)d=this.view[a++],16>d?c.push("0",d.toString(16)):c.push(d.toString(16));return c.join("")};g.fromHex=function(a,b,c){if(!c){if("string"!==typeof a)throw TypeError("Illegal str: Not a string");if(0!==a.length%2)throw TypeError("Illegal str: Length not a multiple of 2");}var d=a.length;b=new g(d/2|0,b);for(var e,f=0,h=0;f<d;f+=2){e=parseInt(a.substring(f,f+2),16);if(!c&& | ||
(!isFinite(e)||0>e||255<e))throw TypeError("Illegal str: Contains non-hex characters");b.view[h++]=e}b.limit=h;return b};var l=function(){var a={j:1114111,i:function(a,c){var d=null;"number"===typeof a&&(d=a,a=function(){return null});for(;null!==d||null!==(d=a());)128>d?c(d&127):(2048>d?c(d>>6&31|192):(65536>d?c(d>>12&15|224):(c(d>>18&7|240),c(d>>12&63|128)),c(d>>6&63|128)),c(d&63|128)),d=null},f:function(a,c){function d(a){a=a.slice(0,a.indexOf(null));var b=Error(a.toString());b.name="TruncatedError"; | ||
b.bytes=a;throw b;}for(var e,f,g,k;null!==(e=a());)if(0===(e&128))c(e);else if(192===(e&224))null===(f=a())&&d([e,f]),c((e&31)<<6|f&63);else if(224===(e&240))null!==(f=a())&&null!==(g=a())||d([e,f,g]),c((e&15)<<12|(f&63)<<6|g&63);else if(240===(e&248))null!==(f=a())&&null!==(g=a())&&null!==(k=a())||d([e,f,g,k]),c((e&7)<<18|(f&63)<<12|(g&63)<<6|k&63);else throw RangeError("Illegal starting byte: "+e);},d:function(a,c){for(var d,e=null;null!==(d=null!==e?e:a());)55296<=d&&57343>=d&&null!==(e=a())&& | ||
56320<=e&&57343>=e?(c(1024*(d-55296)+e-56320+65536),e=null):c(d);null!==e&&c(e)},e:function(a,c){var d=null;"number"===typeof a&&(d=a,a=function(){return null});for(;null!==d||null!==(d=a());)65535>=d?c(d):(d-=65536,c((d>>10)+55296),c(d%1024+56320)),d=null},c:function(b,c){a.d(b,function(b){a.i(b,c)})},b:function(b,c){a.f(b,function(b){a.e(b,c)})},k:function(a){return 128>a?1:2048>a?2:65536>a?3:4},l:function(a){for(var c,d=0;null!==(c=a());)d+=128>c?1:2048>c?2:65536>c?3:4;return d},a:function(b){var c= | ||
0,d=0;a.d(b,function(a){++c;d+=128>a?1:2048>a?2:65536>a?3:4});return[c,d]}};return a}();f.toUTF8=function(a,b){"undefined"===typeof a&&(a=this.offset);"undefined"===typeof b&&(b=this.limit);if(!this.noAssert){if("number"!==typeof a||0!==a%1)throw TypeError("Illegal begin: Not an integer");a>>>=0;if("number"!==typeof b||0!==b%1)throw TypeError("Illegal end: Not an integer");b>>>=0;if(0>a||a>b||b>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+a+" <= "+b+" <= "+this.buffer.byteLength); | ||
}var c;try{l.b(function(){return a<b?this.view[a++]:null}.bind(this),c=s())}catch(d){if(a!==b)throw RangeError("Illegal range: Truncated data, "+a+" != "+b);}return c()};g.fromUTF8=function(a,b,c){if(!c&&"string"!==typeof a)throw TypeError("Illegal str: Not a string");var d=new g(l.a(m(a),!0)[1],b,c),e=0;l.c(m(a),function(a){d.view[e++]=a});d.limit=e;return d};return g} | ||
if("function"===typeof define&&define.amd)define(["Long"],u);else if("function"===typeof require&&"object"===typeof module&&module&&module.exports){var B=module,C,D;try{D=require("long")}catch(E){}C=u(D);B.exports=C}else(this.dcodeIO=this.dcodeIO||{}).ByteBuffer=u(this.dcodeIO.Long); |
Distributions | ||
============= | ||
ByteBuffer uses either ArrayBuffers in the browser or Buffers under node.js. | ||
ByteBuffer.js uses either ArrayBuffers in the browser or Buffers under node.js. | ||
### Browsers: ArrayBuffers | ||
### Browser: [ArrayBuffer](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)-backed | ||
##### Accessed through Typed Arrays | ||
Using Typed Arrays here is pretty much ideal, but it [requires a somewhat recent browser](http://caniuse.com/#feat=typedarrays). | ||
* **[ByteBufferAB.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB.js)** | ||
uses an ArrayBuffer as its backing buffer, accessed through a DataView. | ||
uses an ArrayBuffer as its backing buffer, accessed through an [Uint8Array](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array). | ||
@@ -20,6 +24,23 @@ * **[ByteBufferAB.min.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB.min.js)** | ||
### node.js: Buffers | ||
##### Accessed through a DataView ([polyfill](https://github.com/inexorabletash/polyfill/blob/master/typedarray.js) compatible) | ||
Using DataViews is [generally slower](https://github.com/dcodeIO/ByteBuffer.js/issues/16) but works well with common polyfills for | ||
older browsers (avoids array access operators on Typed Arrays). | ||
* **[ByteBufferAB_DataView.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB_DataView.js)** | ||
uses an ArrayBuffer as its backing buffer, accessed through a [DataView](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/DataView). | ||
* **[ByteBufferAB_DataView.min.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB_DataView.min.js)** | ||
has been compiled with Closure Compiler using advanced optimizations. | ||
* **[ByteBufferAB_DataView.min.js.gz](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB_DataView.min.js.gz)** | ||
has also been gzipped using `-9`. | ||
* **[ByteBufferAB_DataView.min.map](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferAB_DataView.min.map)** | ||
is the source map generated by Closure Compiler. | ||
### node.js: [Buffer](https://nodejs.org/api/buffer.html)-backed | ||
* **[ByteBufferNB.js](https://raw.githubusercontent.com/dcodeIO/ByteBuffer.js/master/dist/ByteBufferNB.js)** | ||
uses a node Buffer as its backing buffer. | ||
uses a [node Buffer](https://nodejs.org/api/buffer.html) as its backing buffer and accessor. | ||
@@ -26,0 +47,0 @@ Also available as `bytebuffer` on [npm](https://www.npmjs.org/package/bytebuffer) and |
10
index.js
@@ -16,7 +16,9 @@ /* | ||
*/ | ||
var ByteBufferNB = require("./dist/ByteBufferNB.js"), | ||
ByteBufferAB = require("./dist/ByteBufferAB.js"); | ||
var ByteBufferNB = require("./dist/ByteBufferNB.js"), | ||
ByteBufferAB = require("./dist/ByteBufferAB.js"), | ||
ByteBufferAB_DataView = require("./dist/ByteBufferAB_DataView.js"); | ||
module.exports = ByteBufferNB; | ||
module.exports.ByteBufferNB = ByteBufferNB; // node Buffer backed | ||
module.exports.ByteBufferAB = ByteBufferAB; // ArrayBuffer backed | ||
module.exports.ByteBufferNB = ByteBufferNB; | ||
module.exports.ByteBufferAB = ByteBufferAB; | ||
module.exports.ByteBufferAB_DataView = ByteBufferAB_DataView; |
{ | ||
"name": "bytebuffer", | ||
"version": "3.5.5", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
"description": "The swiss army knife for binary data in JavaScript.", | ||
"main": "index.js", | ||
"browser": "dist/ByteBufferAB.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dcodeIO/ByteBuffer.js.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dcodeIO/ByteBuffer.js/issues" | ||
}, | ||
"keywords": ["net", "array", "buffer", "arraybuffer", "typed array", "bytebuffer", "json", "websocket", "webrtc"], | ||
"dependencies": { | ||
"long": "~2 >=2.2.3", | ||
"bufferview": "~1" | ||
}, | ||
"devDependencies": { | ||
"utfx": "~1", | ||
"lxiv": "~0.2", | ||
"testjs": "~1", | ||
"metascript": "~0", | ||
"closurecompiler": "~1" | ||
}, | ||
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=0.8" | ||
}, | ||
"scripts": { | ||
"prepublish": "npm test", | ||
"test": "node node_modules/testjs/bin/testjs tests/suite.js", | ||
"make": "npm run-script build && npm run-script compile && npm run-script compress && npm test", | ||
"build": "node scripts/build.js", | ||
"compile": "ccjs dist/ByteBufferAB.js --create_source_map=dist/ByteBufferAB.min.map --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js --externs=node_modules/long/externs/Long.js > dist/ByteBufferAB.min.js", | ||
"compress": "gzip -c -9 dist/ByteBufferAB.min.js > dist/ByteBufferAB.min.js.gz" | ||
} | ||
"name": "bytebuffer", | ||
"version": "4.0.0", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
"description": "The swiss army knife for binary data in JavaScript.", | ||
"main": "index.js", | ||
"browser": "dist/ByteBufferAB.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/dcodeIO/ByteBuffer.js.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dcodeIO/ByteBuffer.js/issues" | ||
}, | ||
"keywords": [ | ||
"net", | ||
"array", | ||
"buffer", | ||
"arraybuffer", | ||
"typed array", | ||
"bytebuffer", | ||
"json", | ||
"websocket", | ||
"webrtc" | ||
], | ||
"dependencies": { | ||
"long": "~2 >=2.2.3", | ||
"bufferview": "~1" | ||
}, | ||
"devDependencies": { | ||
"closurecompiler": "~1", | ||
"lxiv": "~0.2", | ||
"metascript": "~0", | ||
"pretty-hrtime": "^1.0.0", | ||
"testjs": "~1", | ||
"utfx": "^1.0.1" | ||
}, | ||
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=0.8" | ||
}, | ||
"scripts": { | ||
"prepublish": "npm test", | ||
"test": "node node_modules/testjs/bin/testjs tests/suite.js", | ||
"make": "npm run-script build && npm run-script compile && npm run-script compress && npm test", | ||
"build": "node scripts/build.js", | ||
"compile": "npm run-script compileAB && npm run-script compileAB_DataView", | ||
"compileAB": "ccjs dist/ByteBufferAB.js --create_source_map=dist/ByteBufferAB.min.map --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js --externs=node_modules/long/externs/Long.js > dist/ByteBufferAB.min.js", | ||
"compileAB_DataView": "ccjs dist/ByteBufferAB_DataView.js --create_source_map=dist/ByteBufferAB_DataView.min.map --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/minimal-env.js --externs=node_modules/long/externs/Long.js > dist/ByteBufferAB_DataView.min.js", | ||
"compress": "gzip -c -9 dist/ByteBufferAB.min.js > dist/ByteBufferAB.min.js.gz && gzip -c -9 dist/ByteBufferAB_DataView.min.js > dist/ByteBufferAB_DataView.min.js.gz" | ||
} | ||
} |
@@ -11,3 +11,6 @@ ![ByteBuffer.js - The swiss army knife for binary data in JavaScript.](https://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.png) | ||
-------- | ||
* Two API compatible versions, using either node Buffers under node.js or ArrayBuffers in the browser | ||
* Three API-compatible versions: | ||
* **ByteBufferNB** Backing buffer / Accessor: node Buffer | ||
* **ByteBufferAB** Backing buffer: ArrayBuffer, Accessor: Uint8Array | ||
* **ByteBufferAB_DataView** Backing buffer: ArrayBuffer, Accessor: DataView | ||
* 8, 16, 32 and 64 bit signed and unsigned integers | ||
@@ -54,3 +57,3 @@ * 32 and 64 bit floats | ||
--------------------------------------- | ||
* Requires working ArrayBuffer & DataView implementations (i.e. use a [polyfill](https://github.com/inexorabletash/polyfill#typed-arrays-polyfill)) | ||
* Use ByteBufferAB_DataView with a polyfill ([see](https://github.com/dcodeIO/ByteBuffer.js/tree/master/dist)) | ||
@@ -57,0 +60,0 @@ Contributors |
@@ -45,3 +45,4 @@ /* | ||
// Primitive types | ||
BYTES : true, // Include bytes | ||
INTS : true, // Include int types in general (catches all) | ||
@@ -75,3 +76,3 @@ INT8 : true, // Include int8/uint8 | ||
BUFFERVIEW : false, // Include BufferView as ByteBuffer#view under node | ||
INLINE : true, // Inline whatever possible for maximum performance | ||
INLINE : true, // Inline any assertion code | ||
VERBOSE_MS : false // Include MetaScript details as comments | ||
@@ -85,3 +86,3 @@ }; | ||
// Build node ByteBuffer | ||
// Build node ByteBuffer using Buffers | ||
scope.NODE = true; | ||
@@ -91,8 +92,8 @@ console.log("Building ByteBufferNB with scope", JSON.stringify(scope, null, 2)); | ||
path.join(distDir, "ByteBufferNB.js"), | ||
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "ByteBufferNB.js")), filename, scope, srcDir) | ||
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap_node.js")), filename, scope, srcDir) | ||
); | ||
// Build browser ByteBuffer | ||
// Build browser ByteBuffer using Typed Arrays | ||
scope.NODE = false; | ||
scope.DATAVIEW = true; | ||
scope.DATAVIEW = false; | ||
delete scope.BUFFERVIEW; | ||
@@ -102,5 +103,14 @@ console.log("Building ByteBufferAB with scope", JSON.stringify(scope, null, 2)); | ||
path.join(distDir, "ByteBufferAB.js"), | ||
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "ByteBufferAB.js")), filename, scope) | ||
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope) | ||
); | ||
// Build alternative browser ByteBuffer using a DataView | ||
scope.NODE = false; | ||
scope.DATAVIEW = true; | ||
console.log("Building ByteBufferAB_DataView with scope", JSON.stringify(scope, null, 2)); | ||
fs.writeFileSync( | ||
path.join(distDir, "ByteBufferAB_DataView.js"), | ||
MetaScript.transform(fs.readFileSync(filename = path.join(srcDir, "wrap.js")), filename, scope) | ||
); | ||
// Update bower.json | ||
@@ -107,0 +117,0 @@ scope = { VERSION: pkg.version }; |
@@ -15,5 +15,8 @@ //? include("macros.js"); | ||
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 (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) { | ||
@@ -29,3 +32,3 @@ capacity = capacity | 0; | ||
/** | ||
* Backing buffer. | ||
* Backing node Buffer. | ||
* @type {!Buffer} | ||
@@ -38,3 +41,3 @@ * @expose | ||
/** | ||
* Backing buffer. | ||
* Backing ArrayBuffer. | ||
* @type {!ArrayBuffer} | ||
@@ -57,12 +60,18 @@ * @expose | ||
//? if (DATAVIEW) { | ||
/** | ||
* Data view to manipulate the backing buffer. Becomes `null` if the backing buffer has a capacity of `0`. | ||
* DataView utilized to manipulate the backing buffer. Becomes `null` if the backing buffer has a capacity of `0`. | ||
* @type {?DataView} | ||
* @expose | ||
*/ | ||
//? if (DATAVIEW) | ||
this.view = capacity === 0 ? null : new DataView(this.buffer); | ||
//? else | ||
//? } 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); | ||
//? } | ||
//? } | ||
@@ -184,5 +193,24 @@ /** | ||
/** | ||
* 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) { | ||
@@ -209,2 +237,2 @@ | ||
//? include("encodings/*.js"); | ||
//? } | ||
//? } |
@@ -97,2 +97,2 @@ //? if (BASE64) { | ||
//? } | ||
//? } |
@@ -93,2 +93,2 @@ //? if (BINARY) { | ||
//? } | ||
//? } |
@@ -77,2 +77,2 @@ //? if (HEX) { | ||
//? } | ||
//? } |
@@ -73,2 +73,2 @@ //? if (UTF8) { | ||
//? } | ||
//? } |
@@ -141,3 +141,3 @@ //?... | ||
if (VERBOSE_MS) writeln(__+'// <READ_UINT32'+(typeof varEndian === 'boolean' ? ' le='+varEndian : '')+'>'); | ||
if (NODE) { | ||
if (NODE || !DATAVIEW) { | ||
if (typeof varEndian !== 'boolean') | ||
@@ -174,3 +174,3 @@ writeln(__+'if ('+(varEndian || 'this.littleEndian')+') {'); | ||
if (VERBOSE_MS) writeln(__+'// <WRITE_UINT32'+(typeof varEndian === 'boolean' ? ' le='+varEndian : '')+'>'); | ||
if (NODE) { | ||
if (NODE || !DATAVIEW) { | ||
if (typeof varEndian !== 'boolean') | ||
@@ -177,0 +177,0 @@ writeln(__+'if ('+(varEndian || 'this.littleEndian')+') {'); |
@@ -13,3 +13,3 @@ /** | ||
* @param {number=} offset Offset to append at. Will use and increase {@link ByteBuffer#offset} by the number of bytes | ||
* read if omitted. | ||
* written if omitted. | ||
* @returns {!ByteBuffer} this | ||
@@ -34,7 +34,8 @@ * @expose | ||
//? ENSURE_CAPACITY('length'); | ||
//? if (NODE) { | ||
//? if (NODE) | ||
source.buffer.copy(this.buffer, offset, source.offset, source.limit); | ||
//? } else { | ||
//? 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; | ||
@@ -41,0 +42,0 @@ //? RELATIVE('length'); |
@@ -18,7 +18,10 @@ /** | ||
//? } else { | ||
var buffer = new ArrayBuffer(this.buffer.byteLength); | ||
new Uint8Array(buffer).set(this.buffer); | ||
bb.buffer = buffer; | ||
bb.view = new DataView(buffer); | ||
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 { | ||
@@ -25,0 +28,0 @@ bb.buffer = this.buffer; |
@@ -34,3 +34,3 @@ /** | ||
this.view = new BufferView(buffer); | ||
//? } else { | ||
//? } else if (DATAVIEW) { | ||
var buffer = new ArrayBuffer(len); | ||
@@ -40,2 +40,8 @@ new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(begin, end)); | ||
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; | ||
//? } | ||
@@ -42,0 +48,0 @@ if (this.markedOffset >= 0) this.markedOffset -= begin; |
@@ -63,4 +63,6 @@ /** | ||
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 | ||
new Uint8Array(target.buffer).set(new Uint8Array(this.buffer).subarray(sourceOffset, sourceLimit), targetOffset); | ||
target.view.set(this.view.subarray(sourceOffset, sourceLimit), targetOffset); | ||
@@ -67,0 +69,0 @@ if (relative) this.offset += len; |
@@ -27,4 +27,6 @@ /** | ||
begin = end; | ||
//? } else if (DATAVIEW) { | ||
while (begin < end) this.view.setUint8(begin++, value); | ||
//? } else { | ||
while (begin < end) this.view.setUint8(begin++, value); | ||
while (begin < end) this.view[begin++] = value; | ||
//? } | ||
@@ -31,0 +33,0 @@ if (relative) this.offset = begin; |
@@ -34,4 +34,2 @@ /** | ||
var diff = len - offset; | ||
//? if (!NODE) | ||
var arrayView; | ||
if (diff > 0) { // Not enough space before offset, so resize + move | ||
@@ -44,8 +42,14 @@ //? if (NODE) { | ||
this.view = new BufferView(buffer); | ||
//? } else { | ||
//? } else if (DATAVIEW) { | ||
var buffer = new ArrayBuffer(this.buffer.byteLength + diff); | ||
arrayView = new Uint8Array(buffer); | ||
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; | ||
//? } | ||
@@ -57,3 +61,3 @@ this.offset += diff; | ||
}/*? if (!NODE) { */ else { | ||
arrayView = new Uint8Array(this.buffer); | ||
var arrayView = new Uint8Array(this.buffer); | ||
} | ||
@@ -63,4 +67,7 @@ //? } | ||
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 | ||
arrayView.set(new Uint8Array(source.buffer).subarray(source.offset, source.limit), offset - len); | ||
this.view.set(source.view.subarray(source.offset, source.limit), offset - len); | ||
source.offset = source.limit; | ||
@@ -67,0 +74,0 @@ if (relative) |
@@ -26,2 +26,3 @@ /** | ||
if (this.buffer.byteLength < capacity) { | ||
//? if (DATAVIEW) { | ||
var buffer = new ArrayBuffer(capacity); | ||
@@ -31,2 +32,9 @@ new Uint8Array(buffer).set(new Uint8Array(this.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; | ||
//? } | ||
} | ||
@@ -33,0 +41,0 @@ //? } |
@@ -18,7 +18,9 @@ /** | ||
Array.prototype.reverse.call(this.buffer.slice(begin, end)); | ||
//? else { | ||
//? 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; | ||
}; |
@@ -34,3 +34,3 @@ /** | ||
bi; | ||
//? if (!NODE) | ||
//? if (!NODE && DATAVIEW) | ||
var view = new Uint8Array(bb.buffer); | ||
@@ -45,3 +45,6 @@ i=0; while (i<k) { | ||
//? } 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; | ||
@@ -48,0 +51,0 @@ //? } |
@@ -8,3 +8,3 @@ /** | ||
ByteBuffer.isByteBuffer = function(bb) { | ||
return (bb && bb instanceof ByteBuffer) === true; | ||
return (bb && bb["__isByteBuffer__"]) === true; | ||
}; |
/** | ||
* Gets the backing buffer type. | ||
* @returns {Function} `Buffer` for NB builds, `ArrayBuffer` for AB builds (classes) | ||
* @returns {Function} `Buffer` under node.js, `ArrayBuffer` in the browser (classes) | ||
* @expose | ||
@@ -12,2 +12,1 @@ */ | ||
}; | ||
@@ -98,4 +98,7 @@ /** | ||
bb.offset = buffer.byteOffset; | ||
bb.limit = buffer.byteOffset + buffer.length; | ||
bb.view = buffer.length > 0 ? new DataView(buffer.buffer) : null; | ||
bb.limit = buffer.byteOffset + buffer.byteLength; | ||
//? if (DATAVIEW) | ||
bb.view = new DataView(buffer.buffer); | ||
//? else | ||
bb.view = new Uint8Array(buffer.buffer); | ||
} | ||
@@ -108,3 +111,6 @@ } else if (buffer instanceof ArrayBuffer) { // Reuse ArrayBuffer | ||
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; | ||
} | ||
@@ -114,4 +120,7 @@ } else if (Object.prototype.toString.call(buffer) === "[object Array]") { // Create from octets | ||
bb.limit = buffer.length; | ||
for (i=0; i<buffer.length; ++i) | ||
for (var i=0; i<buffer.length; ++i) | ||
//? if (DATAVIEW) | ||
bb.view.setUint8(i, buffer[i]); | ||
//? else | ||
bb.view[i] = buffer[i]; | ||
} else | ||
@@ -118,0 +127,0 @@ throw TypeError("Illegal buffer"); // Otherwise fail |
/** | ||
* 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}. Will transparently {@link ByteBuffer#flip} this | ||
* ByteBuffer if `offset > limit` but the actual offsets remain untouched. | ||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. | ||
* @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory if | ||
@@ -17,7 +16,2 @@ * possible. Defaults to `false` | ||
limit = this.limit; | ||
if (offset > limit) { | ||
var t = offset; | ||
offset = limit; | ||
limit = t; | ||
} | ||
if (!this.noAssert) { | ||
@@ -40,8 +34,6 @@ //? ASSERT_RANGE('offset', 'limit'); | ||
// possible with Uint8Array#subarray only, but we have to return an ArrayBuffer by contract. So: | ||
if (!forceCopy && offset === 0 && limit === this.buffer.byteLength) { | ||
if (!forceCopy && offset === 0 && limit === this.buffer.byteLength) | ||
return this.buffer; | ||
} | ||
if (offset === limit) { | ||
if (offset === limit) | ||
return EMPTY_BUFFER; | ||
} | ||
var buffer = new ArrayBuffer(limit - offset); | ||
@@ -56,5 +48,3 @@ new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(offset, limit), 0); | ||
* 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}. Will transparently {@link ByteBuffer#flip} this | ||
* ByteBuffer if `offset > limit` but the actual offsets remain untouched. | ||
* Defaults to `false` | ||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. | ||
* @returns {!ArrayBuffer} Contents as an ArrayBuffer | ||
@@ -65,7 +55,2 @@ */ | ||
limit = this.limit; | ||
if (offset > limit) { | ||
var t = offset; | ||
offset = limit; | ||
limit = t; | ||
} | ||
if (!this.noAssert) { | ||
@@ -79,5 +64,4 @@ //? ASSERT_RANGE('offset', 'limit'); | ||
var dst = new Uint8Array(ab); | ||
for (var i=offset; i<limit; ++i) { | ||
for (var i=offset; i<limit; ++i) | ||
dst[i-offset] = this.buffer[i]; | ||
} | ||
} | ||
@@ -89,5 +73,3 @@ return ab; | ||
* Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between | ||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. Will transparently {@link ByteBuffer#flip} this | ||
* ByteBuffer if `offset > limit` but the actual offsets remain untouched. This is an alias of | ||
* {@link ByteBuffer#toBuffer}. | ||
* {@link ByteBuffer#offset} and {@link ByteBuffer#limit}. This is an alias of {@link ByteBuffer#toBuffer}. | ||
* @function | ||
@@ -102,2 +84,1 @@ * @param {boolean=} forceCopy If `true` returns a copy, otherwise returns a view referencing the same memory. | ||
@@ -14,3 +14,3 @@ /** | ||
if (typeof encoding === 'undefined') | ||
return "ByteBuffer/*?= NODE ? 'NB' : 'AB' */(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")"; | ||
return "ByteBuffer/*?= NODE ? 'NB' : 'AB'+(DATAVIEW ? '_DataView' : '') */(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")"; | ||
if (typeof encoding === 'number') | ||
@@ -17,0 +17,0 @@ encoding = "utf8", |
//? if (FLOAT32) { | ||
// types/floats/float32 | ||
//? if (!NODE && !DATAVIEW) { | ||
//? include("ieee754.js"); | ||
//? } | ||
/** | ||
@@ -23,4 +27,6 @@ * Writes a 32bit float. | ||
: this.buffer.writeFloatBE(value, offset, true); | ||
//? } else | ||
//? } else if (DATAVIEW) | ||
this.view.setFloat32(offset, value, this.littleEndian); | ||
//? else | ||
ieee754_write(this.view, value, offset, this.littleEndian, 23, 4); | ||
//? RELATIVE(4); | ||
@@ -57,4 +63,6 @@ return this; | ||
: this.buffer.readFloatBE(offset, true); | ||
//? } else | ||
//? } 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); | ||
@@ -61,0 +69,0 @@ return value; |
@@ -23,4 +23,6 @@ //? if (FLOAT64) { | ||
: this.buffer.writeDoubleBE(value, offset, true); | ||
//? } else | ||
//? } else if (DATAVIEW) | ||
this.view.setFloat64(offset, value, this.littleEndian); | ||
//? else | ||
ieee754_write(this.view, value, offset, this.littleEndian, 52, 8); | ||
//? RELATIVE(8); | ||
@@ -57,4 +59,6 @@ return this; | ||
: this.buffer.readDoubleBE(offset, true); | ||
//? } else | ||
//? } 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); | ||
@@ -61,0 +65,0 @@ return value; |
@@ -1,2 +0,37 @@ | ||
// ref: https://github.com/feross/ieee754 | ||
/* | ||
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) { | ||
@@ -17,3 +52,3 @@ var e, m, | ||
nBits += eLen; | ||
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8); | ||
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
@@ -23,3 +58,3 @@ m = e & ((1 << (-nBits)) - 1); | ||
nBits += mLen; | ||
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8); | ||
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
@@ -35,5 +70,14 @@ if (e === 0) { | ||
return (s ? -1 : 1) * m * Math.pow(2, e - mLen); | ||
}; | ||
} | ||
// ref: https://github.com/feross/ieee754 | ||
/** | ||
* 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) { | ||
@@ -82,9 +126,9 @@ var e, m, c, | ||
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8); | ||
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); | ||
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} | ||
buffer[offset + i - d] |= s * 128; | ||
}; | ||
} |
@@ -19,9 +19,9 @@ //? if (INT16) { | ||
//? ENSURE_CAPACITY(2); | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view'; | ||
if (this.littleEndian) { | ||
this.buffer[offset+1] = (value & 0xFF00) >>> 8; | ||
this.buffer[offset ] = value & 0x00FF; | ||
/*?= dst */[offset+1] = (value & 0xFF00) >>> 8; | ||
/*?= dst */[offset ] = value & 0x00FF; | ||
} else { | ||
this.buffer[offset] = (value & 0xFF00) >>> 8; | ||
this.buffer[offset+1] = value & 0x00FF; | ||
/*?= dst */[offset] = (value & 0xFF00) >>> 8; | ||
/*?= dst */[offset+1] = value & 0x00FF; | ||
} | ||
@@ -60,10 +60,10 @@ //? } else | ||
} | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view'; | ||
var value = 0; | ||
if (this.littleEndian) { | ||
value = this.buffer[offset ]; | ||
value |= this.buffer[offset+1] << 8; | ||
value = /*?= dst */[offset ]; | ||
value |= /*?= dst */[offset+1] << 8; | ||
} else { | ||
value = this.buffer[offset ] << 8; | ||
value |= this.buffer[offset+1]; | ||
value = /*?= dst */[offset ] << 8; | ||
value |= /*?= dst */[offset+1]; | ||
} | ||
@@ -105,9 +105,9 @@ if ((value & 0x8000) === 0x8000) value = -(0xFFFF - value + 1); // Cast to signed | ||
//? ENSURE_CAPACITY(2); | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view'; | ||
if (this.littleEndian) { | ||
this.buffer[offset+1] = (value & 0xFF00) >>> 8; | ||
this.buffer[offset ] = value & 0x00FF; | ||
/*?= dst */[offset+1] = (value & 0xFF00) >>> 8; | ||
/*?= dst */[offset ] = value & 0x00FF; | ||
} else { | ||
this.buffer[offset] = (value & 0xFF00) >>> 8; | ||
this.buffer[offset+1] = value & 0x00FF; | ||
/*?= dst */[offset] = (value & 0xFF00) >>> 8; | ||
/*?= dst */[offset+1] = value & 0x00FF; | ||
} | ||
@@ -121,2 +121,13 @@ //? } else | ||
/** | ||
* 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. | ||
@@ -134,10 +145,10 @@ * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `2` if omitted. | ||
} | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { var dst = NODE ? 'this.buffer' : 'this.view'; | ||
var value = 0; | ||
if (this.littleEndian) { | ||
value = this.buffer[offset ]; | ||
value |= this.buffer[offset+1] << 8; | ||
value = /*?= dst */[offset ]; | ||
value |= /*?= dst */[offset+1] << 8; | ||
} else { | ||
value = this.buffer[offset ] << 8; | ||
value |= this.buffer[offset+1]; | ||
value = /*?= dst */[offset ] << 8; | ||
value |= /*?= dst */[offset+1]; | ||
} | ||
@@ -150,2 +161,13 @@ //? } else | ||
/** | ||
* 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; | ||
//? } |
@@ -17,3 +17,3 @@ //? if (INT32) { | ||
//? ENSURE_CAPACITY(4); | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
//? WRITE_UINT32_ARRAY(); | ||
@@ -47,3 +47,3 @@ //? } else | ||
} | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
var value = 0; | ||
@@ -81,3 +81,3 @@ //? READ_UINT32_ARRAY(); | ||
//? ENSURE_CAPACITY(4); | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
//? WRITE_UINT32_ARRAY(); | ||
@@ -91,2 +91,11 @@ //? } else | ||
/** | ||
* 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. | ||
@@ -102,3 +111,3 @@ * @param {number=} offset Offset to read from. Will use and increase {@link ByteBuffer#offset} by `4` if omitted. | ||
} | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
var value = 0; | ||
@@ -112,2 +121,11 @@ //? READ_UINT32_ARRAY(); | ||
/** | ||
* 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; | ||
//? } |
@@ -21,3 +21,3 @@ //? if (INT64) { | ||
//? ENSURE_CAPACITY(8); | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
var lo = value.low, | ||
@@ -69,3 +69,3 @@ hi = value.high; | ||
} | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
var lo = 0, | ||
@@ -117,3 +117,3 @@ hi = 0; | ||
//? ENSURE_CAPACITY(8); | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
var lo = value.low, | ||
@@ -142,2 +142,12 @@ hi = value.high; | ||
}; | ||
/** | ||
* 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; | ||
@@ -155,3 +165,3 @@ /** | ||
} | ||
//? if (NODE) { | ||
//? if (NODE || !DATAVIEW) { | ||
var lo = 0, | ||
@@ -177,2 +187,11 @@ hi = 0; | ||
}; | ||
/** | ||
* 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; | ||
@@ -179,0 +198,0 @@ } // Long |
@@ -20,4 +20,6 @@ //? if (INT8) { | ||
this.buffer[offset] = value; | ||
//? else if (DATAVIEW) | ||
this.view.setInt8(offset, value); | ||
//? else | ||
this.view.setInt8(offset, value); | ||
this.view[offset] = value; | ||
//? RELATIVE(1); | ||
@@ -51,4 +53,8 @@ return this; | ||
if ((value & 0x80) === 0x80) value = -(0xFF - value + 1); // Cast to signed | ||
//? } else | ||
//? } 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); | ||
@@ -85,4 +91,6 @@ return value; | ||
this.buffer[offset] = value; | ||
//? else if (DATAVIEW) | ||
this.view.setUint8(offset, value); | ||
//? else | ||
this.view.setUint8(offset, value); | ||
this.view[offset] = value; | ||
//? RELATIVE(1); | ||
@@ -93,2 +101,12 @@ 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. | ||
@@ -106,4 +124,6 @@ * @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} by `1` if omitted. | ||
var value = this.buffer[offset]; | ||
//? else if (DATAVIEW) | ||
var value = this.view.getUint8(offset); | ||
//? else | ||
var value = this.view.getUint8(offset); | ||
var value = this.view[offset]; | ||
//? RELATIVE(1); | ||
@@ -113,2 +133,11 @@ 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; | ||
//? } |
@@ -36,5 +36,11 @@ //? if (CSTRING) { | ||
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; | ||
//? } | ||
@@ -87,3 +93,7 @@ if (relative) { | ||
throw RangeError("Illegal range: Truncated data, "+offset+" < "+this.limit); | ||
return (b = this.view.getUint8(offset++)) === 0 ? null : b; | ||
//? if (DATAVIEW) | ||
b = this.view.getUint8(offset++); | ||
//? else | ||
b = this.view[offset++]; | ||
return b === 0 ? null : b; | ||
}.bind(this), sd = stringDestination(), true); | ||
@@ -90,0 +100,0 @@ if (relative) { |
@@ -31,6 +31,12 @@ //? if (ISTRING) { | ||
//? 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)); | ||
@@ -72,3 +78,6 @@ if (offset !== start + 4 + k) | ||
//? } else { | ||
//? if (DATAVIEW) | ||
temp = this.view.getUint32(offset, this.littleEndian); | ||
//? else | ||
//? READ_UINT32_ARRAY('temp'); | ||
offset += 4; | ||
@@ -78,3 +87,6 @@ var k = offset + temp, | ||
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); | ||
@@ -81,0 +93,0 @@ str = sd(); |
@@ -47,3 +47,6 @@ //? if (UTF8STRING && UTF8) { | ||
utfx.encodeUTF16toUTF8(stringSource(str), function(b) { | ||
//? if (DATAVIEW) | ||
this.view.setUint8(offset++, b); | ||
//? else | ||
this.view[offset++] = b; | ||
}.bind(this)); | ||
@@ -73,3 +76,2 @@ if (relative) { | ||
* `length` property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF. | ||
* @function | ||
* @param {string} str String to calculate | ||
@@ -85,3 +87,2 @@ * @returns {number} Number of UTF8 characters | ||
* Calculates the number of UTF8 bytes of a string. | ||
* @function | ||
* @param {string} str String to calculate | ||
@@ -99,4 +100,15 @@ * @returns {number} Number of UTF8 bytes | ||
}; | ||
//? 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. | ||
@@ -133,7 +145,9 @@ * @param {number} length Number of characters or bytes to read. | ||
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.getUint8(offset++) : null; | ||
return i < length && offset < this.limit ? this.view[offset++] : null; | ||
}.bind(this), function(cp) { | ||
++i; utfx.UTF8toUTF16(cp, sd); | ||
}.bind(this)); | ||
}); | ||
if (i !== length) | ||
@@ -168,3 +182,6 @@ throw RangeError("Illegal range: Truncated data, "+i+" == "+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); | ||
@@ -171,0 +188,0 @@ if (offset !== k) |
@@ -34,3 +34,6 @@ //? if (VSTRING && VARINTS && VARINT32) { | ||
utfx.encodeUTF16toUTF8(stringSource(str), function(b) { | ||
//? if (DATAVIEW) | ||
this.view.setUint8(offset++, b); | ||
//? else | ||
this.view[offset++] = b; | ||
}.bind(this)); | ||
@@ -75,3 +78,6 @@ if (offset !== start+k+l) | ||
utfx.decodeUTF8toUTF16(function() { | ||
//? if (DATAVIEW) | ||
return offset < k ? this.view.getUint8(offset++) : null; | ||
//? else | ||
return offset < k ? this.view[offset++] : null; | ||
}.bind(this), sd, this.noAssert); | ||
@@ -78,0 +84,0 @@ str = sd(); |
@@ -66,5 +66,6 @@ //? if (VARINT32) { | ||
// ref: http://code.google.com/searchframe#WTeibokF6gE/trunk/src/google/protobuf/io/coded_stream.cc | ||
//? if (NODE) | ||
this.buffer[offset] = b = value | 0x80; | ||
//? else | ||
//? var dst = NODE ? 'this.buffer' : 'this.view'; | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset] = b = value | 0x80; | ||
//? } else | ||
this.view.setUint8(offset, b = value | 0x80); | ||
@@ -74,28 +75,28 @@ value >>>= 0; | ||
b = (value >> 7) | 0x80; | ||
//? if (NODE) | ||
this.buffer[offset+1] = b; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset+1] = b; | ||
//? } else | ||
this.view.setUint8(offset+1, b); | ||
if (value >= 1 << 14) { | ||
b = (value >> 14) | 0x80; | ||
//? if (NODE) | ||
this.buffer[offset+2] = b; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset+2] = b; | ||
//? } else | ||
this.view.setUint8(offset+2, b); | ||
if (value >= 1 << 21) { | ||
b = (value >> 21) | 0x80; | ||
//? if (NODE) | ||
this.buffer[offset+3] = b; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset+3] = b; | ||
//? } else | ||
this.view.setUint8(offset+3, b); | ||
if (value >= 1 << 28) { | ||
//? if (NODE) | ||
this.buffer[offset+4] = (value >> 28) & 0x0F; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset+4] = (value >> 28) & 0x0F; | ||
//? } else | ||
this.view.setUint8(offset+4, (value >> 28) & 0x0F); | ||
size = 5; | ||
} else { | ||
//? if (NODE) | ||
this.buffer[offset+3] = b & 0x7F; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset+3] = b & 0x7F; | ||
//? } else | ||
this.view.setUint8(offset+3, b & 0x7F); | ||
@@ -105,5 +106,5 @@ size = 4; | ||
} else { | ||
//? if (NODE) | ||
this.buffer[offset+2] = b & 0x7F; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset+2] = b & 0x7F; | ||
//? } else | ||
this.view.setUint8(offset+2, b & 0x7F); | ||
@@ -113,5 +114,5 @@ size = 3; | ||
} else { | ||
//? if (NODE) | ||
this.buffer[offset+1] = b & 0x7F; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset+1] = b & 0x7F; | ||
//? } else | ||
this.view.setUint8(offset+1, b & 0x7F); | ||
@@ -121,5 +122,5 @@ size = 2; | ||
} else { | ||
//? if (NODE) | ||
this.buffer[offset] = b & 0x7F; | ||
//? else | ||
//? if (NODE || !DATAVIEW) { | ||
/*?= dst */[offset] = b & 0x7F; | ||
//? } else | ||
this.view.setUint8(offset, b & 0x7F); | ||
@@ -176,4 +177,6 @@ size = 1; | ||
temp = this.buffer[ioffset]; | ||
//? else if (DATAVIEW) | ||
temp = this.view.getUint8(ioffset); | ||
//? else | ||
temp = this.view.getUint8(ioffset); | ||
temp = this.view[ioffset]; | ||
if (size < 5) | ||
@@ -180,0 +183,0 @@ value |= ((temp&0x7F)<<(7*size)) >>> 0; |
@@ -87,13 +87,13 @@ //? if (VARINT64) { | ||
switch (size) { | ||
//? if (NODE) { | ||
case 10: this.buffer[offset+9] = (part2 >>> 7) & 0x01; | ||
case 9 : this.buffer[offset+8] = size !== 9 ? (part2 ) | 0x80 : (part2 ) & 0x7F; | ||
case 8 : this.buffer[offset+7] = size !== 8 ? (part1 >>> 21) | 0x80 : (part1 >>> 21) & 0x7F; | ||
case 7 : this.buffer[offset+6] = size !== 7 ? (part1 >>> 14) | 0x80 : (part1 >>> 14) & 0x7F; | ||
case 6 : this.buffer[offset+5] = size !== 6 ? (part1 >>> 7) | 0x80 : (part1 >>> 7) & 0x7F; | ||
case 5 : this.buffer[offset+4] = size !== 5 ? (part1 ) | 0x80 : (part1 ) & 0x7F; | ||
case 4 : this.buffer[offset+3] = size !== 4 ? (part0 >>> 21) | 0x80 : (part0 >>> 21) & 0x7F; | ||
case 3 : this.buffer[offset+2] = size !== 3 ? (part0 >>> 14) | 0x80 : (part0 >>> 14) & 0x7F; | ||
case 2 : this.buffer[offset+1] = size !== 2 ? (part0 >>> 7) | 0x80 : (part0 >>> 7) & 0x7F; | ||
case 1 : this.buffer[offset ] = size !== 1 ? (part0 ) | 0x80 : (part0 ) & 0x7F; | ||
//? 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 { | ||
@@ -152,28 +152,14 @@ case 10: this.view.setUint8(offset+9, (part2 >>> 7) & 0x01); | ||
b = 0; | ||
//? if (NODE) { | ||
//? if (INLINE) { // Assert through checking for undefined (not optimal but coherent) | ||
b = this.buffer[offset++]; part0 = (b & 0x7F) ; if ( b & 0x80 ) { | ||
b = this.buffer[offset++]; part0 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part0 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part0 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part1 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part1 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part1 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part1 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part2 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
b = this.buffer[offset++]; part2 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) { | ||
//? 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 { // Assert as usual | ||
b = this.buffer.readUint8(offset++, true ); part0 = (b & 0x7F) ; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part0 |= (b & 0x7F) << 7; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part0 |= (b & 0x7F) << 14; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part0 |= (b & 0x7F) << 21; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part1 = (b & 0x7F) ; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part1 |= (b & 0x7F) << 7; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part1 |= (b & 0x7F) << 14; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part1 |= (b & 0x7F) << 21; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part2 = (b & 0x7F) ; if (b & 0x80) { | ||
b = this.buffer.readUint8(offset++, this.noAssert); part2 |= (b & 0x7F) << 7; if (b & 0x80) { | ||
throw Error("Buffer overrun"); }}}}}}}}}} | ||
//? } | ||
//? } else { // Asserts on its own | ||
@@ -180,0 +166,0 @@ b = this.view.getUint8(offset++); part0 = (b & 0x7F) ; if (b & 0x80) { |
@@ -22,4 +22,6 @@ /* | ||
var ByteBuffer = require("../dist/ByteBufferNB.js"); | ||
ByteBuffer.ByteBufferNB = ByteBuffer; | ||
ByteBuffer.ByteBufferAB = require("../dist/ByteBufferAB.min.js"); | ||
var ByteBufferNB = ByteBuffer.ByteBufferNB = ByteBuffer; | ||
var ByteBufferAB = ByteBuffer.ByteBufferAB = require("../dist/ByteBufferAB.min.js"); | ||
var ByteBufferAB_DataView = ByteBuffer.ByteBufferAB_DataView = require("../dist/ByteBufferAB_DataView.min.js"); | ||
var pkg = require("../package.json"); | ||
@@ -53,2 +55,3 @@ /** | ||
var type = ByteBuffer.type(), // Buffer or ArrayBuffer | ||
accessor = ByteBuffer.accessor(), | ||
Long = ByteBuffer.Long; | ||
@@ -59,9 +62,12 @@ var suite = {}; | ||
test.ok(require("../index.js")); | ||
if (type === Buffer) | ||
test.log("\n\n --- node Buffer backed ByteBuffer ---\n".bold.white), | ||
if (ByteBuffer == ByteBufferNB) | ||
test.log("\n\n --- ByteBufferNB ---\n".bold.white), | ||
test.log("[optional] node-memcpy is "+(ByteBuffer.memcpy ? "present" : "not present")); | ||
else | ||
test.log("\n\n --- ArrayBuffer backed ByteBuffer ---\n".bold.white); | ||
else if (ByteBuffer == ByteBufferAB) | ||
test.log("\n\n --- ByteBufferAB ---\n".bold.white); | ||
else if (ByteBuffer == ByteBufferAB_DataView) | ||
test.log("\n\n --- ByteBufferAB_DataView ---\n".bold.white); | ||
test.ok(type === Buffer || type === ArrayBuffer); | ||
test.ok(typeof ByteBuffer == "function"); | ||
test.strictEqual(pkg.version, ByteBuffer.VERSION); | ||
test.done(); | ||
@@ -88,2 +94,14 @@ }; | ||
test.equal(bb.noAssert, !ByteBuffer.DEFAULT_NOASSERT); | ||
// __isByteBuffer__ | ||
test.strictEqual(bb.__isByteBuffer__, true); | ||
bb.__isByteBuffer__ = false; | ||
test.strictEqual(bb.__isByteBuffer__, true); | ||
test.equal(ByteBuffer.isByteBuffer(bb), true); | ||
// Fixed set of properties | ||
for (var i in bb) | ||
if (bb.hasOwnProperty(i) && ["offset", "markedOffset", "limit", "littleEndian", "noAssert", "buffer", "view"].indexOf(i) < 0) | ||
test.fail("Illegal enumerable property: "+i); | ||
test.done(); | ||
@@ -851,3 +869,3 @@ }; | ||
test.equal(bb.toString("debug").substr(0,7), "<61 62>"); | ||
test.equal(bb.toString(), (type === ArrayBuffer ? "ByteBufferAB" : "ByteBufferNB")+"(offset=0,markedOffset=-1,limit=2,capacity=3)"); | ||
test.equal(bb.toString(), (type === ArrayBuffer ? (accessor === DataView ? "ByteBufferAB_DataView" : "ByteBufferAB") : "ByteBufferNB")+"(offset=0,markedOffset=-1,limit=2,capacity=3)"); | ||
test.strictEqual(bb.offset, 0); | ||
@@ -989,4 +1007,3 @@ test.done(); | ||
test.ok(sandbox.define.called); | ||
test.equal(sandbox.define.called[0], "ByteBuffer"); | ||
test.equal(sandbox.define.called[1][0], "Long"); | ||
test.equal(sandbox.define.called[0][0], "Long"); | ||
test.done(); | ||
@@ -1044,4 +1061,5 @@ }; | ||
}, | ||
"NB": makeSuite(ByteBuffer.ByteBufferNB), | ||
"AB": makeSuite(ByteBuffer.ByteBufferAB) | ||
"NB": makeSuite(ByteBufferNB), | ||
"AB": makeSuite(ByteBufferAB), | ||
"AB_DataView": makeSuite(ByteBufferAB_DataView) | ||
}; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1011044
87
16069
65
6
3