[zeromq-dev] zproto 'msg' type question/problem

Duquette, Steve Steve.Duquette at bruker.com
Mon Jun 5 17:07:35 CEST 2017


Hello,
                While working with the zproto project I found that if I tried to define (in the xml file) 2 different messages, with each one having a 'msg' field, things did not work as expected. What would happen is the generated 'c' file would only refer to the 'msg' field of one of the messages.
                I found that the reason for this was because in the 'zproto_codec_c.gsl' script, a variable called 'class.msg' was defined once (for the 'msg' field defined in the second message) and then used throughout the script. This causes errors in the generated .c file as follows;
                Towards the end of the generated xxxx_send function you will get the following
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    //  Now send the param_sequence if necessary
    if (have_param_sequence) {
        if (self->param_sequence) {
            zframe_t *frame = zmsg_first (self->param_sequence);
            while (frame) {
                zframe_send (&frame, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0));
                frame = zmsg_next (self->param_sequence);
            }
        }
        else
            zmq_send (zsock_resolve (output), NULL, 0, 0);
    }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
So in 'message' A, there's a 'msg' field named 'command_message_data'
In 'message' B, there's a 'msg' field named 'param_sequence'.

So if you happen to use message A, the 'command_message_data' msg never even gets considered.

Whereas, I believe you should see two instances of that 'if(have_xxxx)' block as shown below,

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    //  Now send the command_message_data if necessary
    if (have_command_message_data) {
        if (self->command_message_data) {
            zframe_t *frame = zmsg_first (self->command_message_data);
            while (frame) {
                zframe_send (&frame, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0));
                frame = zmsg_next (self->command_message_data);
            }
        }
        else
            zmq_send (zsock_resolve (output), NULL, 0, 0);
    }
    //  Now send the param_sequence if necessary
    if (have_param_sequence) {
        if (self->param_sequence) {
            zframe_t *frame = zmsg_first (self->param_sequence);
            while (frame) {
                zframe_send (&frame, output, ZFRAME_REUSE + (--nbr_frames? ZFRAME_MORE: 0));
                frame = zmsg_next (self->param_sequence);
            }
        }
        else
            zmq_send (zsock_resolve (output), NULL, 0, 0);
    }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I've made the changes to the zproto_codec_c.gsl script to generate the above 2 blocks, and it works as expected on my system.

I'd be glad to submit a pull request to get these changes submitted, but I just thought I'd see if I'm way off track here and the current behavior is how it's supposed to be.

The only reason I could imagine the current behavior is correct is if there should only ever be one 'message' type defined in the xml file.
Also, I know there is the rule that if a message has a 'msg' field in it, then it must be the last field. I did make it the last field in both cases.

Best Regards,
                Steve

P.S. I foolishly opened an issue for this in the repository, and tried explaining it there, before I had a better understanding of how the pull request process works.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170605/d3b4a836/attachment.htm>


More information about the zeromq-dev mailing list