bytebuffer
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -6,50 +6,50 @@ /* | ||
*/ | ||
(function(n){function q(l){function c(a,b){a="undefined"!==typeof a?parseInt(a,10):c.DEFAULT_CAPACITY;1>a&&(a=c.DEFAULT_CAPACITY);this.array=3==arguments.length&&!0===arguments[2]?null:new ArrayBuffer(a);this.view=null!=this.array?new DataView(this.array):null;this.offset=0;this.markedOffset=-1;this.length=0;this.littleEndian="undefined"!=typeof b?!!b:!1}var m=null;if("function"===typeof require)try{var p=require("buffer"),m=p&&"function"===typeof p.Buffer&&"function"===typeof p.Buffer.isBuffer?p.Buffer: | ||
null}catch(n){}c.DEFAULT_CAPACITY=16;c.LITTLE_ENDIAN=!0;c.BIG_ENDIAN=!1;c.Long=l;c.allocate=function(a,b){return new c(a,b)};c.wrap=function(a,b){if("string"===typeof a)return(new c).writeUTF8String(a).flip();var d;if(m&&m.isBuffer(a)){d=(new Uint8Array(a)).buffer;if(d===a){d=a;for(var f=new ArrayBuffer(d.length),e=new Uint8Array(f),g=0;g<d.length;++g)e[g]=d[g];d=f}a=d}if(null===a||"object"!==typeof a)throw Error("Cannot wrap null or non-object");if(a instanceof c)return a.clone();a.array?a=a.array: | ||
a.buffer&&(a=a.buffer);if(!(a instanceof ArrayBuffer))throw Error("Cannot wrap buffer of type "+typeof a+", "+a.constructor.name);d=new c(0,b,!0);d.array=a;d.view=new DataView(d.array);d.offset=0;d.length=a.byteLength;return d};c.prototype.LE=function(){this.littleEndian=!0;return this};c.prototype.BE=function(){this.littleEndian=!1;return this};c.prototype.resize=function(a){if(1>a)return!1;null==this.array&&(this.array=new ArrayBuffer(a),this.view=new DataView(this.array));if(this.array.byteLength< | ||
a){var b=new Uint8Array(this.array);a=new ArrayBuffer(a);(new Uint8Array(a)).set(b);this.array=a;this.view=new DataView(a);return!0}return!1};c.prototype.slice=function(a,b){if(null==this.array)throw Error(this+" cannot be sliced: Already destroyed");if(b<=a)throw Error(this+" cannot be sliced: End ("+b+") is less than begin ("+a+")");if(0>a||a>this.array.byteLength||1>b||b>this.array.byteLength)throw Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+a+"-"+b+")"); | ||
var d=this.clone();d.offset=a;d.length=b;return d};c.prototype.sliceAndCompact=function(a,b){return c.wrap(this.slice(a,b).toArrayBuffer(!0))};c.prototype.ensureCapacity=function(a){return null==this.array?this.resize(a):this.array.byteLength<a?this.resize(2*this.array.byteLength>=a?2*this.array.byteLength:a):!1};c.prototype.flip=function(){this.length=null==this.array?0:this.offset;this.offset=0;return this};c.prototype.mark=function(a){if(null==this.array)throw Error(this+" cannot be marked: Already destroyed"); | ||
a="undefined"!==typeof a?parseInt(a,10):this.offset;if(0>a||a>this.array.byteLength)throw Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+a);this.markedOffset=a;return this};c.prototype.reset=function(){0<=this.markedOffset?(this.offset=this.markedOffset,this.markedOffset=-1):this.length=this.offset=0;return this};c.prototype.clone=function(){var a=new c(-1,this.littleEndian,!0);a.array=this.array;a.view=this.view;a.offset=this.offset; | ||
a.length=this.length;return a};c.prototype.copy=function(){if(null==this.array)return this.clone();var a=new c(this.array.byteLength,this.littleEndian),b=new Uint8Array(this.array);(new Uint8Array(a.array)).set(b);a.offset=this.offset;a.length=this.length;return a};c.prototype.remaining=function(){return null==this.array?0:this.length-this.offset};c.prototype.capacity=function(){return null!=this.array?this.array.byteLength:0};c.prototype.compact=function(){if(null==this.array)throw Error(this+" cannot be compacted: Already destroyed"); | ||
this.offset>this.length&&this.flip();if(this.offset==this.length)throw Error(this+" cannot be compacted: Offset ("+this.offset+") is equal to its length ("+this.length+")");if(0==this.offset&&this.length==this.array.byteLength)return this;var a=new Uint8Array(this.array),b=new ArrayBuffer(this.length-this.offset);(new Uint8Array(b)).set(a.subarray(this.offset,this.length));this.array=b;this.offset=0;this.length=this.array.byteLength;return this};c.prototype.destroy=function(){if(null!=this.array)return this.view= | ||
this.array=null,this.length=this.offset=0,this};c.prototype.reverse=function(){if(null==this.array)throw Error(this+" cannot be reversed: Already destroyed");Array.prototype.reverse.call(new Uint8Array(this.array));var a=this.offset;this.offset=this.array.byteLength-this.length;this.length=this.array.byteLength-a;return this};c.prototype.append=function(a,b){a instanceof c||(a=c.wrap(a));if(null==a.array)throw Error(a+" cannot be appended to "+this+": Already destroyed");var d=a.length-a.offset;if(0== | ||
d)return this;0>d&&(a=a.clone().flip(),d=a.length-a.offset);b="undefined"!==typeof b?b:(this.offset+=d)-d;this.ensureCapacity(b+d);d=new Uint8Array(a.array);(new Uint8Array(this.array)).set(d.subarray(a.offset,a.length),b);return this};c.prototype.prepend=function(a,b){a instanceof c||(a=c.wrap(a));if(null==a.array)throw a+" cannot be prepended to "+this+": Already destroyed";var d=a.length-a.offset;if(0==d)return this;0>d&&(a=a.clone().flip(),d=a.length-a.offset);var f="undefined"===typeof b;b="undefined"!== | ||
typeof b?b:this.offset;var e=d-b;0<e?(this.ensureCapacity(this.length+e),this.append(this,d),this.offset+=e,this.length+=e,this.append(a,0)):this.append(a,b-d);f&&(this.offset-=d);return this};c.prototype.writeInt8=function(a,b){b="undefined"!=typeof b?b:(this.offset+=1)-1;this.ensureCapacity(b+1);this.view.setInt8(b,a);return this};c.prototype.readInt8=function(a){a="undefined"!==typeof a?a:(this.offset+=1)-1;if(a>=this.array.byteLength)throw Error("Cannot read int8 from "+this+" at "+a+": Capacity overflow"); | ||
return this.view.getInt8(a)};c.prototype.writeByte=c.prototype.writeInt8;c.prototype.readByte=c.prototype.readInt8;c.prototype.writeUint8=function(a,b){b="undefined"!=typeof b?b:(this.offset+=1)-1;this.ensureCapacity(b+1);this.view.setUint8(b,a);return this};c.prototype.readUint8=function(a){a="undefined"!==typeof a?a:(this.offset+=1)-1;if(a+1>this.array.byteLength)throw Error("Cannot read uint8 from "+this+" at "+a+": Capacity overflow");return this.view.getUint8(a)};c.prototype.writeInt16=function(a, | ||
b){b="undefined"!==typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setInt16(b,a,this.littleEndian);return this};c.prototype.readInt16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.byteLength)throw Error("Cannot read int16 from "+this+" at "+a+": Capacity overflow");return this.view.getInt16(a,this.littleEndian)};c.prototype.writeShort=c.prototype.writeInt16;c.prototype.readShort=c.prototype.readInt16;c.prototype.writeUint16=function(a,b){b="undefined"!== | ||
typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setUint16(b,a,this.littleEndian);return this};c.prototype.readUint16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.b)throw Error("Cannot read int16 from "+this+" at "+a+": Capacity overflow");return this.view.getUint16(a,this.littleEndian)};c.prototype.writeInt32=function(a,b){b="undefined"!==typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setInt32(b,a,this.littleEndian);return this};c.prototype.readInt32= | ||
function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read int32 from "+this+" at "+a+": Capacity overflow");return this.view.getInt32(a,this.littleEndian)};c.prototype.writeInt=c.prototype.writeInt32;c.prototype.readInt=c.prototype.readInt32;c.prototype.writeUint32=function(a,b){b="undefined"!=typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setUint32(b,a,this.littleEndian);return this};c.prototype.readUint32=function(a){a="undefined"!== | ||
typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read uint32 from "+this+" at "+a+": Capacity overflow");return this.view.getUint32(a,this.littleEndian)};c.prototype.writeFloat32=function(a,b){b="undefined"!==typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setFloat32(b,a,this.littleEndian);return this};c.prototype.readFloat32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(null==this.array||a+4>this.array.byteLength)throw Error("Cannot read float32 from "+ | ||
this+" at "+a+": Capacity overflow");return this.view.getFloat32(a,this.littleEndian)};c.prototype.writeFloat=c.prototype.writeFloat32;c.prototype.readFloat=c.prototype.readFloat32;c.prototype.writeFloat64=function(a,b){b="undefined"!==typeof b?b:(this.offset+=8)-8;this.ensureCapacity(b+8);this.view.setFloat64(b,a,this.littleEndian);return this};c.prototype.readFloat64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null==this.array||a+8>this.array.byteLength)throw Error("Cannot read float64 from "+ | ||
this+" at "+a+": Capacity overflow");return this.view.getFloat64(a,this.littleEndian)};c.prototype.writeDouble=c.prototype.writeFloat64;c.prototype.readDouble=c.prototype.readFloat64;c.prototype.writeInt64=function(a,b){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));this.ensureCapacity(b+8);this.littleEndian?(this.view.setInt32(b, | ||
a.getLowBits(),!0),this.view.setInt32(b+4,a.getHighBits(),!0)):(this.view.setInt32(b,a.getHighBits(),!1),this.view.setInt32(b+4,a.getLowBits(),!1));return this};c.prototype.readInt64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null==this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+this+" at "+a+": Capacity overflow"); | ||
return this.littleEndian?l.fromBits(this.view.getInt32(a,!0),this.view.getInt32(a+4,!0),!1):l.fromBits(this.view.getInt32(a+4,!1),this.view.getInt32(a,!1),!1)};c.prototype.writeUint64=function(a,b){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!0));this.ensureCapacity(b+8);this.littleEndian?(this.view.setUint32(b, | ||
a.getLowBitsUnsigned(),!0),this.view.setUint32(b+4,a.getHighBitsUnsigned(),!0)):(this.view.setUint32(b,a.getHighBitsUnsigned(),!1),this.view.setUint32(b+4,a.getLowBitsUnsigned(),!1));return this};c.prototype.readUint64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null==this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+ | ||
this+" at "+a+": Capacity overflow");return this.littleEndian?l.fromBits(this.view.getUint32(a,!0),this.view.getUint32(a+4,!0),!0):l.fromBits(this.view.getUint32(a+4,!1),this.view.getUint32(a,!1),!0)};c.prototype.writeLong=c.prototype.writeInt64;c.prototype.readLong=c.prototype.readInt64;c.MAX_VARINT32_BYTES=5;c.prototype.writeVarint32=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;a>>>=0;this.ensureCapacity(b+c.calculateVarint32(a));var f=new DataView(this.array), | ||
e=0;f.setUint8(b,a|128);128<=a?(f.setUint8(b+1,a>>7|128),16384<=a?(f.setUint8(b+2,a>>14|128),2097152<=a?(f.setUint8(b+3,a>>21|128),268435456<=a?(f.setUint8(b+4,a>>28&127),e=5):(f.setUint8(b+3,f.getUint8(b+3)&127),e=4)):(f.setUint8(b+2,f.getUint8(b+2)&127),e=3)):(f.setUint8(b+1,f.getUint8(b+1)&127),e=2)):(f.setUint8(b,f.getUint8(b)&127),e=1);return d?(this.offset+=e,this):e};c.prototype.readVarint32=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d=new DataView(this.array), | ||
f=0,e,g=0;do e=d.getUint8(a+f),f<c.MAX_VARINT32_BYTES&&(g|=(e&127)<<7*f>>>0),++f;while(e&128);g|=0;return b?(this.offset+=f,g):{value:g,length:f}};c.prototype.writeZigZagVarint32=function(a,b){return this.writeVarint32(c.zigZagEncode32(a),b)};c.prototype.readZigZagVarint32=function(a){a=this.readVarint32(a);return"object"===typeof a?(a.value=c.zigZagDecode32(a.value),a):c.zigZagDecode32(a)};c.MAX_VARINT64_BYTES=10;c.prototype.writeVarint64=function(a,b){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details"); | ||
var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));var f=a.toInt()>>>0,e=a.shiftRightUnsigned(28).toInt()>>>0,g=a.shiftRightUnsigned(56).toInt()>>>0,k=c.calculateVarint64(a);this.ensureCapacity(b+k);var h=new DataView(this.array);switch(k){case 10:h.setUint8(b+9,g>>>7|128);case 9:h.setUint8(b+8,g|128);case 8:h.setUint8(b+7,e>>>21|128);case 7:h.setUint8(b+6,e>>>14|128);case 6:h.setUint8(b+5,e>>>7|128);case 5:h.setUint8(b+ | ||
4,e|128);case 4:h.setUint8(b+3,f>>>21|128);case 3:h.setUint8(b+2,f>>>14|128);case 2:h.setUint8(b+1,f>>>7|128);case 1:h.setUint8(b+0,f|128)}h.setUint8(b+k-1,h.getUint8(b+k-1)&127);return d?(this.offset+=k,this):k};c.prototype.readVarint64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");var b="undefined"===typeof a,d=a="undefined"!==typeof a?a:this.offset,c=new DataView(this.array),e,g=0,k=0,h;h=c.getUint8(a++); | ||
e=h&127;if(h&128&&(h=c.getUint8(a++),e|=(h&127)<<7,h&128&&(h=c.getUint8(a++),e|=(h&127)<<14,h&128&&(h=c.getUint8(a++),e|=(h&127)<<21,h&128&&(h=c.getUint8(a++),g=h&127,h&128&&(h=c.getUint8(a++),g|=(h&127)<<7,h&128&&(h=c.getUint8(a++),g|=(h&127)<<14,h&128&&(h=c.getUint8(a++),g|=(h&127)<<21,h&128&&(h=c.getUint8(a++),k=h&127,h&128&&(h=c.getUint8(a++),k|=(h&127)<<7,h&128))))))))))throw Error("Data must be corrupt: Buffer overrun");c=l.from28Bits(e,g,k,!1);return b?(this.offset=a,c):{value:c,length:a-d}}; | ||
c.prototype.writeZigZagVarint64=function(a,b){return this.writeVarint64(c.zigZagEncode64(a),b)};c.prototype.readZigZagVarint64=function(a){a=this.readVarint64(a);return"object"!==typeof a||a instanceof l?c.zigZagDecode64(a):(a.value=c.zigZagDecode64(a.value),a)};c.prototype.writeVarint=c.prototype.writeVarint32;c.prototype.readVarint=c.prototype.readVarint32;c.prototype.writeZigZagVarint=c.prototype.writeZigZagVarint32;c.prototype.readZigZagVarint=c.prototype.readZigZagVarint32;c.calculateVarint32= | ||
function(a){a>>>=0;return 128>a?1:16384>a?2:2097152>a?3:268435456>a?4:5};c.calculateVarint64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));var b=a.toInt()>>>0,d=a.shiftRightUnsigned(28).toInt()>>>0;a=a.shiftRightUnsigned(56).toInt()>>>0;return 0==a?0==d?16384>b?128>b?1:2:2097152>b?3:4:16384>d?128>d?5:6:2097152>d?7:8:128>a?9:10};c.zigZagEncode32= | ||
function(a){return((a|=0)<<1^a>>31)>>>0};c.zigZagDecode32=function(a){return a>>>1^-(a&1)|0};c.zigZagEncode64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");"object"===typeof a&&a instanceof l?a.unsigned&&(a=a.toSigned()):a=l.fromNumber(a,!1);return a.shiftLeft(1).xor(a.shiftRight(63)).toUnsigned()};c.zigZagDecode64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details"); | ||
"object"===typeof a&&a instanceof l?a.unsigned||(a=a.toUnsigned()):a=l.fromNumber(a,!0);return a.shiftRightUnsigned(1).xor(a.and(l.ONE).toSigned().negate()).toSigned()};c.decodeUTF8Char=function(a,b){var d=a.readUint8(b),c,e,g,k,h,l=b;if(0==(d&128))b+=1;else if(192==(d&224))c=a.readUint8(b+1),d=(d&31)<<6|c&63,b+=2;else if(224==(d&240))c=a.readUint8(b+1),e=a.readUint8(b+2),d=(d&15)<<12|(c&63)<<6|e&63,b+=3;else if(240==(d&248))c=a.readUint8(b+1),e=a.readUint8(b+2),g=a.readUint8(b+3),d=(d&7)<<18|(c& | ||
63)<<12|(e&63)<<6|g&63,b+=4;else if(248==(d&252))c=a.readUint8(b+1),e=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),d=(d&3)<<24|(c&63)<<18|(e&63)<<12|(g&63)<<6|k&63,b+=5;else if(252==(d&254))c=a.readUint8(b+1),e=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),h=a.readUint8(b+5),d=(d&1)<<30|(c&63)<<24|(e&63)<<18|(g&63)<<12|(k&63)<<6|h&63,b+=6;else throw Error("Cannot decode UTF8 character at offset "+b+": charCode (0x"+d.toString(16)+") is invalid");return{"char":d,length:b-l}};c.encodeUTF8Char= | ||
function(a,b,d){var c=d;if(0>a)throw Error("Cannot encode UTF8 character: charCode ("+a+") is negative");if(128>a)b.writeUint8(a&127,d),d+=1;else if(2048>a)b.writeUint8(a>>6&31|192,d).writeUint8(a&63|128,d+1),d+=2;else if(65536>a)b.writeUint8(a>>12&15|224,d).writeUint8(a>>6&63|128,d+1).writeUint8(a&63|128,d+2),d+=3;else if(2097152>a)b.writeUint8(a>>18&7|240,d).writeUint8(a>>12&63|128,d+1).writeUint8(a>>6&63|128,d+2).writeUint8(a&63|128,d+3),d+=4;else if(67108864>a)b.writeUint8(a>>24&3|248,d).writeUint8(a>> | ||
18&63|128,d+1).writeUint8(a>>12&63|128,d+2).writeUint8(a>>6&63|128,d+3).writeUint8(a&63|128,d+4),d+=5;else if(2147483648>a)b.writeUint8(a>>30&1|252,d).writeUint8(a>>24&63|128,d+1).writeUint8(a>>18&63|128,d+2).writeUint8(a>>12&63|128,d+3).writeUint8(a>>6&63|128,d+4).writeUint8(a&63|128,d+5),d+=6;else throw Error("Cannot encode UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)");return d-c};c.calculateUTF8Char=function(a){if(0>a)throw Error("Cannot calculate length of UTF8 character: charCode ("+ | ||
a+") is negative");if(128>a)return 1;if(2048>a)return 2;if(65536>a)return 3;if(2097152>a)return 4;if(67108864>a)return 5;if(2147483648>a)return 6;throw Error("Cannot calculate length of UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)");};c.a=function(a){a=""+a;for(var b=0,d=0;d<a.length;d++)b+=c.calculateUTF8Char(a.charCodeAt(d));return b};c.encode64=function(a){if(!(a&&a instanceof c)||a.length<a.offset)throw Error("Illegal argument: Not a ByteBuffer or offset out of bounds"); | ||
var b,d,f,e,g=a.offset,k=0,h=[];do b=a.readUint8(g++),d=a.length>g?a.readUint8(g++):0,f=a.length>g?a.readUint8(g++):0,e=b<<16|d<<8|f,b=e>>18&63,d=e>>12&63,f=e>>6&63,e&=63,h[k++]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(b)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(d)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(e);while(g<a.length); | ||
g=h.join("");a=(a.length-a.offset)%3;return(a?g.slice(0,a-3):g)+"===".slice(a||3)};c.decode64=function(a){if("string"!==typeof a)throw Error("Illegal argument: Not a string");var b,d,f,e,g,k=0,h=new c(Math.ceil(a.length/3));do{b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++));d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++));e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++)); | ||
g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++));if(0>b||0>d||0>e||0>g)throw Error("Illegal argument: Not a valid base64 encoded string");f=b<<18|d<<12|e<<6|g;b=f>>16&255;d=f>>8&255;f&=255;64==e?h.writeUint8(b):64==g?h.writeUint8(b).writeUint8(d):h.writeUint8(b).writeUint8(d).writeUint8(f)}while(k<a.length);return h.flip()};c.prototype.writeUTF8String=function(a,b){var d="undefined"===typeof b,f=b="undefined"!==typeof b?b:this.offset,e=c.a(a);this.ensureCapacity(b+ | ||
e);for(e=0;e<a.length;e++)b+=c.encodeUTF8Char(a.charCodeAt(e),this,b);return d?(this.offset=b,this):b-f};c.prototype.readUTF8String=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;for(var f,e="",g=b,k=0;k<a;k++)f=c.decodeUTF8Char(this,b),b+=f.length,e+=String.fromCharCode(f["char"]);return d?(this.offset=b,e):{string:e,length:b-g}};c.prototype.readUTF8StringBytes=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f,e="",g=b;for(a= | ||
b+a;b<a;)f=c.decodeUTF8Char(this,b),b+=f.length,e+=String.fromCharCode(f["char"]);if(b!=a)throw Error("Actual string length differs from the specified: "+((b>a?"+":"")+b-a)+" bytes");return d?(this.offset=b,e):{string:e,length:b-g}};c.prototype.writeLString=function(a,b){a=""+a;var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f=c.encodeUTF8Char(a.length,this,b),f=f+this.writeUTF8String(a,b+f);return d?(this.offset+=f,this):f};c.prototype.readLString=function(a){var b="undefined"=== | ||
typeof a;a="undefined"!==typeof a?a:this.offset;var d=c.decodeUTF8Char(this,a);a=this.readUTF8String(d["char"],a+d.length);return b?(this.offset+=d.length+a.length,a.string):{string:a.string,length:d.length+a.length}};c.prototype.writeVString=function(a,b){a=""+a;var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f=this.writeVarint32(c.a(a),b),f=f+this.writeUTF8String(a,b+f);return d?(this.offset+=f,this):f};c.prototype.readVString=function(a){var b="undefined"===typeof a;a="undefined"!== | ||
typeof a?a:this.offset;var d=this.readVarint32(a);a=this.readUTF8StringBytes(d.value,a+d.length);return b?(this.offset+=d.length+a.length,a.string):{string:a.string,length:d.length+a.length}};c.prototype.writeCString=function(a,b){var d="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var c=this.writeUTF8String(""+a,b);this.writeUint8(0,b+c);return d?(this.offset+=c+1,this):c+1};c.prototype.readCString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var d, | ||
f="",e=a;do d=c.decodeUTF8Char(this,a),a+=d.length,0!=d["char"]&&(f+=String.fromCharCode(d["char"]));while(0!=d["char"]);return b?(this.offset=a,f):{string:f,length:a-e}};c.prototype.writeJSON=function(a,b,d){d="function"===typeof d?d:JSON.stringify;return this.writeLString(d(a),b)};c.prototype.readJSON=function(a,b){b="function"===typeof b?b:JSON.parse;var d=this.readLString(a);return"string"===typeof d?b(d):{data:b(d.string),length:d.length}};c.prototype.printDebug=function(a){for(var b=(null!= | ||
this.array?"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")":"ByteBuffer(DESTROYED)")+"\n-------------------------------------------------------------------\n",d=this.toHex(16,!0),c=this.toASCII(16,!0),e=0;e<d.length;e++)b+=d[e]+" "+c[e]+"\n";if(!0===a)return b;"function"===typeof a?a(b):console.log(b)};c.prototype.toHex=function(a,b){if(null==this.array)return"DESTROYED";b=!!b;a="undefined"!==typeof a?parseInt(a,10): | ||
16;1>a&&(a=16);for(var d="",c=[],e=new DataView(this.array),d=0==this.offset&&0==this.length?d+"|":0==this.length?d+">":0==this.offset?d+"<":d+" ",g=0;g<this.array.byteLength;g++){0<g&&0==g%a&&(c.push(d),d=" ");var k=e.getUint8(g),k=k.toString(16).toUpperCase();2>k.length&&(k="0"+k);d+=k;d=g+1==this.offset&&g+1==this.length?d+"|":g+1==this.offset?d+"<":g+1==this.length?d+">":d+" "}if(b)for(;d.length<3*a+1;)d+=" ";c.push(d);return b?c:c.join("\n")};c.prototype.toASCII=function(a,b){if(null==this.array)return""; | ||
b=!!b;a="undefined"!==typeof a?parseInt(a,10):16;1>a&&(a=16);for(var d="",c=[],e=new DataView(this.array),g=0;g<this.array.byteLength;g++){0<g&&0==g%a&&(c.push(d),d="");var k=e.getUint8(g),k=32<k&&127>k?String.fromCharCode(k):".",d=d+k}c.push(d);return b?c:c.join("\n")+"\n"};c.prototype.toBase64=function(){return null==this.array||this.offset>=this.length?"":c.encode64(this)};c.prototype.toUTF8=function(){return null==this.array||this.offset>=this.length?"":this.readUTF8StringBytes(this.length-this.offset, | ||
this.offset).c};c.prototype.toString=function(a){switch(a||"debug"){case "utf8":return this.toUTF8();case "base64":return this.toBase64();default:return null==this.array?"ByteBuffer(DESTROYED)":"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"}};c.prototype.toArrayBuffer=function(a){var b=this.clone();b.offset>b.length&&b.flip();var c=!1;if(0<b.offset||b.length<b.array.byteLength)b.compact(),c=!0;return a&&!c?b.copy().array: | ||
b.array};c.prototype.toBuffer=function(){if(m){var a=this.offset,b=this.length;if(a>b)var c=a,a=b,b=c;c=new Uint8Array(this.array);return new m(c.subarray(a,b))}throw Error("Conversion to Buffer is available under node.js only");};c.extend=function(a,b){if("string"===typeof a&&"function"===typeof b)c.prototype[a]=b;else throw Error("Cannot extend prototype with "+a+"="+b+" (exptected string and function)");};return c}"undefined"!==typeof module&&module.exports?module.exports=q(require("long")):"undefined"!== | ||
(function(n){function q(l){function d(a,b){a="undefined"!==typeof a?parseInt(a,10):d.DEFAULT_CAPACITY;1>a&&(a=d.DEFAULT_CAPACITY);this.array=3==arguments.length&&!0===arguments[2]?null:new ArrayBuffer(a);this.view=null!=this.array?new DataView(this.array):null;this.offset=0;this.markedOffset=-1;this.length=0;this.littleEndian="undefined"!=typeof b?!!b:!1}var m=null;if("function"===typeof require)try{var p=require("buffer"),m=p&&"function"===typeof p.Buffer&&"function"===typeof p.Buffer.isBuffer?p.Buffer: | ||
null}catch(n){}d.DEFAULT_CAPACITY=16;d.LITTLE_ENDIAN=!0;d.BIG_ENDIAN=!1;d.Long=l;d.allocate=function(a,b){return new d(a,b)};d.wrap=function(a,b){if("string"===typeof a)return(new d).writeUTF8String(a).flip();var c;if(m&&m.isBuffer(a)){c=(new Uint8Array(a)).buffer;if(c===a){c=a;for(var f=new ArrayBuffer(c.length),e=new Uint8Array(f),g=0;g<c.length;++g)e[g]=c[g];c=f}a=c}if(null===a||"object"!==typeof a)throw Error("Cannot wrap null or non-object");if(a instanceof d)return a.clone();a.array?a=a.array: | ||
a.buffer&&(a=a.buffer);if(!(a instanceof ArrayBuffer))throw Error("Cannot wrap buffer of type "+typeof a+", "+a.constructor.name);c=new d(0,b,!0);c.array=a;c.view=new DataView(c.array);c.offset=0;c.length=a.byteLength;return c};d.prototype.LE=function(){this.littleEndian=!0;return this};d.prototype.BE=function(){this.littleEndian=!1;return this};d.prototype.resize=function(a){if(1>a)return!1;null==this.array&&(this.array=new ArrayBuffer(a),this.view=new DataView(this.array));if(this.array.byteLength< | ||
a){var b=new Uint8Array(this.array);a=new ArrayBuffer(a);(new Uint8Array(a)).set(b);this.array=a;this.view=new DataView(a);return!0}return!1};d.prototype.slice=function(a,b){if(null==this.array)throw Error(this+" cannot be sliced: Already destroyed");if(b<=a)throw Error(this+" cannot be sliced: End ("+b+") is less than begin ("+a+")");if(0>a||a>this.array.byteLength||1>b||b>this.array.byteLength)throw Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+a+"-"+b+")"); | ||
var c=this.clone();c.offset=a;c.length=b;return c};d.prototype.sliceAndCompact=function(a,b){return d.wrap(this.slice(a,b).toArrayBuffer(!0))};d.prototype.ensureCapacity=function(a){return null==this.array?this.resize(a):this.array.byteLength<a?this.resize(2*this.array.byteLength>=a?2*this.array.byteLength:a):!1};d.prototype.flip=function(){this.length=null==this.array?0:this.offset;this.offset=0;return this};d.prototype.mark=function(a){if(null==this.array)throw Error(this+" cannot be marked: Already destroyed"); | ||
a="undefined"!==typeof a?parseInt(a,10):this.offset;if(0>a||a>this.array.byteLength)throw Error(this+" cannot be marked: Offset to mark is less than 0 or bigger than the capacity ("+this.array.byteLength+"): "+a);this.markedOffset=a;return this};d.prototype.reset=function(){0<=this.markedOffset?(this.offset=this.markedOffset,this.markedOffset=-1):this.length=this.offset=0;return this};d.prototype.clone=function(){var a=new d(-1,this.littleEndian,!0);a.array=this.array;a.view=this.view;a.offset=this.offset; | ||
a.length=this.length;return a};d.prototype.copy=function(){if(null==this.array)return this.clone();var a=new d(this.array.byteLength,this.littleEndian),b=new Uint8Array(this.array);(new Uint8Array(a.array)).set(b);a.offset=this.offset;a.length=this.length;return a};d.prototype.remaining=function(){return null==this.array?0:this.length-this.offset};d.prototype.capacity=function(){return null!=this.array?this.array.byteLength:0};d.prototype.compact=function(){if(null==this.array)throw Error(this+" cannot be compacted: Already destroyed"); | ||
this.offset>this.length&&this.flip();if(this.offset==this.length)throw Error(this+" cannot be compacted: Offset ("+this.offset+") is equal to its length ("+this.length+")");if(0==this.offset&&this.length==this.array.byteLength)return this;var a=new Uint8Array(this.array),b=new ArrayBuffer(this.length-this.offset);(new Uint8Array(b)).set(a.subarray(this.offset,this.length));this.array=b;this.offset=0;this.length=this.array.byteLength;return this};d.prototype.destroy=function(){if(null!=this.array)return this.view= | ||
this.array=null,this.length=this.offset=0,this};d.prototype.reverse=function(){if(null==this.array)throw Error(this+" cannot be reversed: Already destroyed");Array.prototype.reverse.call(new Uint8Array(this.array));var a=this.offset;this.offset=this.array.byteLength-this.length;this.length=this.array.byteLength-a;return this};d.prototype.append=function(a,b){a instanceof d||(a=d.wrap(a));if(null==a.array)throw Error(a+" cannot be appended to "+this+": Already destroyed");var c=a.length-a.offset;if(0== | ||
c)return this;0>c&&(a=a.clone().flip(),c=a.length-a.offset);b="undefined"!==typeof b?b:(this.offset+=c)-c;this.ensureCapacity(b+c);c=new Uint8Array(a.array);(new Uint8Array(this.array)).set(c.subarray(a.offset,a.length),b);return this};d.prototype.prepend=function(a,b){a instanceof d||(a=d.wrap(a));if(null==a.array)throw a+" cannot be prepended to "+this+": Already destroyed";var c=a.length-a.offset;if(0==c)return this;0>c&&(a=a.clone().flip(),c=a.length-a.offset);var f="undefined"===typeof b;b="undefined"!== | ||
typeof b?b:this.offset;var e=c-b;0<e?(this.ensureCapacity(this.length+e),this.append(this,c),this.offset+=e,this.length+=e,this.append(a,0)):this.append(a,b-c);f&&(this.offset-=c);return this};d.prototype.writeInt8=function(a,b){b="undefined"!=typeof b?b:(this.offset+=1)-1;this.ensureCapacity(b+1);this.view.setInt8(b,a);return this};d.prototype.readInt8=function(a){a="undefined"!==typeof a?a:(this.offset+=1)-1;if(a>=this.array.byteLength)throw Error("Cannot read int8 from "+this+" at "+a+": Capacity overflow"); | ||
return this.view.getInt8(a)};d.prototype.writeByte=d.prototype.writeInt8;d.prototype.readByte=d.prototype.readInt8;d.prototype.writeUint8=function(a,b){b="undefined"!=typeof b?b:(this.offset+=1)-1;this.ensureCapacity(b+1);this.view.setUint8(b,a);return this};d.prototype.readUint8=function(a){a="undefined"!==typeof a?a:(this.offset+=1)-1;if(a+1>this.array.byteLength)throw Error("Cannot read uint8 from "+this+" at "+a+": Capacity overflow");return this.view.getUint8(a)};d.prototype.writeInt16=function(a, | ||
b){b="undefined"!==typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setInt16(b,a,this.littleEndian);return this};d.prototype.readInt16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.byteLength)throw Error("Cannot read int16 from "+this+" at "+a+": Capacity overflow");return this.view.getInt16(a,this.littleEndian)};d.prototype.writeShort=d.prototype.writeInt16;d.prototype.readShort=d.prototype.readInt16;d.prototype.writeUint16=function(a,b){b="undefined"!== | ||
typeof b?b:(this.offset+=2)-2;this.ensureCapacity(b+2);this.view.setUint16(b,a,this.littleEndian);return this};d.prototype.readUint16=function(a){a="undefined"!==typeof a?a:(this.offset+=2)-2;if(a+2>this.array.b)throw Error("Cannot read int16 from "+this+" at "+a+": Capacity overflow");return this.view.getUint16(a,this.littleEndian)};d.prototype.writeInt32=function(a,b){b="undefined"!==typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setInt32(b,a,this.littleEndian);return this};d.prototype.readInt32= | ||
function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read int32 from "+this+" at "+a+": Capacity overflow");return this.view.getInt32(a,this.littleEndian)};d.prototype.writeInt=d.prototype.writeInt32;d.prototype.readInt=d.prototype.readInt32;d.prototype.writeUint32=function(a,b){b="undefined"!=typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setUint32(b,a,this.littleEndian);return this};d.prototype.readUint32=function(a){a="undefined"!== | ||
typeof a?a:(this.offset+=4)-4;if(a+4>this.array.byteLength)throw Error("Cannot read uint32 from "+this+" at "+a+": Capacity overflow");return this.view.getUint32(a,this.littleEndian)};d.prototype.writeFloat32=function(a,b){b="undefined"!==typeof b?b:(this.offset+=4)-4;this.ensureCapacity(b+4);this.view.setFloat32(b,a,this.littleEndian);return this};d.prototype.readFloat32=function(a){a="undefined"!==typeof a?a:(this.offset+=4)-4;if(null==this.array||a+4>this.array.byteLength)throw Error("Cannot read float32 from "+ | ||
this+" at "+a+": Capacity overflow");return this.view.getFloat32(a,this.littleEndian)};d.prototype.writeFloat=d.prototype.writeFloat32;d.prototype.readFloat=d.prototype.readFloat32;d.prototype.writeFloat64=function(a,b){b="undefined"!==typeof b?b:(this.offset+=8)-8;this.ensureCapacity(b+8);this.view.setFloat64(b,a,this.littleEndian);return this};d.prototype.readFloat64=function(a){a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null==this.array||a+8>this.array.byteLength)throw Error("Cannot read float64 from "+ | ||
this+" at "+a+": Capacity overflow");return this.view.getFloat64(a,this.littleEndian)};d.prototype.writeDouble=d.prototype.writeFloat64;d.prototype.readDouble=d.prototype.readFloat64;d.prototype.writeInt64=function(a,b){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));this.ensureCapacity(b+8);this.littleEndian?(this.view.setInt32(b, | ||
a.getLowBits(),!0),this.view.setInt32(b+4,a.getHighBits(),!0)):(this.view.setInt32(b,a.getHighBits(),!1),this.view.setInt32(b+4,a.getLowBits(),!1));return this};d.prototype.readInt64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null==this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+this+" at "+a+": Capacity overflow"); | ||
return this.littleEndian?l.fromBits(this.view.getInt32(a,!0),this.view.getInt32(a+4,!0),!1):l.fromBits(this.view.getInt32(a+4,!1),this.view.getInt32(a,!1),!1)};d.prototype.writeUint64=function(a,b){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");b="undefined"!==typeof b?b:(this.offset+=8)-8;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!0));this.ensureCapacity(b+8);this.littleEndian?(this.view.setUint32(b, | ||
a.getLowBitsUnsigned(),!0),this.view.setUint32(b+4,a.getHighBitsUnsigned(),!0)):(this.view.setUint32(b,a.getHighBitsUnsigned(),!1),this.view.setUint32(b+4,a.getLowBitsUnsigned(),!1));return this};d.prototype.readUint64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");a="undefined"!==typeof a?a:(this.offset+=8)-8;if(null==this.array||a+8>this.array.byteLength)throw this.offset-=8,Error("Cannot read int64 from "+ | ||
this+" at "+a+": Capacity overflow");return this.littleEndian?l.fromBits(this.view.getUint32(a,!0),this.view.getUint32(a+4,!0),!0):l.fromBits(this.view.getUint32(a+4,!1),this.view.getUint32(a,!1),!0)};d.prototype.writeLong=d.prototype.writeInt64;d.prototype.readLong=d.prototype.readInt64;d.MAX_VARINT32_BYTES=5;d.prototype.writeVarint32=function(a,b){var c="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;a>>>=0;this.ensureCapacity(b+d.calculateVarint32(a));var f=this.view,e=0;f.setUint8(b, | ||
a|128);128<=a?(f.setUint8(b+1,a>>7|128),16384<=a?(f.setUint8(b+2,a>>14|128),2097152<=a?(f.setUint8(b+3,a>>21|128),268435456<=a?(f.setUint8(b+4,a>>28&127),e=5):(f.setUint8(b+3,f.getUint8(b+3)&127),e=4)):(f.setUint8(b+2,f.getUint8(b+2)&127),e=3)):(f.setUint8(b+1,f.getUint8(b+1)&127),e=2)):(f.setUint8(b,f.getUint8(b)&127),e=1);return c?(this.offset+=e,this):e};d.prototype.readVarint32=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var c=0,f,e=0;do f=this.view.getUint8(a+ | ||
c),c<d.MAX_VARINT32_BYTES&&(e|=(f&127)<<7*c>>>0),++c;while(f&128);e|=0;return b?(this.offset+=c,e):{value:e,length:c}};d.prototype.writeZigZagVarint32=function(a,b){return this.writeVarint32(d.zigZagEncode32(a),b)};d.prototype.readZigZagVarint32=function(a){a=this.readVarint32(a);return"object"===typeof a?(a.value=d.zigZagDecode32(a.value),a):d.zigZagDecode32(a)};d.MAX_VARINT64_BYTES=10;d.prototype.writeVarint64=function(a,b){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details"); | ||
var c="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));var f=a.toInt()>>>0,e=a.shiftRightUnsigned(28).toInt()>>>0,g=a.shiftRightUnsigned(56).toInt()>>>0,k=d.calculateVarint64(a);this.ensureCapacity(b+k);var h=this.view;switch(k){case 10:h.setUint8(b+9,g>>>7|128);case 9:h.setUint8(b+8,g|128);case 8:h.setUint8(b+7,e>>>21|128);case 7:h.setUint8(b+6,e>>>14|128);case 6:h.setUint8(b+5,e>>>7|128);case 5:h.setUint8(b+4,e|128);case 4:h.setUint8(b+ | ||
3,f>>>21|128);case 3:h.setUint8(b+2,f>>>14|128);case 2:h.setUint8(b+1,f>>>7|128);case 1:h.setUint8(b+0,f|128)}h.setUint8(b+k-1,h.getUint8(b+k-1)&127);return c?(this.offset+=k,this):k};d.prototype.readVarint64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");var b="undefined"===typeof a,c=a="undefined"!==typeof a?a:this.offset,d=this.view,e,g=0,k=0,h;h=d.getUint8(a++);e=h&127;if(h&128&&(h=d.getUint8(a++), | ||
e|=(h&127)<<7,h&128&&(h=d.getUint8(a++),e|=(h&127)<<14,h&128&&(h=d.getUint8(a++),e|=(h&127)<<21,h&128&&(h=d.getUint8(a++),g=h&127,h&128&&(h=d.getUint8(a++),g|=(h&127)<<7,h&128&&(h=d.getUint8(a++),g|=(h&127)<<14,h&128&&(h=d.getUint8(a++),g|=(h&127)<<21,h&128&&(h=d.getUint8(a++),k=h&127,h&128&&(h=d.getUint8(a++),k|=(h&127)<<7,h&128))))))))))throw Error("Data must be corrupt: Buffer overrun");d=l.from28Bits(e,g,k,!1);return b?(this.offset=a,d):{value:d,length:a-c}};d.prototype.writeZigZagVarint64=function(a, | ||
b){return this.writeVarint64(d.zigZagEncode64(a),b)};d.prototype.readZigZagVarint64=function(a){a=this.readVarint64(a);return"object"!==typeof a||a instanceof l?d.zigZagDecode64(a):(a.value=d.zigZagDecode64(a.value),a)};d.prototype.writeVarint=d.prototype.writeVarint32;d.prototype.readVarint=d.prototype.readVarint32;d.prototype.writeZigZagVarint=d.prototype.writeZigZagVarint32;d.prototype.readZigZagVarint=d.prototype.readZigZagVarint32;d.calculateVarint32=function(a){a>>>=0;return 128>a?1:16384>a? | ||
2:2097152>a?3:268435456>a?4:5};d.calculateVarint64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");"object"===typeof a&&a instanceof l||(a=l.fromNumber(a,!1));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};d.zigZagEncode32=function(a){return((a|=0)<<1^a>>31)>>>0}; | ||
d.zigZagDecode32=function(a){return a>>>1^-(a&1)|0};d.zigZagEncode64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details");"object"===typeof a&&a instanceof l?a.unsigned&&(a=a.toSigned()):a=l.fromNumber(a,!1);return a.shiftLeft(1).xor(a.shiftRight(63)).toUnsigned()};d.zigZagDecode64=function(a){if(!l)throw Error("Long support is not available: See https://github.com/dcodeIO/ByteBuffer.js#on-long-int64-support for details"); | ||
"object"===typeof a&&a instanceof l?a.unsigned||(a=a.toUnsigned()):a=l.fromNumber(a,!0);return a.shiftRightUnsigned(1).xor(a.and(l.ONE).toSigned().negate()).toSigned()};d.decodeUTF8Char=function(a,b){var c=a.readUint8(b),d,e,g,k,h,l=b;if(0==(c&128))b+=1;else if(192==(c&224))d=a.readUint8(b+1),c=(c&31)<<6|d&63,b+=2;else if(224==(c&240))d=a.readUint8(b+1),e=a.readUint8(b+2),c=(c&15)<<12|(d&63)<<6|e&63,b+=3;else if(240==(c&248))d=a.readUint8(b+1),e=a.readUint8(b+2),g=a.readUint8(b+3),c=(c&7)<<18|(d& | ||
63)<<12|(e&63)<<6|g&63,b+=4;else if(248==(c&252))d=a.readUint8(b+1),e=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),c=(c&3)<<24|(d&63)<<18|(e&63)<<12|(g&63)<<6|k&63,b+=5;else if(252==(c&254))d=a.readUint8(b+1),e=a.readUint8(b+2),g=a.readUint8(b+3),k=a.readUint8(b+4),h=a.readUint8(b+5),c=(c&1)<<30|(d&63)<<24|(e&63)<<18|(g&63)<<12|(k&63)<<6|h&63,b+=6;else throw Error("Cannot decode UTF8 character at offset "+b+": charCode (0x"+c.toString(16)+") is invalid");return{"char":c,length:b-l}};d.encodeUTF8Char= | ||
function(a,b,c){var d=c;if(0>a)throw Error("Cannot encode UTF8 character: charCode ("+a+") is negative");if(128>a)b.writeUint8(a&127,c),c+=1;else if(2048>a)b.writeUint8(a>>6&31|192,c).writeUint8(a&63|128,c+1),c+=2;else if(65536>a)b.writeUint8(a>>12&15|224,c).writeUint8(a>>6&63|128,c+1).writeUint8(a&63|128,c+2),c+=3;else if(2097152>a)b.writeUint8(a>>18&7|240,c).writeUint8(a>>12&63|128,c+1).writeUint8(a>>6&63|128,c+2).writeUint8(a&63|128,c+3),c+=4;else if(67108864>a)b.writeUint8(a>>24&3|248,c).writeUint8(a>> | ||
18&63|128,c+1).writeUint8(a>>12&63|128,c+2).writeUint8(a>>6&63|128,c+3).writeUint8(a&63|128,c+4),c+=5;else if(2147483648>a)b.writeUint8(a>>30&1|252,c).writeUint8(a>>24&63|128,c+1).writeUint8(a>>18&63|128,c+2).writeUint8(a>>12&63|128,c+3).writeUint8(a>>6&63|128,c+4).writeUint8(a&63|128,c+5),c+=6;else throw Error("Cannot encode UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)");return c-d};d.calculateUTF8Char=function(a){if(0>a)throw Error("Cannot calculate length of UTF8 character: charCode ("+ | ||
a+") is negative");if(128>a)return 1;if(2048>a)return 2;if(65536>a)return 3;if(2097152>a)return 4;if(67108864>a)return 5;if(2147483648>a)return 6;throw Error("Cannot calculate length of UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)");};d.a=function(a){a=""+a;for(var b=0,c=0;c<a.length;c++)b+=d.calculateUTF8Char(a.charCodeAt(c));return b};d.encode64=function(a){if(!(a&&a instanceof d)||a.length<a.offset)throw Error("Illegal argument: Not a ByteBuffer or offset out of bounds"); | ||
var b,c,f,e,g=a.offset,k=0,h=[];do b=a.readUint8(g++),c=a.length>g?a.readUint8(g++):0,f=a.length>g?a.readUint8(g++):0,e=b<<16|c<<8|f,b=e>>18&63,c=e>>12&63,f=e>>6&63,e&=63,h[k++]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(b)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(c)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(f)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(e);while(g<a.length); | ||
g=h.join("");a=(a.length-a.offset)%3;return(a?g.slice(0,a-3):g)+"===".slice(a||3)};d.decode64=function(a){if("string"!==typeof a)throw Error("Illegal argument: Not a string");var b,c,f,e,g,k=0,h=new d(Math.ceil(a.length/3));do{b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++));c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++));e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++)); | ||
g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(k++));if(0>b||0>c||0>e||0>g)throw Error("Illegal argument: Not a valid base64 encoded string");f=b<<18|c<<12|e<<6|g;b=f>>16&255;c=f>>8&255;f&=255;64==e?h.writeUint8(b):64==g?h.writeUint8(b).writeUint8(c):h.writeUint8(b).writeUint8(c).writeUint8(f)}while(k<a.length);return h.flip()};d.prototype.writeUTF8String=function(a,b){var c="undefined"===typeof b,f=b="undefined"!==typeof b?b:this.offset,e=d.a(a);this.ensureCapacity(b+ | ||
e);for(e=0;e<a.length;e++)b+=d.encodeUTF8Char(a.charCodeAt(e),this,b);return c?(this.offset=b,this):b-f};d.prototype.readUTF8String=function(a,b){var c="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;for(var f,e="",g=b,k=0;k<a;k++)f=d.decodeUTF8Char(this,b),b+=f.length,e+=String.fromCharCode(f["char"]);return c?(this.offset=b,e):{string:e,length:b-g}};d.prototype.readUTF8StringBytes=function(a,b){var c="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f,e="",g=b;for(a= | ||
b+a;b<a;)f=d.decodeUTF8Char(this,b),b+=f.length,e+=String.fromCharCode(f["char"]);if(b!=a)throw Error("Actual string length differs from the specified: "+((b>a?"+":"")+b-a)+" bytes");return c?(this.offset=b,e):{string:e,length:b-g}};d.prototype.writeLString=function(a,b){a=""+a;var c="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f=d.encodeUTF8Char(a.length,this,b),f=f+this.writeUTF8String(a,b+f);return c?(this.offset+=f,this):f};d.prototype.readLString=function(a){var b="undefined"=== | ||
typeof a;a="undefined"!==typeof a?a:this.offset;var c=d.decodeUTF8Char(this,a);a=this.readUTF8String(c["char"],a+c.length);return b?(this.offset+=c.length+a.length,a.string):{string:a.string,length:c.length+a.length}};d.prototype.writeVString=function(a,b){a=""+a;var c="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var f=this.writeVarint32(d.a(a),b),f=f+this.writeUTF8String(a,b+f);return c?(this.offset+=f,this):f};d.prototype.readVString=function(a){var b="undefined"===typeof a;a="undefined"!== | ||
typeof a?a:this.offset;var c=this.readVarint32(a);a=this.readUTF8StringBytes(c.value,a+c.length);return b?(this.offset+=c.length+a.length,a.string):{string:a.string,length:c.length+a.length}};d.prototype.writeCString=function(a,b){var c="undefined"===typeof b;b="undefined"!==typeof b?b:this.offset;var d=this.writeUTF8String(""+a,b);this.writeUint8(0,b+d);return c?(this.offset+=d+1,this):d+1};d.prototype.readCString=function(a){var b="undefined"===typeof a;a="undefined"!==typeof a?a:this.offset;var c, | ||
f="",e=a;do c=d.decodeUTF8Char(this,a),a+=c.length,0!=c["char"]&&(f+=String.fromCharCode(c["char"]));while(0!=c["char"]);return b?(this.offset=a,f):{string:f,length:a-e}};d.prototype.writeJSON=function(a,b,c){c="function"===typeof c?c:JSON.stringify;return this.writeLString(c(a),b)};d.prototype.readJSON=function(a,b){b="function"===typeof b?b:JSON.parse;var c=this.readLString(a);return"string"===typeof c?b(c):{data:b(c.string),length:c.length}};d.prototype.printDebug=function(a){for(var b=(null!= | ||
this.array?"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")":"ByteBuffer(DESTROYED)")+"\n-------------------------------------------------------------------\n",c=this.toHex(16,!0),d=this.toASCII(16,!0),e=0;e<c.length;e++)b+=c[e]+" "+d[e]+"\n";if(!0===a)return b;"function"===typeof a?a(b):console.log(b)};d.prototype.toHex=function(a,b){if(null==this.array)return"DESTROYED";b=!!b;a="undefined"!==typeof a?parseInt(a,10): | ||
16;1>a&&(a=16);for(var c="",d=[],e=this.view,c=0==this.offset&&0==this.length?c+"|":0==this.length?c+">":0==this.offset?c+"<":c+" ",g=0;g<this.array.byteLength;g++){0<g&&0==g%a&&(d.push(c),c=" ");var k=e.getUint8(g),k=k.toString(16).toUpperCase();2>k.length&&(k="0"+k);c+=k;c=g+1==this.offset&&g+1==this.length?c+"|":g+1==this.offset?c+"<":g+1==this.length?c+">":c+" "}if(b)for(;c.length<3*a+1;)c+=" ";d.push(c);return b?d:d.join("\n")};d.prototype.toASCII=function(a,b){if(null==this.array)return""; | ||
b=!!b;a="undefined"!==typeof a?parseInt(a,10):16;1>a&&(a=16);for(var c="",d=[],e=0;e<this.array.byteLength;e++){0<e&&0==e%a&&(d.push(c),c="");var g=this.view.getUint8(e),g=32<g&&127>g?String.fromCharCode(g):".",c=c+g}d.push(c);return b?d:d.join("\n")+"\n"};d.prototype.toBase64=function(){return null==this.array||this.offset>=this.length?"":d.encode64(this)};d.prototype.toUTF8=function(){return null==this.array||this.offset>=this.length?"":this.readUTF8StringBytes(this.length-this.offset,this.offset).c}; | ||
d.prototype.toString=function(a){switch(a||"debug"){case "utf8":return this.toUTF8();case "base64":return this.toBase64();default:return null==this.array?"ByteBuffer(DESTROYED)":"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"}};d.prototype.toArrayBuffer=function(a){var b=this.clone();b.offset>b.length&&b.flip();var c=!1;if(0<b.offset||b.length<b.array.byteLength)b.compact(),c=!0;return a&&!c?b.copy().array:b.array}; | ||
d.prototype.toBuffer=function(){if(m){var a=this.offset,b=this.length;if(a>b)var c=a,a=b,b=c;c=new Uint8Array(this.array);return new m(c.subarray(a,b))}throw Error("Conversion to Buffer is available under node.js only");};d.extend=function(a,b){if("string"===typeof a&&"function"===typeof b)d.prototype[a]=b;else throw Error("Cannot extend prototype with "+a+"="+b+" (exptected string and function)");};return d}"undefined"!==typeof module&&module.exports?module.exports=q(require("long")):"undefined"!== | ||
typeof define&&define.amd?define("ByteBuffer",["Math/Long"],function(l){return q(l)}):(n.dcodeIO||(n.dcodeIO={}),n.dcodeIO.ByteBuffer=q(dcodeIO.Long))})(this); |
{ | ||
"name": "bytebuffer", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
@@ -5,0 +5,0 @@ "description": "ByteBuffer.js: A Java-like, Netty-inspired ByteBuffer implementation using typed arrays.", |
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 too big to display
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
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
8322
728489