Umm thank you for the response... but isn't clear for me. Now I develop on 
version 6.2.1 seems that "ArrayBufferView" have an instance of Uint8Array.. 
but how this help for my questions?

1. Why I see inside my "ArrayBuffer" the entire js code and other binary 
content?
2. What is the right way for access to data?

Il giorno lunedì 4 luglio 2016 12:06:43 UTC+2, Ben Noordhuis ha scritto:
>
> On Mon, Jul 4, 2016 at 12:00 PM, Elia Mazzuoli <[email protected] 
> <javascript:>> wrote: 
> > Hi all, I'm trying to access data inside an ArrayBufferView. This is my 
> > simple javascript code: 
> > 
> > const myAddon = require('addon location'); 
> > 
> > const myObj = myAddon.MyObj(); 
> > 
> > const data = Buffer.from('test'); 
> > myObj = doSomething(data); 
> > 
> > After that in my c++ I have this: 
> > 
> > void MyObj::doSomething(const v8::FunctionCallbackInfo<v8::Value> &args) 
> {) 
> > { 
> > 
> >     Local<v8::ArrayBufferView> dataBufferView = 
> > Local<v8::ArrayBufferView>::Cast(args[1]); 
> > 
> >     std::cout << "Lenght on dataBufferView: " << 
> > dataBufferView->ByteLength() << std::endl; 
> > 
> >     std::cout << "Byte offset on dataBufferView: " << 
> > dataBufferView->ByteOffset() << std::endl; 
> > 
> >      Local<ArrayBuffer> dataBuffer = dataBufferView->Buffer(); 
> > 
> >      std::cout << "Lenght dataBuffer: " << dataBuffer->ByteLength() << 
> > std::endl; 
> > 
> >      ArrayBuffer::Contents dataContent = dataBuffer->Externalize(); 
> > 
> > 
> >      uint8_t* startData = static_cast<uint8_t*>(dataContent.Data()); 
> > 
> >      std::cout << "Content of " <<dataContent.ByteLength() << " from js: 
> "; 
> > 
> >      for(unsigned int i = 0; i < dataContent->ByteLength(); i++) { 
> > 
> >         std::cout << *(startData + i); 
> > 
> >      } 
> > 
> >      std::cout << std::endl; 
> > 
> > 
> > } 
> > 
> > 
> > What is strange in this simple code is that dataBuffer->ByteLength() is 
> 8192 
> > and if I print out the data content what I see is my full javascript 
> code 
> > and some other binary data. 
> > 
> > So.. what is the right way to access data? 
>
> node::Buffer::Data() and node::Buffer::Length() from node_buffer.h. 
>
> Using v8::ArrayBufferView won't work in node.js versions where Buffer 
> is not an instance of Uint8Array. 
>

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to