Skip to content

uyha/zimq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zig binding for ZeroMQ

A ZeroMQ wrapper that covers nearly 100% of ZeroMQ's API (skipped functions are to be deprecated or superseded).

How to use

  1. Run the following command to add this project as a dependency

    zig fetch --save git+https://github.com/uyha/zimq.git
  2. In your build.zig, add the following

    const zimq = b.dependency("zimq", .{
        .target = target,
        .optimize = optimize,
    });
    // Replace `exe` with your actual library or executable
    exe.root_module.addImport("zimq", zimq.module("zimq"));

Example

const std = @import("std");
const zimq = @import("zimq");

pub fn main() !void {
    const context: *zimq.Context = try .init();
    defer context.deinit();

    const pull: *zimq.Socket = try .init(context, .pull);
    defer pull.deinit();

    const push: *zimq.Socket = try .init(context, .push);
    defer push.deinit();

    try pull.bind("inproc://#1");
    try push.connect("inproc://#1");

    try push.sendSlice("hello", .{});

    var buffer: zimq.Message = .empty();
    _ = try pull.recvMsg(&buffer, .{});

    std.debug.print("{s}\n", .{buffer.slice().?});
}

Binding map

All the binding functions live in the zimq module.

Context
  • zmq_ctx_get (zmq_ctx_get_ext is used instead)
  • zmq_ctx_get_ext -> Context.get
  • zmq_ctx_new -> Context.init
  • zmq_ctx_set (zmq_ctx_set_ext is used instead)
  • zmq_ctx_set_ext -> Context.set
  • zmq_ctx_shutdown -> Context.shutdown
  • zmq_ctx_term -> Context.deinit
Socket
  • zmq_bind -> Socket.bind
  • zmq_close -> Socket.deinit
  • zmq_connect -> Socket.connect
  • zmq_connect_peer -> Socket.connectPeer
  • zmq_disconnect -> Socket.disconnect
  • zmq_getsockopt -> Socket.get
  • zmq_recv -> Socket.recv
  • zmq_recvmsg (to be deprecated, zmq_msg_recv is used instead)
  • zmq_msg_recv -> Socket.recvMsg
  • zmq_send -> Socket.sendBuffer
  • zmq_send_const -> Socket.sendConst
  • zmq_sendmsg (to be deprecated, zmq_msg_send is used instead)
  • zmq_msg_send -> Socket.sendMsg
  • zmq_setsockopt -> Socket.set
  • zmq_socket -> Socket.init
  • zmq_socket_monitor -> Socket.monitor
  • zmq_socket_monitor_versioned -> Socket.monitorVersioned
  • zmq_socket_monitor_pipes_stats -> Socket.pipesStats
  • zmq_unbind -> Socket.unbind
Message
  • zmq_msg_close -> Message.deinit
  • zmq_msg_copy -> Message.copy
  • zmq_msg_data -> Message.data (Message.slice provides better access to the underlying data)
  • zmq_msg_get -> Message.get
  • zmq_msg_gets -> Message.gets
  • zmq_msg_init -> Message.empty
  • zmq_msg_init_buffer -> Message.withBuffer
  • zmq_msg_init_data -> Message.withData
  • zmq_msg_init_size -> Message.withSize
  • zmq_msg_more -> Message.more
  • zmq_msg_move -> Message.move
  • zmq_msg_routing_id -> Message.getRoutingId
  • zmq_msg_set (currently useless)
  • zmq_msg_set_routing_id -> Message.setRoutingId
  • zmq_msg_size -> Message.size
Polling
  • zmq_poll -> poll.poll
  • zmq_ppoll -> poll.ppoll
Poller
  • zmq_poller_new -> Poller.init
  • zmq_poller_destroy -> Poller.deinit
  • zmq_poller_size -> Poller.size
  • zmq_poller_add -> Poller.add
  • zmq_poller_modify -> Poller.modify
  • zmq_poller_remove -> Poller.remove
  • zmq_poller_add_fd -> Poller.add_fd
  • zmq_poller_modify_fd -> Poller.modify_fd
  • zmq_poller_remove_fd -> Poller.remove_fd
  • zmq_poller_wait -> Poller.wait
  • zmq_poller_wait_all -> Poller.wait_all
  • zmq_poller_fd -> Poller.fd
Proxy
  • zmq_proxy -> proxy
  • zmq_proxy_steerable -> proxySteerable
Timer
  • zmq_timers_new -> Timers.init
  • zmq_timers_destroy -> Timers.deinit
  • zmq_timers_add -> Timers.add
  • zmq_timers_cancel -> Timers.cancel
  • zmq_timers_set_interval -> Timers.setInterval
  • zmq_timers_reset -> Timers.reset
  • zmq_timers_timeout -> Timers.timeout
  • zmq_timers_execute -> Timers.execute
Runtime inspection
  • zmq_has -> has
  • zmq_version -> version
Atomic Counter
  • zmq_atomic_counter_dec -> AtomicCounter.dec
  • zmq_atomic_counter_destroy -> AtomicCounter.deinit
  • zmq_atomic_counter_inc -> AtomicCounter.inc
  • zmq_atomic_counter_new -> AtomicCounter.init
  • zmq_atomic_counter_set -> AtomicCounter.set
  • zmq_atomic_counter_value -> AtomicCounter.value
Utilities
  • zmq_errno -> errno
  • zmq_strerror -> strerror
Curve
  • zmq_curve_keypair -> curve.keypair
  • zmq_curve_public -> curve.publicKey
Z85
  • zmq_z85_encode -> z85.encode
  • zmq_z85_decode -> z85.decode