哪个头文件是ZeroMQ中定义的smessage()方法?

时间:2018-03-23 14:39:50

标签: c++ zeromq pipeline

以下是ZeroMQ中使用smessage方法的代码。我在zhelpers.hpp头文件中搜索了它的定义,但它不在那里。

#include "zhelpers.hpp"
#include <string>

int main (int argc, char *argv[])
{
    //  Process tasks forever
    while (1) {

        zmq::message_t message;
        int workload;           //  Workload in msecs

        receiver.recv(&message);
        std::string smessage(static_cast<char*>(message.data()), message.size());

        std::istringstream iss(smessage);
        iss >> workload;

        //  Do the work
        s_sleep(workload);

        //  Send results to sink
        message.rebuild();
        sender.send(message);

        //  Simple progress indicator for the viewer
        std::cout << "." << std::flush;
    }
    return 0;
}

2 个答案:

答案 0 :(得分:2)

std::string smessage(static_cast<char*>(message.data()), message.size());

不是对函数smessage的调用,而是调用构造函数的std::string变量的定义

basic_string( const CharT* s,
              size_type count, 
              const Allocator& alloc = Allocator() );

答案 1 :(得分:2)

smessage不是一种方法。它是std::string类型的变量,它是通过使用带有指针和大小的重载构造函数创建的。

顺便说一句,您可以直接使用zmq::message_t::str()函数获取std::string

例如:

zmq::message_t msg;
// read some data...
std::string smessage = msg.str();