However, according to the ZMQ guide, strings should always be sent without the trailing NULL byte, as such, it's probably a good idea to stick to that ?
Kr, Diego Duclos On Tue, Aug 6, 2013 at 4:48 PM, <[email protected]> wrote: > 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. > > > [image: Inactive hide details for liuchuanbo---06/08/2013 03:41:54 > PM---Hi, Admir Thanks.]liuchuanbo---06/08/2013 03:41:54 PM---Hi, Admir > Thanks. > > From: [email protected] > To: "ZeroMQ development list" <[email protected]> > Date: 06/08/2013 03:41 PM > Subject: Re: [zeromq-dev] help: memcpy with message_t > Sent by: [email protected] > ------------------------------ > > > > Hi, Admir > > Thanks. > You're right. > > zipcode.data() is also correct. > > -- > Best Regards, > Roy Liu > > On 2013-8-6, at 下午9:58, Admir Efendic > <*[email protected]*<[email protected]>> > wrote: > > been ages but shouldn't this work: > > memcpy ((void *) message.data(), zipcode.c_str(), zipcode.size()+1); > > > > 2013/8/6 <*[email protected]* <[email protected]>> > 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* > **[email protected]* <[email protected]>* > > **http://lists.zeromq.org/mailman/listinfo/zeromq-dev*<http://lists.zeromq.org/mailman/listinfo/zeromq-dev> > > _______________________________________________ > zeromq-dev mailing list* > **[email protected]* <[email protected]> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > > _______________________________________________ > zeromq-dev mailing list > [email protected] > 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. > =========================================================== > > > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev > >
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
