Reputation: 439
I am receiving a 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 I send this object through another socket avoiding the 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, is it a good idea to use an std::string
to contain a binary object, or should I use a void*
instead?
Upvotes: 0
Views: 326
Reputation: 1530
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)
{
fChannels.at("data2").at(0).Send(input);
}
Alternatively you can look at the 4 argument message constructor to use an existing buffer as the message payload rather than copying.
Upvotes: 1