当我试图从结构中获取char数组时的奇怪符号

时间:2015-05-17 03:09:56

标签: c++ node.js c++11 v8 libuv

我正在使用libuv(https://github.com/joyent/libuv)和nodejs v12。我写了本机模块,在这个模块中我有struct:

    struct Work_req
    {
        const char *data;
        size_t data_length;
        Isolate* isolate;
        unsigned int callback_id;

        Persistent<Function> callback;
    };

然后我尝试将此结构传递给工作:

     Work_req* request = new Work_req;
     request->data = buf->base;
     request->data_length = (size_t)nread;
     request->isolate = env->isolate();
     request->callback_id = callback_id->ToNumber()->Value();

     uv_work_t *req = new uv_work_t;
     req->data = request;

     uv_queue_work(env->event_loop(), req, findCallback, after_findCallback);

在这段代码的最后,我将工作传递给循环,一切正常。 但是当我在 findCallback 函数中尝试从uv_work_t * req读取数据时,我会在那里得到奇怪的符号:

      Work_req *s = ((struct Work_req*)req->data);
      printf(s>data); //print char array from structure here

我看到这样的事情:

����g�Kack_id":1,"error":null,"response":{"type":"test"}}�����

我如何解决它?

非常感谢。

0 个答案:

没有答案