在哪个头文件中,在 ZeroMQ 中定义了 smessage() 方法

In which header file is the method smessage() defined in ZeroMQ?

本文关键字:smessage 方法 定义 文件 ZeroMQ      更新时间:2023-10-16

下面是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;
}
smessage不是

方法。它是 std::string 类型的变量,它是通过使用接受指针和大小的重载构造函数创建的。

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

例如:

zmq::message_t msg;
// read some data...
std::string smessage = msg.str();
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() );