[zeromq-dev] help: memcpy with message_t
Richard_Newton at waters.com
Richard_Newton at waters.com
Tue Aug 6 16:48:56 CEST 2013
Well, if your subscriber relies on it being null terminated you should use c_str(), data() may work but its implementation dependant, not guaranteed
to null terminate.
If you don't need a null terminated you can use size() instead of size() + 1. E.g.
// To message
memcpy(message.data(), zipcode.data(), zipcode.size());
// From message
std::string result(static_cast<const char*>(message.data()), message.size());
Ric.
From: liuchuanbo at gmail.com
To: "ZeroMQ development list" <zeromq-dev at lists.zeromq.org>
Date: 06/08/2013 03:41 PM
Subject: Re: [zeromq-dev] help: memcpy with message_t
Sent by: zeromq-dev-bounces at lists.zeromq.org
Hi, Admir
Thanks.
You're right.
zipcode.data() is also correct.
--
Best Regards,
Roy Liu
On 2013-8-6, at 下午9:58, Admir Efendic <admir.efendic at gmail.com> wrote:
been ages but shouldn't this work:
memcpy ((void *) message.data(), zipcode.c_str(), zipcode.size()+1);
2013/8/6 <liuchuanbo at gmail.com>
I'm using PUB-SUB test with zmq.
pls give me some advices. Thanks.
My code:
---------------------
std::string zipcode = "10001";
zmq::message_t message(zipcode.size()+1);
// it's OK.
memcpy ((void *) message.data(), "10001", zipcode.size()+1);
// it's Error, subscriber always receives bizarre code.
memcpy ((void *) message.data(), &zipcode, zipcode.size()+1);
---------------------
--
Best Regards,
Roy Liu
_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
===========================================================
The information in this email is confidential, and is intended solely for the addressee(s).
Access to this email by anyone else is unauthorized and therefore prohibited. If you are
not the intended recipient you are notified that disclosing, copying, distributing or taking
any action in reliance on the contents of this information is strictly prohibited and may be unlawful.
===========================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130806/e367c441/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130806/e367c441/attachment.gif>
More information about the zeromq-dev
mailing list