Hey I know people have asked this question before however for whatever reason the typical SO answer isn't working for me. Basically I have an unsigned byte array:
var message = Buffer.from([
0x27, 0x52, 0x00, 0x8E
])
myAddon.test(message);
In my c++ module I need to get that ByteBuffer into an const UInt8 * data structure.
My code currently is:
#include <node.h>
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::Object;
using v8::Value;
using v8::Exception;
void test(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
if (!args[0] ->IsObject()) {
isolate -> ThrowException(Exception::TypeError(
v8::String::NewFromUtf8(isolate, "All arguments must be string")
));
return;
}
Local<Object> bufferObj = args[0]->ToObject();
const UInt8* d = (const UInt8*)node::Buffer::Data(bufferObj);
This only code that demonstrates the issue. Now whats happening is that Buffer is that I'm getting error: no member named 'Buffer' in namespace 'node'. So when I see examples of people extracting arrays from byte buffers, I get confused. Is there another header file or library I need to import?
Thanks