[zeromq-dev] How to set filter for struct type

Lucas Hope lucas.r.hope at gmail.com
Fri Aug 9 03:57:08 CEST 2013


Hi again,

Sorry, it is important that the first struct member is a char array (char
arr[10]), and not a char pointer (char *ptr), as arr gets encoded directly
as part of the struct, but the ptr does not.

Luke


On Fri, Aug 9, 2013 at 11:54 AM, Lucas Hope <lucas.r.hope at gmail.com> wrote:

> Hi there,
>
> I don't know 100%. Subscriptions are prefix based. The way structs work in
> C is that they are packed according to member order. If your first struct
> member was a cstring (char *, null-terminated), then the subscription
> prefix should match that okay.  I'm not sure how C++ strings are
> represented. It might still work if they hold the char buffer at the front.
>
> I hope that helps. I'm not that qualified to answer, really.
>
> Cheers,
>
> Luke
>
>
> On Fri, Aug 9, 2013 at 11:06 AM, Roy Liu <liuchuanbo at gmail.com> wrote:
>
>> Anyone knows?
>> I can not find documents about the filter format according to different
>> data type.
>>
>>
>> On Thu, Aug 8, 2013 at 10:30 PM, <liuchuanbo at gmail.com> wrote:
>>
>>> Hi, everyone
>>>
>>> On PUB side: wd is struct type message and I send it to the subscriber.
>>> typedef struct tag_StructData
>>> {
>>> string name;
>>> }StructData;
>>>
>>> StructData wd;
>>> //  Prepare our context and publisher
>>> zmq::context_t context (1);
>>> zmq::socket_t publisher (context, ZMQ_PUB);
>>> int msgSize = sizeof(wd);
>>> zmq::message_t message(msgSize);
>>> memcpy ((void *) message.data(), &wd, msgSize);
>>> publisher.send(message);
>>>
>>>
>>> On SUB side:
>>> // Receive Everything
>>> subscriber.setsockopt(ZMQ_SUBSCRIBE, NULL, 0);
>>>
>>> *// How to set a filter to receive the struct message with the
>>> specified name, for example "ABC".*
>>>
>>>
>>> //string msg;
>>>  StructData *msg;
>>> while(true){
>>>  zmq::message_t m;
>>> subscriber.recv(&m);
>>>  msg = (StructData *)m.data();
>>> cout << msg->Symbol << endl;
>>>  }
>>>
>>>
>>> Thanks.
>>>
>>> --
>>> Best Regards,
>>> Roy Liu
>>>
>>>
>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>>
>
>
> --
> ---------------------------------------------------
> Dr Lucas Hope - lucas.r.hope at skype
> Machine Learning and Software Engineering Consultant
> Melbourne, Australia
>



-- 
---------------------------------------------------
Dr Lucas Hope - lucas.r.hope at skype
Machine Learning and Software Engineering Consultant
Melbourne, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130809/630a82cc/attachment.htm>


More information about the zeromq-dev mailing list