1

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

1
  • "So when I see examples of people extracting arrays from byte buffers," Where is an example that works? Commented Sep 16, 2016 at 21:01

1 Answer 1

1

Make sure that you've included <node_buffer.h>. Otherwise that is correct.

See also: Node Buffer to char array

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.