[zeromq-dev] zmsg.hpp
Ilja Golshtein
ilejncs at narod.ru
Thu Apr 28 16:32:37 CEST 2011
Pieter,
yes, zeromq messages are length specified, and I would expect
==
ustring data ((unsigned char*) message.data(), message.size())
==
instead of
==
ustring data = (unsigned char*) message.data();
==
zmsg.hpp is used in "Simple Pirate queue" C++ example. The wrap/unwrap semantics was unclear
for me and I've tried to find out the roots.
Personally I believe 0mq is targeted at people and environments do care about
performance and things like extra copy. That is why slow wrappers are a sort of dangerous
and could occasionally ruin 0mq reputation.
Thanks.
28.04.2011, 18:09, "Pieter Hintjens" <ph at imatix.com>:
> On Thu, Apr 28, 2011 at 4:00 PM, Ilja Golshtein <ilejncs at narod.ru>; wrote:
>
>> a couple of questions about zmsg.hpp , mentioned in zguide.
>
> Not sure where you're seeing the reference, it shouldn't be mentioned
> in the text. Perhaps in the C++ examples?
>
>> 1. Where is the official source of it? What is the status of the code?
>
> This was based on the C zmsg.h proto-API. That became part of libzapi
> which became czmq.
>
> That raft of changes is explained here:
> http://zguide.zeromq.org/main:author-notes
>
> The code is valid but IMO should be replaced (as the C code was) by a
> proper high-level C++ API (cppzmq), since it's unfortunate to base
> examples on adhoc APIs.
>
>> The question is if it reliable to assume zeromq message is ASCIIZ, what
>> we effectively do in the latest line I've quoted?
>
> I've covered this in the Guide quite early on since it's a major
> problem. It is unsafe to assume in C/C++ a message is ASCIIZ because
> that breaks interop with other languages.
>
> 0MQ strings are length-specified. One of the classes that czmq
> provides is zstr which reads/writes C strings to/from 0MQ strings.
> Similar functionality is in the zmsg.hpp header too.
>
>> Why we do this
>> data[message.size()] = 0
>> afterwards?
>
> Precisely to create an ASCIIZ string from a 0MQ string.
>
>> 3. Is it good idea to do extra copy keeping message parts?
>> I mean if
>> ==
>> std::vector<std::basic_string<unsigned char> > m_part_data;
>> ==
>> reasonable storing approach?
>
> IMO copying is fine for most cases but you want to abstract this so
> that the implementation can move to zero-copy later. The original C
> zmsg.h file copied multipart data, but the czmq zmsg class that
> replaces it does zero-copy whenever possible.
>
> -Pieter
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
--
Best regards,
Ilja Golshtein.
More information about the zeromq-dev
mailing list