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
I'm not familiar with ByteBuffer (trying it for the first time due protobuf.js), but I'm trying to simply write an int32 to the buffer, convert it to a ArrayBuffers and see this value in 4 bytes in a file output. I'm pretty sure I'm doing some nasty mistake and it's not the library's fault, but this is one of the ways I've tried:
varByteBuffer=dcodeIO.ByteBuffer;//below is run inside a loopvarbyteBuffer=newByteBuffer(ByteBuffer.DEFAULT_CAPACITY,ByteBuffer.LITTLE_ENDIAN);byteBuffer.append(newByteBuffer().writeInt32(data.calculate()));//finally, generate the file for downloadvardata=newBlob([newDataView(byteBuffer.toArrayBuffer())],{type: 'application/octet-stream'});this.url=($window.URL||$window.webkitURL).createObjectURL(data);
then in html there's a field to download the file, as in:
For example, when data.calculate() yields 32, I'd expect to see 0x 20 00 00 00, but what I got is 0x 28 00 38 05 (which in little endian integer is 87556136). Anyone would be kind to help me pinpoint the mistake(s) here?
A more extensive explanation of what I'm trying to accomplish can be found here.
The text was updated successfully, but these errors were encountered:
HOORAY! it works now! I actually tried the short version as well before, but it didn't come to me that when using .toArrayBuffer() that is effectively performing a read operation, and per docs if I understood it right when switching from read/write operations a flip() is necessary, so that explains it (I forgot to add it when creating the DataView() after using .toArrayBuffer().
Just for clarity writing both mentioned ways works now:
Hello,
I'm not familiar with ByteBuffer (trying it for the first time due protobuf.js), but I'm trying to simply write an int32 to the buffer, convert it to a ArrayBuffers and see this value in 4 bytes in a file output. I'm pretty sure I'm doing some nasty mistake and it's not the library's fault, but this is one of the ways I've tried:
then in html there's a field to download the file, as in:
For example, when data.calculate() yields 32, I'd expect to see 0x 20 00 00 00, but what I got is 0x 28 00 38 05 (which in little endian integer is 87556136). Anyone would be kind to help me pinpoint the mistake(s) here?
A more extensive explanation of what I'm trying to accomplish can be found here.
The text was updated successfully, but these errors were encountered: