当我从C ++插件到NodeJS时
void MyFunction(const FunctionCallbackInfo<Value>& args)
{
Isolate *isolate = args.GetIsolate();
unsigned char *buffer = "something";
unsigned int len = 9;
args.GetReturnValue().Set(buffer);
}
我收到错误:
.node-gyp/9.2.0/include/node/v8.h:162:37:
error: cannot convert ‘v8::Primitive*’ to ‘unsigned char** volatile’ in assignment
我也看过这里:how to deliver c++ array to node.js using v8 native addon但是没有关于将无符号字符* 从C ++ 返回到NodeJS的答案。相反,这两个示例都显示了如何将缓冲区从NodeJS路由到C ++插件(并将它们转换为char *)
我希望我的nodejs中的“另一边”有
const buffer = myaddon.myfunc();
答案 0 :(得分:1)
node.js缓冲区表示为node::Buffer
对象
要从字节数组创建一个,请使用node::Buffer::Copy
- 例如:
Local<node::Buffer> js_buffer =
node::Buffer::Copy(isolate,
(const char *)buffer,
buffer_size)
.ToLocalChecked();