I am sending a message over ZeroMQ PUB/SUB
archetype, using a tcp://
transport-class channel, after serializing a capnp
message using capnp::messageToFlatArray
. On the receiving side I receive the entire content in a zmq_msg_t
message. But zmq_msg_data(&message)
returns a memory location which is not capnp::word
aligned. So FlatArrayMessageReader
is throwing exception that the memory is not aligned.
Simplified code looks like this:
zmq_msg_t message;
zmq_msg_init(&message);
zmq_msg_recv(&message, socket, flags);
size_t size = zmq_msg_size(&message);
auto data = zmq_msg_data(&message);
auto pdata = kj::arrayPtr((const capnp::word*)data, size / sizeof(capnp::word));
capnp::FlatArrayMessageReader msg = capnp::FlatArrayMessageReader(pdata); // exception
What would be a good way to get the data aligned without copying the entire buffer? Or is there a way to receive the message in a word aligned memory without performance penalty - like disabling zero copy in zmq?
Trying on ubuntu 18.04 with capnp version 0.7.0, zeromq version 4.3.2 and gcc 7.4.0.