charis charis - 2 years ago 79
C++ Question

What is the correct way to receive an object as a string through ZeroMQ and then send it with zero-copy through another socket?

I am receiving a large, serialized, binary object using


std::unique_ptr<Message> input(CreateMessage());

if (Receive(input, "data") > 0) {
std::string serialStr(static_cast<char*>(input->GetData()), input->GetSize());

How can I send this object through another socket avoiding the unnecessary

std::unique_ptr<Message> output(CreateMessage(serialStr.length()));
memcpy(output->GetData(), serialStr.c_str(), serialStr.length());"data2").at(0).Send(output);

Also, is it a good idea to use an
to contain a binary object, or should I use a

Answer Source

If all you are doing is forwarding then you can use the same message, you can use something like :

std::unique_ptr<Message> input(CreateMessage());
if (Receive(input, "data") > 0)

Alternatively you can look at the 4 argument message constructor to use an existing buffer as the message payload rather than copying.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download