c++ - 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 receiving large, serialized, binary object using zeromq:

std::unique_ptr<message> input(createmessage());  if (receive(input, "data") > 0) {     std::string serialstr(static_cast<char*>(input->getdata()), input->getsize()); } 

how can send object through socket avoiding unnecessary memcpy:

std::unique_ptr<message> output(createmessage(serialstr.length())); memcpy(output->getdata(), serialstr.c_str(), serialstr.length());  fchannels.at("data2").at(0).send(output); 

also, idea use std::string contain binary object, or should use void* instead?

if doing forwarding can use same message, can use :

std::unique_ptr<message> input(createmessage()); if (receive(input, "data") > 0) {     fchannels.at("data2").at(0).send(input); } 

alternatively can @ 4 argument message constructor use existing buffer message payload rather copying.


Comments