ZMQ.jl
ZMQ.jl copied to clipboard
messaging interface is unnecessarily low-level and confusing
The Message type seems very unnecessary and like it exposes a lot of dangerous and confusing low-level details about how ZMQ works internally. Why doesn't ZMQ.send just take a array of bytes as its second argument? Why doesn't ZMQ.recv just return an array of bytes? ZMQ is message-oriented and each message is just an array of bytes. If someone wants to write to a buffer and then send that, they can do exactly that – construct an IOBuffer object themselves and then send the bytes it contains. To be helpful, ZMQ.send could easily allow passing an IOBuffer value as its second argument. You could even expose this interface:
ZMQ.send(s) do io
# write stuff to io
end
ZMQ.recv(s) do io
# read stuff from io
end
Is there any real reason to ever expose the Message type to the programmer?
Note that recv does "just return an array of bytes," since Message <: AbstractVector{Uint8}. And you really want to return the zmq_msg wrapper directly, rather than copying to Vector{Uint8} or similar, so that you can read the data in-place for a large message.
However, send could certainly support higher-level interfaces.
(That's also why the Message type is potentially useful for sending too: you might want to be accessing the data in a read-only fashion while you are sending it, without making a copy.)