problem parsing byte arrays through the jsb

problem parsing byte arrays through the jsb
0.0 0


Hi all,

I’m having a problem passing a byte array through the JSB layer to my C++ file implementation which does file saving and reading.

The data arrives as an ArrayBuffer, so I tried to save it as a char pointer as below:

 int FileOperation::saveFile(string fileName, unsigned char* file, double size)

However in the JSB file it seems to not be able to convert this.

    ok &= jsval_to_std_string(cx, argv[0], &arg0);
    #pragma warning NO CONVERSION TO NATIVE FOR unsigned char*;
    ok &= JS_ValueToNumber(cx, argv[2], &arg2);

I notice that this is the case, because it chops my picture files down to 20480 bytes maximum.

Any hints will be appreciated,
else I will post the answer when Ive crawled to an answer :slight_smile:


Just to feedback an answer to people who are looking:

It is necessary to pass an ArrayBufferView that’s typed appropriately - for instance to Uint8Array on the JS side, and then one can use the following clip of JSB from the extensions.

ok &= JSB_get_arraybufferview_dataptr( cx, argv[1], &bufferSize, &arg1);

That’s the gist of it.