[zeromq-dev] zmsg.hpp
Pieter Hintjens
ph at imatix.com
Thu Apr 28 16:09:38 CEST 2011
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
More information about the zeromq-dev
mailing list