[zeromq-dev] understanding CZMQ and its wrap/unwrap functions

Chuck Remes cremes.devlist at mac.com
Thu Oct 27 18:17:00 CEST 2011


I need some help understanding the *purpose* of the zmsg_wrap() and zmsg_unwrap() functions in the CZMQ library. I understand their function and how they work, but I don't understand why this particular pattern was important enough to put into the library.

The zmsg_wrap() function takes a zmsg_t and a zframe_t. It prepends an empty message to the zmsg_t and prepends the given frame.


list = frame1 -> frame2

zmsg_wrap(list, frame3)

list is now:

frame3 -> empty_frame -> frame1 -> frame2


The unwrap function reverses this work. Given the list above it would remove frame3 and empty_frame, destroy empty_frame and return frame3 to the caller.

So why does this functionality exist? The only reason that comes to mind is adding an envelope to a list of message frames that are part of a XREP reply. You could use zmsg_wrap() to prepend the envelope information and add the envelope delimiter from the rest of the body.

However, this is only useful if your REQ/XREQ socket is *directly* connected to the XREP. If there are any hops in between (e.g. QUEUE device) then the envelope information will consume multiple frames (message parts) before the delimiter. If this is the intention, then it should take a src *and* dst zmsg_t and prepend the src to the dst with the empty frame in between; that would make it useful for this particular case.

I came upon this when I was reading through the Majordomo message pattern. MDP might be useful in a new project I am doing at work, so while perusing the code I immediately came upon these wrap/unwrap functions. Maybe they are only useful for this particular protocol?

Any insight is appreciated.

cr




More information about the zeromq-dev mailing list