请问下nodejs c/c++ addon 如何返回Buffer?
如题,项目里有个xtea加密解密的算法,是用C实现的,两个函数声明如下:
int encrypt(const char *plain, unsigned int plain_len, const char key[16], char *crypt, unsigned int * crypt_len )
int decrypt(const char *plain, unsigned int plain_len, const char key[16], char *crypt, unsigned int * crypt_len);
我尝试自己写一个addon,想传入参数(Buffer),加/解密完后用返回一个(Buffer)。
但是最新的nodejs c++代码有很大的变化,api都变了,网上的例子都很老,实在找不到可以参考的例子;
node::Buffer创建buffer返回的都是MaybeLocal<v8::Object>
类型,而MaybeLocal的toLocal函数又需要一个Local<S>* out
参数,
至此完全没有头绪如何创建一个Local<S>*
对象了。。。,请各位不吝指教!谢谢啦!
(头大,nodejs/iojs 文档真的太少了,看起来像是散文小说,。。。)
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local<S>* out) const
// public constructor
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate, size_t length);
// public constructor from string
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
v8::Handle<v8::String> string,
enum encoding enc = UTF8);
// public constructor - data is used, callback is passed data on object gc
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
char* data,
size_t length,
FreeCallback callback,
void* hint);
// public constructor - data is used.
NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
char* data,
size_t len);