将 Node.js 缓冲区传递给 C++ 插件 [英] Pass Node.js Buffer to C++ addon

查看:33
本文介绍了将 Node.js 缓冲区传递给 C++ 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

test.js

buf = new Buffer(100);
for (var i = 0; i < 100; i++) buf[i] = i
addon.myFync(buf);

addon.cpp

Handle<Value> set(const Arguments& args) {
    char *buf = SOMETHING(args[0]);
    return Undefined();
}

如何获取C++函数内部缓冲区数据的指针?

How to get the pointer to a data of the buffer inside the C++ function?

我应该写什么来代替SOMETHING(args[0])?

我在编辑器中打开了 node_buffer.h,但我不知道.

I have node_buffer.h opened in my editor, but I cannot figure out.

节点版本 = v0.10.29

推荐答案

您可以:

char* buf = node::Buffer::Data(args[0]);

直接访问Buffer的字节.

这篇关于将 Node.js 缓冲区传递给 C++ 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆