zmq: hoisting header encoding to helper function