pp::VarArrayBuffer to transfer data from JavaScript to NaCl, but not vice versa

293 views
Skip to first unread message

DevelopDaily

unread,
Feb 20, 2013, 12:23:10 AM2/20/13
to native-cli...@googlegroups.com
It seems to me that it is easy to use pp::VarArrayBuffer to transfer binary data from the Chrome/JavaScript to the NaCl, but not vice versa.

I have a chunk of bytes produced in the NaCl, but I cannot find a way to construct a pp::VarArrayBuffer object to transfer the bytes to the JavaScript. Did I miss something?

Thanks.

David Michael

unread,
Feb 20, 2013, 4:00:11 PM2/20/13
to native-cli...@googlegroups.com
You can just create one of the size you need:
https://developers.google.com/native-client/peppercpp/classpp_1_1_var_array_buffer#a7fd29347661fc1539dd474cc3f0e2a72
then write to it, probably using memcpy.

E.g.:
pp::VarArrayBuffer buffer(num_bytes);
memcpy(buffer.Map(), data, num_bytes);
instance->PostMessage(buffer);

Let me know if this doesn't work for you.




--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

taimoo...@gorillabox.net

unread,
Feb 3, 2016, 4:12:16 AM2/3/16
to Native-Client-Discuss, dmic...@chromium.org
Hello David

I am using your code template to transfer a simple uint8* array from PNaCl to javascript.

            uint8_t array[] = {120,120,120,120};

            struct PP_Var data = PSInterfaceVarArrayBuffer()->Create(num_bytes);

            memcpy(PSInterfaceVarArrayBuffer()->Map(data), array, sizeof(array));

            PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), data);

But on the javascript side I am getting an empty ArrayBuffer. Can you please tell me what the problem might be?


On Thursday, 21 February 2013 02:00:11 UTC+5, David Michael wrote:
You can just create one of the size you need:
https://developers.google.com/native-client/peppercpp/classpp_1_1_var_array_buffer#a7fd29347661fc1539dd474cc3f0e2a72
then write to it, probably using memcpy.

E.g.:
pp::VarArrayBuffer buffer(num_bytes);
memcpy(buffer.Map(), data, num_bytes);
instance->PostMessage(buffer);

Let me know if this doesn't work for you.

On Tue, Feb 19, 2013 at 10:23 PM, DevelopDaily <c...@datacivilization.com> wrote:
It seems to me that it is easy to use pp::VarArrayBuffer to transfer binary data from the Chrome/JavaScript to the NaCl, but not vice versa.

I have a chunk of bytes produced in the NaCl, but I cannot find a way to construct a pp::VarArrayBuffer object to transfer the bytes to the JavaScript. Did I miss something?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-discuss+unsub...@googlegroups.com.

David Michael

unread,
Feb 3, 2016, 11:10:06 AM2/3/16
to taimoo...@gorillabox.net, Native-Client-Discuss
Where does "num_bytes" come from? If I remember correctly, the ArrayBuffer has fixed size for its lifetime, so make sure that number is correct. If it's zero, you'll get an empty buffer sent to JavaScript.

HTH

On Wed, Feb 3, 2016 at 2:12 AM, <taimoo...@gorillabox.net> wrote:
Hello David

I am using your code template to transfer a simple uint8* array from PNaCl to javascript.

            uint8_t array[] = {120,120,120,120};

            struct PP_Var data = PSInterfaceVarArrayBuffer()->Create(num_bytes);

            memcpy(PSInterfaceVarArrayBuffer()->Map(data), array, sizeof(array));

            PSInterfaceMessaging()->PostMessage(PSGetInstanceId(), data);

But on the javascript side I am getting an empty ArrayBuffer. Can you please tell me what the problem might be?

On Thursday, 21 February 2013 02:00:11 UTC+5, David Michael wrote:
You can just create one of the size you need:
https://developers.google.com/native-client/peppercpp/classpp_1_1_var_array_buffer#a7fd29347661fc1539dd474cc3f0e2a72
then write to it, probably using memcpy.

E.g.:
pp::VarArrayBuffer buffer(num_bytes);
memcpy(buffer.Map(), data, num_bytes);
instance->PostMessage(buffer);

Let me know if this doesn't work for you.

On Tue, Feb 19, 2013 at 10:23 PM, DevelopDaily <c...@datacivilization.com> wrote:
It seems to me that it is easy to use pp::VarArrayBuffer to transfer binary data from the Chrome/JavaScript to the NaCl, but not vice versa.

I have a chunk of bytes produced in the NaCl, but I cannot find a way to construct a pp::VarArrayBuffer object to transfer the bytes to the JavaScript. Did I miss something?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages