Hi Stephan,

You'll want to pass the segments to capnp::SegmentArrayMessageReader.

But, the segments do need to be aligned, and if ZeroMQ doesn't guarantee
this, you might be stuck copying. You could of course check dynamically
whether the pointer is properly-aligned and skip the copy in that case, but
if the alignment is random then you'd only expect to avoid the copy 1 time
in 8, which is not so exciting... :/

-Kenton

On Wed, Mar 29, 2017 at 3:56 AM, Stephan Opfer <[email protected]>
wrote:

> Hi,
>
> I would like to receive capnp messages over zeromq without extra copying
> the data from zeromq into capnp messages.
>
> My current approach is based on these articles/tutorials/posts:
>
>    - ZeroMQ - Multipart + ZeroCopy: http://zeromq.org/blog:zero-copy
>    - Old post about sending and receiving via ZeroMQ + Capnp:
>    https://groups.google.com/d/msg/capnproto/ClDjGbO7egA/JZjlsUr5kCkJ
>    <https://groups.google.com/d/msg/capnproto/ClDjGbO7egA/JZjlsUr5kCkJ>
>    - Question about ownership of CAPNP messages, while sending via
>    ZeroMQ: https://lists.zeromq.org/pipermail/zeromq-dev/2017-
>    March/031525.html
>
> So the sending part (untested & uncompiled) is currently like this:
>
>     auto segments = message.getSegmentsForOutput();
>
>     auto it = segments.begin();
>     auto i = segments.size();
>     assert(i != 0);
>     while (--i != 0)
>     {
>         zmq_send_const(this->socket, reinterpret_cast<char const
> *>(&(*it)[0]), it->size() * sizeof(capnp::word),
>                        ZMQ_SNDMORE);
>         ++it;
>     }
>     zmq_send_const(this->socket, reinterpret_cast<char const
> *>(&(*it)[0]), it->size() * sizeof(capnp::word), 0);
>
>
> The question is how should I create a capnp message from the received
> parts of a zeromq multipart message? I read about word alignment, which is
> taken care of in the second of the above links. But it looks like a lot of
> copies, could they be avoided?
>
>
> General hints/advices are welcome too. :)
>
>
> Greetings,
>
>   Stephan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> Visit this group at https://groups.google.com/group/capnproto.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to