Node Buffer to char array

后端 未结 1 1743
名媛妹妹
名媛妹妹 2021-01-23 12:47

I have a native NodeJS addon that accepts a Buffer instance as one of it\'s arguments.

I\'m able to convert a char array into a Buffer

相关标签:
1条回答
  • 2021-01-23 13:25

    Maybe I'm late, but the following code should work:

    #include <node.h>
    #include <node_buffer.h>
    
    void Test(const FunctionCallbackInfo<Value>& args)
    {
      Local<Object> bufferObj = args[0]->ToObject();
      char* bufferData = node::Buffer::Data(bufferObj);
      size_t bufferLength = node::Buffer::Length(bufferObj);
    }
    

    Reference:

    • http://www.puritys.me/docs-blog/article-286-How-to-pass-the-paramater-of-Node.js-or-io.js-into-native-C/C++-function..html
    • https://github.com/nodejs/nan/blob/master/nan.h#L25
    0 讨论(0)
提交回复
热议问题