Node Buffer to char array

后端 未结 1 1744
名媛妹妹
名媛妹妹 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 
    #include 
    
    void Test(const FunctionCallbackInfo& args)
    {
      Local 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)
    提交回复
    热议问题