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

bytebuffer

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bytebuffer - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

externs/Long.js

70

ByteBuffer.min.js

@@ -6,35 +6,37 @@ /*

*/
function g(n){throw n;}var k=!0,m=null,p=!1;
(function(n){function b(a,c){a="undefined"!=typeof a?parseInt(a,10):b.DEFAULT_CAPACITY;1>a&&(a=b.DEFAULT_CAPACITY);this.array=3==arguments.length&&arguments[2]===k?m:new ArrayBuffer(a);this.view=this.array!=m?new DataView(this.array):m;this.offset=0;this.markedOffset=-1;this.length=0;this.littleEndian="undefined"!=typeof c?!!c:p}b.DEFAULT_CAPACITY=16;b.LITTLE_ENDIAN=k;b.BIG_ENDIAN=p;b.INT8=new Int8Array(1);b.UINT8=new Uint8Array(1);b.INT16=new Int16Array(1);b.UINT16=new Uint16Array(1);b.INT32=new Int32Array(1);
b.UINT32=new Uint32Array(1);b.FLOAT32=new Float32Array(1);b.FLOAT64=new Float64Array(1);b.cast=function(a,c){a[0]=c;return a[0]};b.allocate=function(a,c){return new b(a,c)};b.wrap=function(a,c){if("string"==typeof a)return(new b).writeUTF8String(a).flip();a.array?a=a.array:a.buffer&&(a=a.buffer);a instanceof ArrayBuffer||g(Error("Cannot wrap buffer of type "+typeof a));var d=new b(0,c,k);d.array=a;d.view=new DataView(d.array);d.offset=0;d.length=a.byteLength;return d};b.prototype.LE=function(){this.littleEndian=
k;return this};b.prototype.BE=function(){this.littleEndian=p;return this};b.prototype.resize=function(a){if(1>a)return p;this.array==m&&(this.array=new ArrayBuffer(a),this.view=new DataView(this.array));if(this.array.byteLength<a){var c=new Uint8Array(this.array);a=new ArrayBuffer(a);(new Uint8Array(a)).set(c);this.array=a;this.view=new DataView(a);return k}return p};b.prototype.slice=function(a,c){this.array==m&&g(Error(this+" cannot be sliced: Already destroyed"));c<=a&&g(Error(this+" cannot be sliced: End ("+
c+") is less than begin ("+a+")"));(0>a||a>this.array.byteLength||1>c||c>this.array.byteLength)&&g(Error(this+" cannot be sliced: Index out of bounds (0-"+this.array.byteLength+" -> "+a+"-"+c+")"));var d=this.clone();d.offset=a;d.length=c;return d};b.prototype.sliceAndCompact=function(a,c){return b.wrap(this.slice(a,c).toArrayBuffer(k))};b.prototype.ensureCapacity=function(a){return this.array==m?this.resize(a):this.array.byteLength<a?this.resize(2*this.array.byteLength>=a?2*this.array.byteLength:
a):p};b.prototype.flip=function(){this.length=this.array==m?0:this.offset;this.offset=0;return this};b.prototype.mark=function(a){this.array==m&&g(Error(this+" cannot be marked: Already destroyed"));a="undefined"!=typeof a?parseInt(a,10):this.offset;(0>a||a>this.array.byteLength)&&g(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};b.prototype.reset=function(){0<=this.markedOffset?(this.offset=
this.markedOffset,this.markedOffset=-1):this.length=this.offset=0;return this};b.prototype.clone=function(){var a=new b(-1,this.littleEndian,k);a.array=this.array;a.view=this.view;a.offset=this.offset;a.length=this.length;return a};b.prototype.copy=function(){if(this.array==m)return this.clone();var a=new b(this.array.byteLength,this.littleEndian),c=new Uint8Array(this.array);(new Uint8Array(a.array)).set(c);a.offset=this.offset;a.length=this.length;return a};b.prototype.remaining=function(){return this.array==
m?0:this.length-this.offset};b.prototype.capacity=function(){return this.array!=m?this.array.byteLength:0};b.prototype.compact=function(){this.array==m&&g(Error(this+" cannot be compacted: Already destroyed"));this.offset>this.length&&this.flip();this.offset==this.length&&g(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),c=new ArrayBuffer(this.length-
this.offset);(new Uint8Array(c)).set(a.subarray(this.offset,this.length));this.array=c;this.offset=0;this.length=this.array.byteLength;return this};b.prototype.destroy=function(){if(this.array!=m)return this.view=this.array=m,this.length=this.offset=0,this};b.prototype.reverse=function(){this.array==m&&g(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};b.prototype.append=function(a,c){a instanceof b||(a=b.wrap(a));a.array==m&&g(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);c="undefined"!=typeof c?c:(this.offset+=d)-d;this.ensureCapacity(c+d);d=new Uint8Array(a.array);(new Uint8Array(this.array)).set(d.subarray(a.offset,a.length),c);return this};b.prototype.prepend=function(a,c){a instanceof b||(a=b.wrap(a));a.array==m&&g(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 e="undefined"==typeof c;c="undefined"!=typeof c?c:this.offset;var f=d-c;0<f?(this.ensureCapacity(this.length+f),this.append(this,d),this.offset+=f,this.length+=f,this.append(a,0)):this.append(a,c-d);e&&(this.offset-=d);return this};b.prototype.writeInt8=function(a,c){c="undefined"!=typeof c?c:(this.offset+=1)-1;this.ensureCapacity(c+1);this.view.setInt8(c,a);return this};b.prototype.readInt8=
function(a){a="undefined"!=typeof a?a:(this.offset+=1)-1;a>=this.array.byteLength&&g(Error("Cannot read int8 from "+this+": Capacity overflow"));return this.view.getInt8(a)};b.prototype.writeByte=b.prototype.writeInt8;b.prototype.readByte=b.prototype.readInt8;b.prototype.writeUint8=function(a,c){c="undefined"!=typeof c?c:(this.offset+=1)-1;this.ensureCapacity(c+1);this.view.setUint8(c,a);return this};b.prototype.readUint8=function(a){a="undefined"!=typeof a?a:(this.offset+=1)-1;a>=this.array.byteLength&&
g("Cannot read uint8 from "+this+": Capacity overflow");return this.view.getUint8(a)};b.prototype.writeInt16=function(a,c){c="undefined"!=typeof c?c:(this.offset+=2)-2;this.ensureCapacity(c+2);this.view.setInt16(c,a,this.littleEndian);return this};b.prototype.readInt16=function(a){a="undefined"!=typeof a?a:(this.offset+=2)-2;a+2>this.array.byteLength&&g(Error("Cannot read int16 from "+this+": Capacity overflow"));return this.view.getInt16(a,this.littleEndian)};b.prototype.writeShort=b.prototype.writeInt16;
b.prototype.readShort=b.prototype.readInt16;b.prototype.writeUint16=function(a,c){c="undefined"!=typeof c?c:(this.offset+=2)-2;this.ensureCapacity(c+2);this.view.setUint16(c,a,this.littleEndian);return this};b.prototype.readUint16=function(a){a="undefined"!=typeof a?a:(this.offset+=2)-2;a+2>this.array.c&&g(Error("Cannot read int16 from "+this+": Capacity overflow"));return this.view.getUint16(a,this.littleEndian)};b.prototype.writeInt32=function(a,c){c="undefined"!=typeof c?c:(this.offset+=4)-4;this.ensureCapacity(c+
4);this.view.setInt32(c,a,this.littleEndian);return this};b.prototype.readInt32=function(a){a="undefined"!=typeof a?a:(this.offset+=4)-4;a+4>this.array.byteLength&&g(Error("Cannot read int32 from "+this+": Capacity overflow"));return this.view.getInt32(a,this.littleEndian)};b.prototype.writeInt=b.prototype.writeInt32;b.prototype.readInt=b.prototype.readInt32;b.prototype.writeUint32=function(a,c){c="undefined"!=typeof c?c:(this.offset+=4)-4;this.ensureCapacity(c+4);this.view.setUint32(c,a,this.littleEndian);
return this};b.prototype.readUint32=function(a){a="undefined"!=typeof a?a:(this.offset+=4)-4;a+4>this.array.byteLength&&g(Error("Cannot read uint32 from "+this+": Capacity overflow"));return this.view.getUint32(a,this.littleEndian)};b.prototype.writeFloat32=function(a,c){c="undefined"!=typeof c?c:(this.offset+=4)-4;this.ensureCapacity(c+4);this.view.setFloat32(c,a,this.littleEndian);return this};b.prototype.readFloat32=function(a){a="undefined"!=typeof a?a:(this.offset+=4)-4;(this.array==m||a+4>this.array.byteLength)&&
g(Error("Cannot read float32 from "+this+": Capacity overflow"));return this.view.getFloat32(a,this.littleEndian)};b.prototype.writeFloat=b.prototype.writeFloat32;b.prototype.readFloat=b.prototype.readFloat32;b.prototype.writeFloat64=function(a,c){c="undefined"!=typeof c?c:(this.offset+=8)-8;this.ensureCapacity(c+8);this.view.setFloat64(c,a,this.littleEndian);return this};b.prototype.readFloat64=function(a){a="undefined"!=typeof a?a:(this.offset+=8)-8;(this.array==m||a+8>this.array.byteLength)&&g(Error("Cannot read float64 from "+
this+": Capacity overflow"));return this.view.getFloat64(a,this.littleEndian)};b.prototype.writeDouble=b.prototype.writeFloat64;b.prototype.readDouble=b.prototype.readFloat64;b.prototype.writeLong=b.prototype.writeFloat64;b.prototype.readLong=function(a){return Math.round(this.readFloat64(a))};b.a=5;b.prototype.writeVarint32=function(a,c){var d="undefined"==typeof c;c="undefined"!=typeof c?c:this.offset;b.UINT32[0]=a;this.ensureCapacity(c+b.calculateVarint32(a=b.UINT32[0]));var e=new Uint8Array(this.array),
f=0;e[c]=a|128;128<=a?(e[c+1]=a>>7|128,16384<=a?(e[c+2]=a>>14|128,2097152<=a?(e[c+3]=a>>21|128,268435456<=a?(e[c+4]=a>>28&127,f=5):(e[c+3]&=127,f=4)):(e[c+2]&=127,f=3)):(e[c+1]&=127,f=2)):(e[c]&=127,f=1);return d?(this.offset+=f,this):f};b.prototype.readVarint32=function(a){var c="undefined"==typeof a;a="undefined"!=typeof a?a:this.offset;var d=new Uint8Array(this.array),e=0,f;b.UINT32[0]=0;do e==b.a&&g(Error("Cannot read Varint32 from "+this+"@"+a+": Number of bytes is larger than "+b.a)),f=d[a+
e],b.UINT32[0]|=(f&127)<<7*e,++e;while(f&128);b.INT32[0]=b.UINT32[0];return c?(this.offset+=e,b.INT32[0]):{value:b.INT32[0],length:e}};b.prototype.writeZigZagVarint32=function(a,c){return this.writeVarint32(b.zigZagEncode32(a),c)};b.prototype.readZigZagVarint32=function(a){a=this.readVarint32(a);return"object"==typeof a?(a.value=b.zigZagDecode32(a.value),a):b.zigZagDecode32(a)};b.prototype.writeVarint=b.prototype.writeVarint32;b.prototype.readVarint=b.prototype.readVarint32;b.calculateVarint32=function(a){b.UINT32[0]=
a;return 128>b.UINT32[0]?1:16384>b.UINT32[0]?2:2097152>b.UINT32[0]?3:268435456>b.UINT32[0]?4:5};b.zigZagEncode32=function(a){b.INT32[0]=a;return 0<=(a=b.INT32[0])?2*a:2*-a-1};b.zigZagDecode32=function(a){b.UINT32[0]=a;return 0==((a=b.UINT32[0])&1)?a/2:-(a+1)/2};b.decodeUTF8Char=function(a,c){var d=a.readUint8(c),b,f,h,l,n,q=c;0==(d&128)?(b=d,c+=1):192==(d&224)?(b=a.readUint8(c+1),b=(d&31)<<6|b&63,c+=2):224==(d&240)?(b=a.readUint8(c+1),f=a.readUint8(c+2),b=(d&15)<<12|(b&63)<<6|f&63,c+=3):240==(d&248)?
(b=a.readUint8(c+1),f=a.readUint8(c+2),h=a.readUint8(c+3),b=(d&7)<<18|(b&63)<<12|(f&63)<<6|h&63,c+=4):248==(d&252)?(b=a.readUint8(c+1),f=a.readUint8(c+2),h=a.readUint8(c+3),l=a.readUint8(c+4),b=(d&3)<<24|(b&63)<<18|(f&63)<<12|(h&63)<<6|l&63,c+=5):252==(d&254)?(b=a.readUint8(c+1),f=a.readUint8(c+2),h=a.readUint8(c+3),l=a.readUint8(c+4),n=a.readUint8(c+5),b=(d&1)<<30|(b&63)<<24|(f&63)<<18|(h&63)<<12|(l&63)<<6|n&63,c+=6):g(Error("Cannot decode UTF8 character at offset "+c+": charCode (0x"+d.toString(16)+
") is invalid"));return{"char":b,length:c-q}};b.encodeUTF8Char=function(a,c,b){var e=b;0>a&&g(Error("Cannot encode UTF8 character: charCode ("+a+") is negative"));128>a?(c.writeUint8(a&127,b),b+=1):2048>a?(c.writeUint8(a>>6&31|192,b).writeUint8(a&63|128,b+1),b+=2):65536>a?(c.writeUint8(a>>12&15|224,b).writeUint8(a>>6&63|128,b+1).writeUint8(a&63|128,b+2),b+=3):2097152>a?(c.writeUint8(a>>18&7|240,b).writeUint8(a>>12&63|128,b+1).writeUint8(a>>6&63|128,b+2).writeUint8(a&63|128,b+3),b+=4):67108864>a?(c.writeUint8(a>>
24&3|248,b).writeUint8(a>>18&63|128,b+1).writeUint8(a>>12&63|128,b+2).writeUint8(a>>6&63|128,b+3).writeUint8(a&63|128,b+4),b+=5):2147483648>a?(c.writeUint8(a>>30&1|252,b).writeUint8(a>>24&63|128,b+1).writeUint8(a>>18&63|128,b+2).writeUint8(a>>12&63|128,b+3).writeUint8(a>>6&63|128,b+4).writeUint8(a&63|128,b+5),b+=6):g(Error("Cannot encode UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)"));return b-e};b.calculateUTF8Char=function(a){0>a&&g(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;g(Error("Cannot calculate length of UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)"))};b.b=function(a){a=""+a;for(var c=0,d=0;d<a.length;d++)c+=b.calculateUTF8Char(a.charCodeAt(d));return c};b.prototype.writeUTF8String=function(a,c){var d="undefined"==typeof c,e=c="undefined"!=typeof c?c:this.offset,f=b.b(a);this.ensureCapacity(c+
f);for(f=0;f<a.length;f++)c+=b.encodeUTF8Char(a.charCodeAt(f),this,c);return d?(this.offset=c,this):c-e};b.prototype.readUTF8String=function(a,c){var d="undefined"==typeof c;c="undefined"!=typeof c?c:this.offset;for(var e,f="",h=c,l=0;l<a;l++)e=b.decodeUTF8Char(this,c),c+=e.length,f+=String.fromCharCode(e["char"]);return d?(this.offset=c,f):{string:f,length:c-h}};b.prototype.readUTF8StringBytes=function(a,c){var d="undefined"==typeof c;c="undefined"!=typeof c?c:this.offset;var e,f="",h=c;for(a=c+
a;c<a;)e=b.decodeUTF8Char(this,c),c+=e.length,f+=String.fromCharCode(e["char"]);c!=a&&g(Error("Actual string length differs from the specified: "+((c>a?"+":"")+c-a)+" bytes"));return d?(this.offset=c,f):{string:f,length:c-h}};b.prototype.writeLString=function(a,c){a=""+a;var d="undefined"==typeof c;c="undefined"!=typeof c?c:this.offset;var e=b.encodeUTF8Char(a.length,this,c),e=e+this.writeUTF8String(a,c+e);return d?(this.offset+=e,this):e};b.prototype.readLString=function(a){var c="undefined"==typeof a;
a="undefined"!=typeof a?a:this.offset;var d=b.decodeUTF8Char(this,a);a=this.readUTF8String(d["char"],a+d.length);return c?(this.offset+=d.length+a.length,a.string):{string:a.string,length:d.length+a.length}};b.prototype.writeVString=function(a,c){a=""+a;var d="undefined"==typeof c;c="undefined"!=typeof c?c:this.offset;var e=this.writeVarint32(b.b(a),c),e=e+this.writeUTF8String(a,c+e);return d?(this.offset+=e,this):e};b.prototype.readVString=function(a){var c="undefined"==typeof a;a="undefined"!=typeof a?
a:this.offset;var b=this.readVarint32(a);a=this.readUTF8StringBytes(b.value,a+b.length);return c?(this.offset+=b.length+a.length,a.string):{string:a.string,length:b.length+a.length}};b.prototype.writeCString=function(a,c){var b="undefined"==typeof c;c="undefined"!=typeof c?c:this.offset;var e=this.writeUTF8String(""+a,c);this.writeUint8(0,c+e);return b?(this.offset+=e+1,this):e+1};b.prototype.readCString=function(a){var c="undefined"==typeof a;a="undefined"!=typeof a?a:this.offset;var d,e="",f=a;
do d=b.decodeUTF8Char(this,a),a+=d.length,0!=d["char"]&&(e+=String.fromCharCode(d["char"]));while(0!=d["char"]);return c?(this.offset=a,e):{string:e,length:a-f}};b.prototype.writeJSON=function(a,c,b){b="function"==typeof b?b:JSON.stringify;return this.writeLString(b(a),c)};b.prototype.readJSON=function(a,c){c="function"==typeof c?c:JSON.parse;var b=this.readLString(a);return"string"==typeof b?c(b):{data:c(b.string),length:b.length}};b.prototype.printDebug=function(a){for(var c=(this.array!=m?"ByteBuffer(offset="+
this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")":"ByteBuffer(DESTROYED)")+"\n-------------------------------------------------------------------\n",b=this.toHex(16,k),e=this.toASCII(16,k),f=0;f<b.length;f++)c+=b[f]+" "+e[f]+"\n";if(a===k)return c;"function"==typeof a?a(c):console.log(c)};b.prototype.toHex=function(a,c){if(this.array==m)return"DESTROYED";c=!!c;a="undefined"!=typeof a?parseInt(a,10):16;1>a&&(a=16);for(var b="",e=[],f=new Uint8Array(this.array),
b=0==this.offset&&0==this.length?b+"|":0==this.length?b+">":0==this.offset?b+"<":b+" ",h=0;h<this.array.byteLength;h++){0<h&&0==h%a&&(e.push(b),b=" ");var l=f[h],l=l.toString(16).toUpperCase();2>l.length&&(l="0"+l);b+=l;b=h+1==this.offset&&h+1==this.length?b+"|":h+1==this.offset?b+"<":h+1==this.length?b+">":b+" "}if(c)for(;b.length<3*a+1;)b+=" ";e.push(b);return c?e:e.join("\n")};b.prototype.toASCII=function(a,c){if(this.array==m)return"";c=!!c;a="undefined"!=typeof a?parseInt(a,10):16;1>a&&(a=
16);for(var b="",e=[],f=new Uint8Array(this.array),h=0;h<this.array.byteLength;h++){0<h&&0==h%a&&(e.push(b),b="");var l=f[h],l=32<l&&127>l?String.fromCharCode(l):".",b=b+l}e.push(b);return c?e:e.join("\n")+"\n"};b.prototype.toString=function(){return this.array==m?"ByteBuffer(DESTROYED)":"ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")"};b.prototype.toArrayBuffer=function(a){var c=this.clone();c.offset>c.length&&c.flip();
var b=p;if(0<c.offset||c.length<c.array.byteLength)c.compact(),b=k;return a&&!b?c.copy().array:c.array};b.extend=function(a,c){"string"==typeof a&&"function"==typeof c?b.prototype[a]=c:g(Error("Cannot extend prototype with "+a+"="+c+" (exptected string and function)"))};"undefined"!=typeof module&&module.exports?module.exports=b:"undefined"!=typeof define&&define.amd?define("ByteBuffer",[],function(){return b}):(n.dcodeIO||(n.dcodeIO={}),n.dcodeIO.ByteBuffer=b)})(this);
function g(q){throw q;}var k=!0,m=null,p=!1;
(function(q){function r(n){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&&arguments[2]===k?m:new ArrayBuffer(a);this.view=this.array!=m?new DataView(this.array):m;this.offset=0;this.markedOffset=-1;this.length=0;this.littleEndian="undefined"!=typeof b?!!b:p}c.DEFAULT_CAPACITY=16;c.LITTLE_ENDIAN=k;c.BIG_ENDIAN=p;c.INT8=new Int8Array(1);c.UINT8=new Uint8Array(1);c.INT16=new Int16Array(1);c.UINT16=new Uint16Array(1);
c.INT32=new Int32Array(1);c.UINT32=new Uint32Array(1);c.FLOAT32=new Float32Array(1);c.FLOAT64=new Float64Array(1);c.Long=n;c.cast=function(a,b){a[0]=b;return a[0]};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();a.array?a=a.array:a.buffer&&(a=a.buffer);a instanceof ArrayBuffer||g(Error("Cannot wrap buffer of type "+typeof a));var e=new c(0,b,k);e.array=a;e.view=new DataView(e.array);e.offset=0;e.length=a.byteLength;return e};
c.prototype.LE=function(){this.littleEndian=k;return this};c.prototype.BE=function(){this.littleEndian=p;return this};c.prototype.resize=function(a){if(1>a)return p;this.array==m&&(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 k}return p};c.prototype.slice=function(a,b){this.array==m&&g(Error(this+" cannot be sliced: Already destroyed"));
b<=a&&g(Error(this+" cannot be sliced: End ("+b+") is less than begin ("+a+")"));(0>a||a>this.array.byteLength||1>b||b>this.array.byteLength)&&g(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};c.prototype.sliceAndCompact=function(a,b){return c.wrap(this.slice(a,b).toArrayBuffer(k))};c.prototype.ensureCapacity=function(a){return this.array==m?this.resize(a):this.array.byteLength<a?this.resize(2*this.array.byteLength>=
a?2*this.array.byteLength:a):p};c.prototype.flip=function(){this.length=this.array==m?0:this.offset;this.offset=0;return this};c.prototype.mark=function(a){this.array==m&&g(Error(this+" cannot be marked: Already destroyed"));a="undefined"!=typeof a?parseInt(a,10):this.offset;(0>a||a>this.array.byteLength)&&g(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,k);a.array=this.array;a.view=this.view;a.offset=this.offset;a.length=this.length;return a};c.prototype.copy=function(){if(this.array==m)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 this.array==
m?0:this.length-this.offset};c.prototype.capacity=function(){return this.array!=m?this.array.byteLength:0};c.prototype.compact=function(){this.array==m&&g(Error(this+" cannot be compacted: Already destroyed"));this.offset>this.length&&this.flip();this.offset==this.length&&g(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(this.array!=m)return this.view=this.array=m,this.length=this.offset=0,this};c.prototype.reverse=function(){this.array==m&&g(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));a.array==m&&g(Error(a+" cannot be appended to "+this+": Already destroyed"));var e=a.length-a.offset;if(0==e)return this;0>e&&(a=a.clone().flip(),e=a.length-a.offset);b="undefined"!=typeof b?b:(this.offset+=e)-e;this.ensureCapacity(b+e);e=new Uint8Array(a.array);(new Uint8Array(this.array)).set(e.subarray(a.offset,a.length),b);return this};c.prototype.prepend=function(a,b){a instanceof c||(a=c.wrap(a));a.array==m&&g(a+" cannot be prepended to "+
this+": Already destroyed");var e=a.length-a.offset;if(0==e)return this;0>e&&(a=a.clone().flip(),e=a.length-a.offset);var d="undefined"==typeof b;b="undefined"!=typeof b?b:this.offset;var f=e-b;0<f?(this.ensureCapacity(this.length+f),this.append(this,e),this.offset+=f,this.length+=f,this.append(a,0)):this.append(a,b-e);d&&(this.offset-=e);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;a>=this.array.byteLength&&g(Error("Cannot read int8 from "+this+": 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;a>=this.array.byteLength&&
g("Cannot read uint8 from "+this+": 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;a+2>this.array.byteLength&&g(Error("Cannot read int16 from "+this+": 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;a+2>this.array.c&&g(Error("Cannot read int16 from "+this+": 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;a+4>this.array.byteLength&&g(Error("Cannot read int32 from "+this+": 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;a+4>this.array.byteLength&&g(Error("Cannot read uint32 from "+this+": 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;(this.array==m||a+4>this.array.byteLength)&&
g(Error("Cannot read float32 from "+this+": 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;(this.array==m||a+8>this.array.byteLength)&&g(Error("Cannot read float64 from "+
this+": 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){n||g(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 n||(a=n.fromNumber(a));this.ensureCapacity(b+8);this.littleEndian?(this.view.setInt32(b,
a.getLowBits(),k),this.view.setInt32(b+4,a.getHighBits(),k)):(this.view.setInt32(b,a.getHighBits(),p),this.view.setInt32(b+4,a.getLowBits(),p));return this};c.prototype.readInt64=function(a){n||g(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(this.array==m||a+8>this.array.byteLength)this.offset-=8,g(Error("Cannot read int64 from "+this+": Capacity overflow"));return this.littleEndian?
new n(this.view.getInt32(a,k),this.view.getInt32(a+4,k)):new n(this.view.getInt32(a+4,p),this.view.getInt32(a,p))};c.prototype.writeLong=c.prototype.writeInt64;c.prototype.readLong=c.prototype.readInt64;c.a=5;c.prototype.writeVarint32=function(a,b){var e="undefined"==typeof b;b="undefined"!=typeof b?b:this.offset;c.UINT32[0]=a;this.ensureCapacity(b+c.calculateVarint32(a=c.UINT32[0]));var d=new Uint8Array(this.array),f=0;d[b]=a|128;128<=a?(d[b+1]=a>>7|128,16384<=a?(d[b+2]=a>>14|128,2097152<=a?(d[b+
3]=a>>21|128,268435456<=a?(d[b+4]=a>>28&127,f=5):(d[b+3]&=127,f=4)):(d[b+2]&=127,f=3)):(d[b+1]&=127,f=2)):(d[b]&=127,f=1);return e?(this.offset+=f,this):f};c.prototype.readVarint32=function(a){var b="undefined"==typeof a;a="undefined"!=typeof a?a:this.offset;var e=new Uint8Array(this.array),d=0,f;c.UINT32[0]=0;do d==c.a&&g(Error("Cannot read Varint32 from "+this+"@"+a+": Number of bytes is larger than "+c.a)),f=e[a+d],c.UINT32[0]|=(f&127)<<7*d,++d;while(f&128);c.INT32[0]=c.UINT32[0];return b?(this.offset+=
d,c.INT32[0]):{value:c.INT32[0],length:d}};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.prototype.writeVarint=c.prototype.writeVarint32;c.prototype.readVarint=c.prototype.readVarint32;c.calculateVarint32=function(a){c.UINT32[0]=a;return 128>c.UINT32[0]?1:16384>c.UINT32[0]?2:2097152>c.UINT32[0]?3:268435456>
c.UINT32[0]?4:5};c.zigZagEncode32=function(a){c.INT32[0]=a;return 0<=(a=c.INT32[0])?2*a:2*-a-1};c.zigZagDecode32=function(a){c.UINT32[0]=a;return 0==((a=c.UINT32[0])&1)?a/2:-(a+1)/2};c.decodeUTF8Char=function(a,b){var c=a.readUint8(b),d,f,h,l,n,q=b;0==(c&128)?(d=c,b+=1):192==(c&224)?(d=a.readUint8(b+1),d=(c&31)<<6|d&63,b+=2):224==(c&240)?(d=a.readUint8(b+1),f=a.readUint8(b+2),d=(c&15)<<12|(d&63)<<6|f&63,b+=3):240==(c&248)?(d=a.readUint8(b+1),f=a.readUint8(b+2),h=a.readUint8(b+3),d=(c&7)<<18|(d&63)<<
12|(f&63)<<6|h&63,b+=4):248==(c&252)?(d=a.readUint8(b+1),f=a.readUint8(b+2),h=a.readUint8(b+3),l=a.readUint8(b+4),d=(c&3)<<24|(d&63)<<18|(f&63)<<12|(h&63)<<6|l&63,b+=5):252==(c&254)?(d=a.readUint8(b+1),f=a.readUint8(b+2),h=a.readUint8(b+3),l=a.readUint8(b+4),n=a.readUint8(b+5),d=(c&1)<<30|(d&63)<<24|(f&63)<<18|(h&63)<<12|(l&63)<<6|n&63,b+=6):g(Error("Cannot decode UTF8 character at offset "+b+": charCode (0x"+c.toString(16)+") is invalid"));return{"char":d,length:b-q}};c.encodeUTF8Char=function(a,
b,c){var d=c;0>a&&g(Error("Cannot encode UTF8 character: charCode ("+a+") is negative"));128>a?(b.writeUint8(a&127,c),c+=1):2048>a?(b.writeUint8(a>>6&31|192,c).writeUint8(a&63|128,c+1),c+=2):65536>a?(b.writeUint8(a>>12&15|224,c).writeUint8(a>>6&63|128,c+1).writeUint8(a&63|128,c+2),c+=3):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):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):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):g(Error("Cannot encode UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)"));return c-d};c.calculateUTF8Char=function(a){0>a&&g(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;g(Error("Cannot calculate length of UTF8 character: charCode (0x"+a.toString(16)+") is too large (>= 0x80000000)"))};c.b=function(a){a=""+a;for(var b=0,e=0;e<a.length;e++)b+=c.calculateUTF8Char(a.charCodeAt(e));return b};c.prototype.writeUTF8String=function(a,b){var e="undefined"==typeof b,d=b="undefined"!=typeof b?b:this.offset,f=c.b(a);this.ensureCapacity(b+f);for(f=0;f<a.length;f++)b+=
c.encodeUTF8Char(a.charCodeAt(f),this,b);return e?(this.offset=b,this):b-d};c.prototype.readUTF8String=function(a,b){var e="undefined"==typeof b;b="undefined"!=typeof b?b:this.offset;for(var d,f="",h=b,l=0;l<a;l++)d=c.decodeUTF8Char(this,b),b+=d.length,f+=String.fromCharCode(d["char"]);return e?(this.offset=b,f):{string:f,length:b-h}};c.prototype.readUTF8StringBytes=function(a,b){var e="undefined"==typeof b;b="undefined"!=typeof b?b:this.offset;var d,f="",h=b;for(a=b+a;b<a;)d=c.decodeUTF8Char(this,
b),b+=d.length,f+=String.fromCharCode(d["char"]);b!=a&&g(Error("Actual string length differs from the specified: "+((b>a?"+":"")+b-a)+" bytes"));return e?(this.offset=b,f):{string:f,length:b-h}};c.prototype.writeLString=function(a,b){a=""+a;var e="undefined"==typeof b;b="undefined"!=typeof b?b:this.offset;var d=c.encodeUTF8Char(a.length,this,b),d=d+this.writeUTF8String(a,b+d);return e?(this.offset+=d,this):d};c.prototype.readLString=function(a){var b="undefined"==typeof a;a="undefined"!=typeof a?
a:this.offset;var e=c.decodeUTF8Char(this,a);a=this.readUTF8String(e["char"],a+e.length);return b?(this.offset+=e.length+a.length,a.string):{string:a.string,length:e.length+a.length}};c.prototype.writeVString=function(a,b){a=""+a;var e="undefined"==typeof b;b="undefined"!=typeof b?b:this.offset;var d=this.writeVarint32(c.b(a),b),d=d+this.writeUTF8String(a,b+d);return e?(this.offset+=d,this):d};c.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}};c.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};c.prototype.readCString=function(a){var b="undefined"==typeof a;a="undefined"!=typeof a?a:this.offset;var e,d="",f=a;do e=c.decodeUTF8Char(this,
a),a+=e.length,0!=e["char"]&&(d+=String.fromCharCode(e["char"]));while(0!=e["char"]);return b?(this.offset=a,d):{string:d,length:a-f}};c.prototype.writeJSON=function(a,b,c){c="function"==typeof c?c:JSON.stringify;return this.writeLString(c(a),b)};c.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}};c.prototype.printDebug=function(a){for(var b=(this.array!=m?"ByteBuffer(offset="+this.offset+
",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")":"ByteBuffer(DESTROYED)")+"\n-------------------------------------------------------------------\n",c=this.toHex(16,k),d=this.toASCII(16,k),f=0;f<c.length;f++)b+=c[f]+" "+d[f]+"\n";if(a===k)return b;"function"==typeof a?a(b):console.log(b)};c.prototype.toHex=function(a,b){if(this.array==m)return"DESTROYED";b=!!b;a="undefined"!=typeof a?parseInt(a,10):16;1>a&&(a=16);for(var c="",d=[],f=new Uint8Array(this.array),
c=0==this.offset&&0==this.length?c+"|":0==this.length?c+">":0==this.offset?c+"<":c+" ",h=0;h<this.array.byteLength;h++){0<h&&0==h%a&&(d.push(c),c=" ");var l=f[h],l=l.toString(16).toUpperCase();2>l.length&&(l="0"+l);c+=l;c=h+1==this.offset&&h+1==this.length?c+"|":h+1==this.offset?c+"<":h+1==this.length?c+">":c+" "}if(b)for(;c.length<3*a+1;)c+=" ";d.push(c);return b?d:d.join("\n")};c.prototype.toASCII=function(a,b){if(this.array==m)return"";b=!!b;a="undefined"!=typeof a?parseInt(a,10):16;1>a&&(a=
16);for(var c="",d=[],f=new Uint8Array(this.array),h=0;h<this.array.byteLength;h++){0<h&&0==h%a&&(d.push(c),c="");var l=f[h],l=32<l&&127>l?String.fromCharCode(l):".",c=c+l}d.push(c);return b?d:d.join("\n")+"\n"};c.prototype.toString=function(){return this.array==m?"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=p;if(0<b.offset||b.length<b.array.byteLength)b.compact(),c=k;return a&&!c?b.copy().array:b.array};c.extend=function(a,b){"string"==typeof a&&"function"==typeof b?c.prototype[a]=b:g(Error("Cannot extend prototype with "+a+"="+b+" (exptected string and function)"))};return c}"undefined"!=typeof module&&module.exports?module.exports=r(require("long")):"undefined"!=typeof define&&define.amd?define("ByteBuffer",["Long"],function(n){return r(n)}):(q.dcodeIO||(q.dcodeIO={}),q.dcodeIO.ByteBuffer=r(dcodeIO.Long))})(this);
{
"name": "bytebuffer",
"version": "1.1.5",
"version": "1.2.0",
"author": "Daniel Wirtz <dcode@dcode.io>",

@@ -16,2 +16,3 @@ "description": "ByteBuffer.js: A Java-like, Netty-inspired ByteBuffer implementation using typed arrays.",

"dependencies": {
"long": ">=1.0.1"
},

@@ -33,3 +34,3 @@ "devDependencies": {

"build": "preprocess src/ByteBuffer.js src/ > ByteBuffer.js",
"compile": "ccjs ByteBuffer.js --create_source_map=ByteBuffer.min.map --compilation_level=ADVANCED_OPTIMIZATIONS > ByteBuffer.min.js",
"compile": "ccjs ByteBuffer.js --create_source_map=ByteBuffer.min.map --compilation_level=ADVANCED_OPTIMIZATIONS --externs=externs/Long.js > ByteBuffer.min.js",
"noexpose": "cat ByteBuffer.js | grep -v @expose > ByteBuffer.noexpose.js",

@@ -36,0 +37,0 @@ "jsdoc": "jsdoc -c jsdoc.json"

@@ -19,3 +19,3 @@ ![ByteBuffer.js - A Java-like ByteBuffer](https://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.png)

* Efficient implicit resizing by doubling the current capacity
* Flipping (`ByteBuffer#flip()`) and resetting (`ByteBuffer#reset()`) like known from Java ByteBuffers
* Flipping (`ByteBuffer#flip()`), marking (`ByteBuffer#mark([offset])`) and resetting (`ByteBuffer#reset()`)
* Compacting of the backing buffer (`ByteBuffer#compact()`)

@@ -91,3 +91,7 @@ * Conversion to ArrayBuffer (`ByteBuffer#toArrayBuffer([forceCopy])`) (i.e. to send data over the wire, e.g. a WebSocket

Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long
support, you can skip the Long.js include.
```html
<script src="//raw.github.com/dcodeIO/Long.js/master/Long.min.js"></script>
<script src="//raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.min.js"></script>

@@ -106,4 +110,13 @@ ```

Optionally depends on [Long.js](https://github.com/dcodeIO/Long.js) for long (int64) support. If you do not require long
support, you can skip the Long.js config. [Require.js](http://requirejs.org/) example:
```javascript
require(["/path/to/ByteBuffer.js"], function(ByteBuffer) {
require.config({
"paths": {
"Long": "/path/to/Long.js"
"ByteBuffer": "/path/to/ByteBuffer.js"
}
});
require(["ByteBuffer"], function(ByteBuffer) {
var bb = new ByteBuffer();

@@ -116,2 +129,11 @@ bb.writeLString("Hello world!");

On long (int64) support
-----------------------
As of the [ECMAScript specification](http://ecma262-5.com/ELS5_HTML.htm#Section_8.5), number types have a maximum value
of 2^53. Beyond that, JavaScript falls back to double internally. However, real long support requires the full 64 bits
with the possibility to perform bitwise operations on the value for varint en-/decoding. So, to enable true long support
in ByteBuffer.js, it optionally depends on [Long.js](https://github.com/dcodeIO/Long.js), which actually utilizes two
32 bit numbers internally. If you do not require long support at all, you can skip it and save the additional bandwidth.
On node, long support is available by default through the [long](https://npmjs.org/package/long) dependency.
Downloads

@@ -118,0 +140,0 @@ ---------

@@ -383,21 +383,33 @@ /*

"write/readLong": function(test) {
"write/readInt64": function(test) {
var bb = new ByteBuffer(8);
test.strictEqual(bb.writeFloat64, bb.writeLong);
var max = Math.pow(2,52)-0.5;
bb.writeLong(max);
test.notEqual(max, bb.readLong(0));
test.equal(Math.round(max), bb.readLong(0));
max = Math.pow(2,53)-1;
var max = ByteBuffer.Long.MAX_VALUE.toNumber();
bb.writeLong(max).flip();
test.equal(bb.toHex(), "<7F FF FF FF FF FF FF FF>");
test.equal(bb.readLong(0), max);
var min = ByteBuffer.Long.MIN_VALUE.toNumber();
bb.writeLong(min).flip();
test.equal(bb.toHex(), "<80 00 00 00 00 00 00 00>");
test.equal(bb.readLong(0), min);
bb.writeLong(-1).flip();
test.equal(bb.toHex(), "<FF FF FF FF FF FF FF FF>");
test.equal(bb.readLong(0), -1);
bb.reset();
bb.writeLong(max);
bb.flip();
test.equal(max, bb.readLong());
bb.reset();
bb.writeLong(max+2);
bb.flip();
test.equal(max+2, bb.readLong());
bb.LE().writeInt64(new ByteBuffer.Long(0x89ABCDEF, 0x01234567)).flip();
test.equal(bb.toHex(), "<EF CD AB 89 67 45 23 01>");
test.done();
},
"write/readLong": function(test) {
var bb = new ByteBuffer(1);
test.strictEqual(bb.readInt64, bb.readLong);
test.strictEqual(bb.writeInt64, bb.writeLong);
test.done();
},
"LE/BE": function(test) {

@@ -600,3 +612,9 @@ var bb = new ByteBuffer(8).LE().writeInt(1).BE().writeInt(2).flip();

var code = fs.readFileSync(__dirname+"/../"+FILE);
var Long = ByteBuffer.Long;
var sandbox = new Sandbox({
require: function(moduleName) {
if (moduleName == 'long') {
return Long;
}
},
module: {

@@ -609,2 +627,3 @@ exports: {}

test.ok(typeof sandbox.module.exports == 'function');
test.ok(sandbox.module.exports.Long && sandbox.module.exports.Long == ByteBuffer.Long);
test.done();

@@ -642,6 +661,11 @@ },

var code = fs.readFileSync(__dirname+"/../"+FILE);
var sandbox = new Sandbox();
var sandbox = new Sandbox({
dcodeIO: {
Long: ByteBuffer.Long
}
});
vm.runInNewContext(code, sandbox, "ByteBuffer.js in shim-VM");
// console.log(util.inspect(sandbox));
test.ok(typeof sandbox.dcodeIO != 'undefined' && typeof sandbox.dcodeIO.ByteBuffer != 'undefined');
test.ok(sandbox.dcodeIO.ByteBuffer.Long && sandbox.dcodeIO.ByteBuffer.Long == ByteBuffer.Long);
test.done();

@@ -648,0 +672,0 @@ },

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 not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc