You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any reason why ByteBuffer.wrap can't use a plain array? If it can already use a string, why couldn't use an array?
I'm saying this because I've created a new prototype function called readBytes that looks as the following:
ByteBuffer.prototype.readBytes=function(length,offset){length=typeoflength!=='undefined' ? length : this.length;offset=typeofoffset!=='undefined' ? offset : (this.offset+=length)-length;if(offset+length>this.array.byteLength){throw(newError('Cannot read '+length+' bytes from '+this+' at '+offset+': Capacity overflow'));}varout=newByteBuffer(length,this.littleEndian);// this instead of []for(vari=0;i<length;i++){out.writeUint8(this.view.getInt8(offset+i,this.littleEndian));// this instead of out.push()}out.flip();returnout;// returns a bytebuffer instead of array, since cant use ByteBuffer.wrap on array};
ByteBuffer.wrap errors out with Cannot wrap buffer of type object, Array. I know it expects a native Buffer, ByteBuffer or ArrayBuffer, but I wanted to keep it "neutral", so I can use it on the browser, is it possible or I should use a typed array anyway?
The text was updated successfully, but these errors were encountered:
Is there any reason why ByteBuffer.wrap can't use a plain array? If it can already use a string, why couldn't use an array?
I'm saying this because I've created a new prototype function called
readBytes
that looks as the following:ByteBuffer.wrap errors out with
Cannot wrap buffer of type object, Array
. I know it expects a native Buffer, ByteBuffer or ArrayBuffer, but I wanted to keep it "neutral", so I can use it on the browser, is it possible or I should use a typed array anyway?The text was updated successfully, but these errors were encountered: