czmq-ffi-gen 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,385 @@
1
+ ################################################################################
2
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3
+ # Please refer to the README for information about making permanent changes. #
4
+ ################################################################################
5
+
6
+ module CZMQ
7
+ module FFI
8
+
9
+ # event-driven reactor
10
+ # @note This class is 100% generated using zproject.
11
+ class Zloop
12
+ # Raised when one tries to use an instance of {Zloop} after
13
+ # the internal pointer to the native object has been nullified.
14
+ class DestroyedError < RuntimeError; end
15
+
16
+ # Boilerplate for self pointer, initializer, and finalizer
17
+ class << self
18
+ alias :__new :new
19
+ end
20
+ # Attaches the pointer _ptr_ to this instance and defines a finalizer for
21
+ # it if necessary.
22
+ # @param ptr [::FFI::Pointer]
23
+ # @param finalize [Boolean]
24
+ def initialize(ptr, finalize = true)
25
+ @ptr = ptr
26
+ if @ptr.null?
27
+ @ptr = nil # Remove null pointers so we don't have to test for them.
28
+ elsif finalize
29
+ @finalizer = self.class.create_finalizer_for @ptr
30
+ ObjectSpace.define_finalizer self, @finalizer
31
+ end
32
+ end
33
+ # @param ptr [::FFI::Pointer]
34
+ # @return [Proc]
35
+ def self.create_finalizer_for(ptr)
36
+ Proc.new do
37
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
38
+ ptr_ptr.write_pointer ptr
39
+ ::CZMQ::FFI.zloop_destroy ptr_ptr
40
+ end
41
+ end
42
+ # @return [Boolean]
43
+ def null?
44
+ !@ptr or @ptr.null?
45
+ end
46
+ # Return internal pointer
47
+ # @return [::FFI::Pointer]
48
+ def __ptr
49
+ raise DestroyedError unless @ptr
50
+ @ptr
51
+ end
52
+ # So external Libraries can just pass the Object to a FFI function which expects a :pointer
53
+ alias_method :to_ptr, :__ptr
54
+ # Nullify internal pointer and return pointer pointer.
55
+ # @note This detaches the current instance from the native object
56
+ # and thus makes it unusable.
57
+ # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
58
+ # pointing to the native object
59
+ def __ptr_give_ref
60
+ raise DestroyedError unless @ptr
61
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
+ ptr_ptr.write_pointer @ptr
63
+ ObjectSpace.undefine_finalizer self if @finalizer
64
+ @finalizer = nil
65
+ @ptr = nil
66
+ ptr_ptr
67
+ end
68
+
69
+ # Create a new callback of the following type:
70
+ # Callback function for reactor socket activity
71
+ # typedef int (zloop_reader_fn) (
72
+ # zloop_t *loop, zsock_t *reader, void *arg);
73
+ #
74
+ # @note WARNING: If your Ruby code doesn't retain a reference to the
75
+ # FFI::Function object after passing it to a C function call,
76
+ # it may be garbage collected while C still holds the pointer,
77
+ # potentially resulting in a segmentation fault.
78
+ def self.reader_fn
79
+ ::FFI::Function.new :int, [:pointer, :pointer, :pointer], blocking: true do |loop, reader, arg|
80
+ loop = Zloop.__new loop, false
81
+ reader = Zsock.__new reader, false
82
+ result = yield loop, reader, arg
83
+ result = Integer(result)
84
+ result
85
+ end
86
+ end
87
+
88
+ # Create a new callback of the following type:
89
+ # Callback function for reactor events (low-level)
90
+ # typedef int (zloop_fn) (
91
+ # zloop_t *loop, zmq_pollitem_t *item, void *arg);
92
+ #
93
+ # @note WARNING: If your Ruby code doesn't retain a reference to the
94
+ # FFI::Function object after passing it to a C function call,
95
+ # it may be garbage collected while C still holds the pointer,
96
+ # potentially resulting in a segmentation fault.
97
+ def self.fn
98
+ ::FFI::Function.new :int, [:pointer, :pointer, :pointer], blocking: true do |loop, item, arg|
99
+ loop = Zloop.__new loop, false
100
+ result = yield loop, item, arg
101
+ result = Integer(result)
102
+ result
103
+ end
104
+ end
105
+
106
+ # Create a new callback of the following type:
107
+ # Callback for reactor timer events
108
+ # typedef int (zloop_timer_fn) (
109
+ # zloop_t *loop, int timer_id, void *arg);
110
+ #
111
+ # @note WARNING: If your Ruby code doesn't retain a reference to the
112
+ # FFI::Function object after passing it to a C function call,
113
+ # it may be garbage collected while C still holds the pointer,
114
+ # potentially resulting in a segmentation fault.
115
+ def self.timer_fn
116
+ ::FFI::Function.new :int, [:pointer, :int, :pointer], blocking: true do |loop, timer_id, arg|
117
+ loop = Zloop.__new loop, false
118
+ result = yield loop, timer_id, arg
119
+ result = Integer(result)
120
+ result
121
+ end
122
+ end
123
+
124
+ # Create a new zloop reactor
125
+ # @return [CZMQ::Zloop]
126
+ def self.new()
127
+ ptr = ::CZMQ::FFI.zloop_new()
128
+ __new ptr
129
+ end
130
+
131
+ # Destroy a reactor
132
+ #
133
+ # @return [void]
134
+ def destroy()
135
+ return unless @ptr
136
+ self_p = __ptr_give_ref
137
+ result = ::CZMQ::FFI.zloop_destroy(self_p)
138
+ result
139
+ end
140
+
141
+ # Register socket reader with the reactor. When the reader has messages,
142
+ # the reactor will call the handler, passing the arg. Returns 0 if OK, -1
143
+ # if there was an error. If you register the same socket more than once,
144
+ # each instance will invoke its corresponding handler.
145
+ #
146
+ # @param sock [Zsock, #__ptr]
147
+ # @param handler [::FFI::Pointer, #to_ptr]
148
+ # @param arg [::FFI::Pointer, #to_ptr]
149
+ # @return [Integer]
150
+ def reader(sock, handler, arg)
151
+ raise DestroyedError unless @ptr
152
+ self_p = @ptr
153
+ sock = sock.__ptr if sock
154
+ result = ::CZMQ::FFI.zloop_reader(self_p, sock, handler, arg)
155
+ result
156
+ end
157
+
158
+ # Cancel a socket reader from the reactor. If multiple readers exist for
159
+ # same socket, cancels ALL of them.
160
+ #
161
+ # @param sock [Zsock, #__ptr]
162
+ # @return [void]
163
+ def reader_end(sock)
164
+ raise DestroyedError unless @ptr
165
+ self_p = @ptr
166
+ sock = sock.__ptr if sock
167
+ result = ::CZMQ::FFI.zloop_reader_end(self_p, sock)
168
+ result
169
+ end
170
+
171
+ # Configure a registered reader to ignore errors. If you do not set this,
172
+ # then readers that have errors are removed from the reactor silently.
173
+ #
174
+ # @param sock [Zsock, #__ptr]
175
+ # @return [void]
176
+ def reader_set_tolerant(sock)
177
+ raise DestroyedError unless @ptr
178
+ self_p = @ptr
179
+ sock = sock.__ptr if sock
180
+ result = ::CZMQ::FFI.zloop_reader_set_tolerant(self_p, sock)
181
+ result
182
+ end
183
+
184
+ # Register low-level libzmq pollitem with the reactor. When the pollitem
185
+ # is ready, will call the handler, passing the arg. Returns 0 if OK, -1
186
+ # if there was an error. If you register the pollitem more than once, each
187
+ # instance will invoke its corresponding handler. A pollitem with
188
+ # socket=NULL and fd=0 means 'poll on FD zero'.
189
+ #
190
+ # @param item [::FFI::Pointer, #to_ptr]
191
+ # @param handler [::FFI::Pointer, #to_ptr]
192
+ # @param arg [::FFI::Pointer, #to_ptr]
193
+ # @return [Integer]
194
+ def poller(item, handler, arg)
195
+ raise DestroyedError unless @ptr
196
+ self_p = @ptr
197
+ result = ::CZMQ::FFI.zloop_poller(self_p, item, handler, arg)
198
+ result
199
+ end
200
+
201
+ # Cancel a pollitem from the reactor, specified by socket or FD. If both
202
+ # are specified, uses only socket. If multiple poll items exist for same
203
+ # socket/FD, cancels ALL of them.
204
+ #
205
+ # @param item [::FFI::Pointer, #to_ptr]
206
+ # @return [void]
207
+ def poller_end(item)
208
+ raise DestroyedError unless @ptr
209
+ self_p = @ptr
210
+ result = ::CZMQ::FFI.zloop_poller_end(self_p, item)
211
+ result
212
+ end
213
+
214
+ # Configure a registered poller to ignore errors. If you do not set this,
215
+ # then poller that have errors are removed from the reactor silently.
216
+ #
217
+ # @param item [::FFI::Pointer, #to_ptr]
218
+ # @return [void]
219
+ def poller_set_tolerant(item)
220
+ raise DestroyedError unless @ptr
221
+ self_p = @ptr
222
+ result = ::CZMQ::FFI.zloop_poller_set_tolerant(self_p, item)
223
+ result
224
+ end
225
+
226
+ # Register a timer that expires after some delay and repeats some number of
227
+ # times. At each expiry, will call the handler, passing the arg. To run a
228
+ # timer forever, use 0 times. Returns a timer_id that is used to cancel the
229
+ # timer in the future. Returns -1 if there was an error.
230
+ #
231
+ # @param delay [Integer, #to_int, #to_i]
232
+ # @param times [Integer, #to_int, #to_i]
233
+ # @param handler [::FFI::Pointer, #to_ptr]
234
+ # @param arg [::FFI::Pointer, #to_ptr]
235
+ # @return [Integer]
236
+ def timer(delay, times, handler, arg)
237
+ raise DestroyedError unless @ptr
238
+ self_p = @ptr
239
+ delay = Integer(delay)
240
+ times = Integer(times)
241
+ result = ::CZMQ::FFI.zloop_timer(self_p, delay, times, handler, arg)
242
+ result
243
+ end
244
+
245
+ # Cancel a specific timer identified by a specific timer_id (as returned by
246
+ # zloop_timer).
247
+ #
248
+ # @param timer_id [Integer, #to_int, #to_i]
249
+ # @return [Integer]
250
+ def timer_end(timer_id)
251
+ raise DestroyedError unless @ptr
252
+ self_p = @ptr
253
+ timer_id = Integer(timer_id)
254
+ result = ::CZMQ::FFI.zloop_timer_end(self_p, timer_id)
255
+ result
256
+ end
257
+
258
+ # Register a ticket timer. Ticket timers are very fast in the case where
259
+ # you use a lot of timers (thousands), and frequently remove and add them.
260
+ # The main use case is expiry timers for servers that handle many clients,
261
+ # and which reset the expiry timer for each message received from a client.
262
+ # Whereas normal timers perform poorly as the number of clients grows, the
263
+ # cost of ticket timers is constant, no matter the number of clients. You
264
+ # must set the ticket delay using zloop_set_ticket_delay before creating a
265
+ # ticket. Returns a handle to the timer that you should use in
266
+ # zloop_ticket_reset and zloop_ticket_delete.
267
+ #
268
+ # @param handler [::FFI::Pointer, #to_ptr]
269
+ # @param arg [::FFI::Pointer, #to_ptr]
270
+ # @return [::FFI::Pointer]
271
+ def ticket(handler, arg)
272
+ raise DestroyedError unless @ptr
273
+ self_p = @ptr
274
+ result = ::CZMQ::FFI.zloop_ticket(self_p, handler, arg)
275
+ result
276
+ end
277
+
278
+ # Reset a ticket timer, which moves it to the end of the ticket list and
279
+ # resets its execution time. This is a very fast operation.
280
+ #
281
+ # @param handle [::FFI::Pointer, #to_ptr]
282
+ # @return [void]
283
+ def ticket_reset(handle)
284
+ raise DestroyedError unless @ptr
285
+ self_p = @ptr
286
+ result = ::CZMQ::FFI.zloop_ticket_reset(self_p, handle)
287
+ result
288
+ end
289
+
290
+ # Delete a ticket timer. We do not actually delete the ticket here, as
291
+ # other code may still refer to the ticket. We mark as deleted, and remove
292
+ # later and safely.
293
+ #
294
+ # @param handle [::FFI::Pointer, #to_ptr]
295
+ # @return [void]
296
+ def ticket_delete(handle)
297
+ raise DestroyedError unless @ptr
298
+ self_p = @ptr
299
+ result = ::CZMQ::FFI.zloop_ticket_delete(self_p, handle)
300
+ result
301
+ end
302
+
303
+ # Set the ticket delay, which applies to all tickets. If you lower the
304
+ # delay and there are already tickets created, the results are undefined.
305
+ #
306
+ # @param ticket_delay [Integer, #to_int, #to_i]
307
+ # @return [void]
308
+ def set_ticket_delay(ticket_delay)
309
+ raise DestroyedError unless @ptr
310
+ self_p = @ptr
311
+ ticket_delay = Integer(ticket_delay)
312
+ result = ::CZMQ::FFI.zloop_set_ticket_delay(self_p, ticket_delay)
313
+ result
314
+ end
315
+
316
+ # Set hard limit on number of timers allowed. Setting more than a small
317
+ # number of timers (10-100) can have a dramatic impact on the performance
318
+ # of the reactor. For high-volume cases, use ticket timers. If the hard
319
+ # limit is reached, the reactor stops creating new timers and logs an
320
+ # error.
321
+ #
322
+ # @param max_timers [Integer, #to_int, #to_i]
323
+ # @return [void]
324
+ def set_max_timers(max_timers)
325
+ raise DestroyedError unless @ptr
326
+ self_p = @ptr
327
+ max_timers = Integer(max_timers)
328
+ result = ::CZMQ::FFI.zloop_set_max_timers(self_p, max_timers)
329
+ result
330
+ end
331
+
332
+ # Set verbose tracing of reactor on/off
333
+ #
334
+ # @param verbose [Boolean]
335
+ # @return [void]
336
+ def set_verbose(verbose)
337
+ raise DestroyedError unless @ptr
338
+ self_p = @ptr
339
+ verbose = !(0==verbose||!verbose) # boolean
340
+ result = ::CZMQ::FFI.zloop_set_verbose(self_p, verbose)
341
+ result
342
+ end
343
+
344
+ # Start the reactor. Takes control of the thread and returns when the 0MQ
345
+ # context is terminated or the process is interrupted, or any event handler
346
+ # returns -1. Event handlers may register new sockets and timers, and
347
+ # cancel sockets. Returns 0 if interrupted, -1 if cancelled by a handler.
348
+ #
349
+ # @return [Integer]
350
+ def start()
351
+ raise DestroyedError unless @ptr
352
+ self_p = @ptr
353
+ result = ::CZMQ::FFI.zloop_start(self_p)
354
+ result
355
+ end
356
+
357
+ # Ignore zsys_interrupted flag in this loop. By default, a zloop_start will
358
+ # exit as soon as it detects zsys_interrupted is set to something other than
359
+ # zero. Calling zloop_ignore_interrupts will supress this behavior.
360
+ #
361
+ # @return [void]
362
+ def ignore_interrupts()
363
+ raise DestroyedError unless @ptr
364
+ self_p = @ptr
365
+ result = ::CZMQ::FFI.zloop_ignore_interrupts(self_p)
366
+ result
367
+ end
368
+
369
+ # Self test of this class.
370
+ #
371
+ # @param verbose [Boolean]
372
+ # @return [void]
373
+ def self.test(verbose)
374
+ verbose = !(0==verbose||!verbose) # boolean
375
+ result = ::CZMQ::FFI.zloop_test(verbose)
376
+ result
377
+ end
378
+ end
379
+ end
380
+ end
381
+
382
+ ################################################################################
383
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
384
+ # Please refer to the README for information about making permanent changes. #
385
+ ################################################################################
@@ -0,0 +1,512 @@
1
+ ################################################################################
2
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
3
+ # Please refer to the README for information about making permanent changes. #
4
+ ################################################################################
5
+
6
+ module CZMQ
7
+ module FFI
8
+
9
+ # working with multipart messages
10
+ # @note This class is 100% generated using zproject.
11
+ class Zmsg
12
+ # Raised when one tries to use an instance of {Zmsg} after
13
+ # the internal pointer to the native object has been nullified.
14
+ class DestroyedError < RuntimeError; end
15
+
16
+ # Boilerplate for self pointer, initializer, and finalizer
17
+ class << self
18
+ alias :__new :new
19
+ end
20
+ # Attaches the pointer _ptr_ to this instance and defines a finalizer for
21
+ # it if necessary.
22
+ # @param ptr [::FFI::Pointer]
23
+ # @param finalize [Boolean]
24
+ def initialize(ptr, finalize = true)
25
+ @ptr = ptr
26
+ if @ptr.null?
27
+ @ptr = nil # Remove null pointers so we don't have to test for them.
28
+ elsif finalize
29
+ @finalizer = self.class.create_finalizer_for @ptr
30
+ ObjectSpace.define_finalizer self, @finalizer
31
+ end
32
+ end
33
+ # @param ptr [::FFI::Pointer]
34
+ # @return [Proc]
35
+ def self.create_finalizer_for(ptr)
36
+ Proc.new do
37
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
38
+ ptr_ptr.write_pointer ptr
39
+ ::CZMQ::FFI.zmsg_destroy ptr_ptr
40
+ end
41
+ end
42
+ # @return [Boolean]
43
+ def null?
44
+ !@ptr or @ptr.null?
45
+ end
46
+ # Return internal pointer
47
+ # @return [::FFI::Pointer]
48
+ def __ptr
49
+ raise DestroyedError unless @ptr
50
+ @ptr
51
+ end
52
+ # So external Libraries can just pass the Object to a FFI function which expects a :pointer
53
+ alias_method :to_ptr, :__ptr
54
+ # Nullify internal pointer and return pointer pointer.
55
+ # @note This detaches the current instance from the native object
56
+ # and thus makes it unusable.
57
+ # @return [::FFI::MemoryPointer] the pointer pointing to a pointer
58
+ # pointing to the native object
59
+ def __ptr_give_ref
60
+ raise DestroyedError unless @ptr
61
+ ptr_ptr = ::FFI::MemoryPointer.new :pointer
62
+ ptr_ptr.write_pointer @ptr
63
+ ObjectSpace.undefine_finalizer self if @finalizer
64
+ @finalizer = nil
65
+ @ptr = nil
66
+ ptr_ptr
67
+ end
68
+
69
+ # Create a new empty message object
70
+ # @return [CZMQ::Zmsg]
71
+ def self.new()
72
+ ptr = ::CZMQ::FFI.zmsg_new()
73
+ __new ptr
74
+ end
75
+
76
+ # Receive message from socket, returns zmsg_t object or NULL if the recv
77
+ # was interrupted. Does a blocking recv. If you want to not block then use
78
+ # the zloop class or zmsg_recv_nowait or zmq_poll to check for socket input
79
+ # before receiving.
80
+ # @param source [::FFI::Pointer, #to_ptr]
81
+ # @return [CZMQ::Zmsg]
82
+ def self.recv(source)
83
+ ptr = ::CZMQ::FFI.zmsg_recv(source)
84
+ __new ptr
85
+ end
86
+
87
+ # Load/append an open file into new message, return the message.
88
+ # Returns NULL if the message could not be loaded.
89
+ # @param file [::FFI::Pointer, #to_ptr]
90
+ # @return [CZMQ::Zmsg]
91
+ def self.load(file)
92
+ ptr = ::CZMQ::FFI.zmsg_load(file)
93
+ __new ptr
94
+ end
95
+
96
+ # Decodes a serialized message buffer created by zmsg_encode () and returns
97
+ # a new zmsg_t object. Returns NULL if the buffer was badly formatted or
98
+ # there was insufficient memory to work.
99
+ # @param buffer [::FFI::Pointer, #to_ptr]
100
+ # @param buffer_size [Integer, #to_int, #to_i]
101
+ # @return [CZMQ::Zmsg]
102
+ def self.decode(buffer, buffer_size)
103
+ buffer_size = Integer(buffer_size)
104
+ ptr = ::CZMQ::FFI.zmsg_decode(buffer, buffer_size)
105
+ __new ptr
106
+ end
107
+
108
+ # Generate a signal message encoding the given status. A signal is a short
109
+ # message carrying a 1-byte success/failure code (by convention, 0 means
110
+ # OK). Signals are encoded to be distinguishable from "normal" messages.
111
+ # @param status [Integer, #to_int, #to_i]
112
+ # @return [CZMQ::Zmsg]
113
+ def self.new_signal(status)
114
+ status = Integer(status)
115
+ ptr = ::CZMQ::FFI.zmsg_new_signal(status)
116
+ __new ptr
117
+ end
118
+
119
+ # Destroy a message object and all frames it contains
120
+ #
121
+ # @return [void]
122
+ def destroy()
123
+ return unless @ptr
124
+ self_p = __ptr_give_ref
125
+ result = ::CZMQ::FFI.zmsg_destroy(self_p)
126
+ result
127
+ end
128
+
129
+ # Send message to destination socket, and destroy the message after sending
130
+ # it successfully. If the message has no frames, sends nothing but destroys
131
+ # the message anyhow. Nullifies the caller's reference to the message (as
132
+ # it is a destructor).
133
+ #
134
+ # @param self_p [#__ptr_give_ref]
135
+ # @param dest [::FFI::Pointer, #to_ptr]
136
+ # @return [Integer]
137
+ def self.send(self_p, dest)
138
+ self_p = self_p.__ptr_give_ref
139
+ result = ::CZMQ::FFI.zmsg_send(self_p, dest)
140
+ result
141
+ end
142
+
143
+ # Send message to destination socket as part of a multipart sequence, and
144
+ # destroy the message after sending it successfully. Note that after a
145
+ # zmsg_sendm, you must call zmsg_send or another method that sends a final
146
+ # message part. If the message has no frames, sends nothing but destroys
147
+ # the message anyhow. Nullifies the caller's reference to the message (as
148
+ # it is a destructor).
149
+ #
150
+ # @param self_p [#__ptr_give_ref]
151
+ # @param dest [::FFI::Pointer, #to_ptr]
152
+ # @return [Integer]
153
+ def self.sendm(self_p, dest)
154
+ self_p = self_p.__ptr_give_ref
155
+ result = ::CZMQ::FFI.zmsg_sendm(self_p, dest)
156
+ result
157
+ end
158
+
159
+ # Return size of message, i.e. number of frames (0 or more).
160
+ #
161
+ # @return [Integer]
162
+ def size()
163
+ raise DestroyedError unless @ptr
164
+ self_p = @ptr
165
+ result = ::CZMQ::FFI.zmsg_size(self_p)
166
+ result
167
+ end
168
+
169
+ # Return total size of all frames in message.
170
+ #
171
+ # @return [Integer]
172
+ def content_size()
173
+ raise DestroyedError unless @ptr
174
+ self_p = @ptr
175
+ result = ::CZMQ::FFI.zmsg_content_size(self_p)
176
+ result
177
+ end
178
+
179
+ # Return message routing ID, if the message came from a ZMQ_SERVER socket.
180
+ # Else returns zero.
181
+ #
182
+ # @return [Integer]
183
+ def routing_id()
184
+ raise DestroyedError unless @ptr
185
+ self_p = @ptr
186
+ result = ::CZMQ::FFI.zmsg_routing_id(self_p)
187
+ result
188
+ end
189
+
190
+ # Set routing ID on message. This is used if/when the message is sent to a
191
+ # ZMQ_SERVER socket.
192
+ #
193
+ # @param routing_id [Integer, #to_int, #to_i]
194
+ # @return [void]
195
+ def set_routing_id(routing_id)
196
+ raise DestroyedError unless @ptr
197
+ self_p = @ptr
198
+ routing_id = Integer(routing_id)
199
+ result = ::CZMQ::FFI.zmsg_set_routing_id(self_p, routing_id)
200
+ result
201
+ end
202
+
203
+ # Push frame to the front of the message, i.e. before all other frames.
204
+ # Message takes ownership of frame, will destroy it when message is sent.
205
+ # Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
206
+ # nullify the caller's frame reference.
207
+ #
208
+ # @param frame_p [#__ptr_give_ref]
209
+ # @return [Integer]
210
+ def prepend(frame_p)
211
+ raise DestroyedError unless @ptr
212
+ self_p = @ptr
213
+ frame_p = frame_p.__ptr_give_ref
214
+ result = ::CZMQ::FFI.zmsg_prepend(self_p, frame_p)
215
+ result
216
+ end
217
+
218
+ # Add frame to the end of the message, i.e. after all other frames.
219
+ # Message takes ownership of frame, will destroy it when message is sent.
220
+ # Returns 0 on success. Deprecates zmsg_add, which did not nullify the
221
+ # caller's frame reference.
222
+ #
223
+ # @param frame_p [#__ptr_give_ref]
224
+ # @return [Integer]
225
+ def append(frame_p)
226
+ raise DestroyedError unless @ptr
227
+ self_p = @ptr
228
+ frame_p = frame_p.__ptr_give_ref
229
+ result = ::CZMQ::FFI.zmsg_append(self_p, frame_p)
230
+ result
231
+ end
232
+
233
+ # Remove first frame from message, if any. Returns frame, or NULL.
234
+ #
235
+ # @return [Zframe]
236
+ def pop()
237
+ raise DestroyedError unless @ptr
238
+ self_p = @ptr
239
+ result = ::CZMQ::FFI.zmsg_pop(self_p)
240
+ result = Zframe.__new result, true
241
+ result
242
+ end
243
+
244
+ # Push block of memory to front of message, as a new frame.
245
+ # Returns 0 on success, -1 on error.
246
+ #
247
+ # @param src [::FFI::Pointer, #to_ptr]
248
+ # @param size [Integer, #to_int, #to_i]
249
+ # @return [Integer]
250
+ def pushmem(src, size)
251
+ raise DestroyedError unless @ptr
252
+ self_p = @ptr
253
+ size = Integer(size)
254
+ result = ::CZMQ::FFI.zmsg_pushmem(self_p, src, size)
255
+ result
256
+ end
257
+
258
+ # Add block of memory to the end of the message, as a new frame.
259
+ # Returns 0 on success, -1 on error.
260
+ #
261
+ # @param src [::FFI::Pointer, #to_ptr]
262
+ # @param size [Integer, #to_int, #to_i]
263
+ # @return [Integer]
264
+ def addmem(src, size)
265
+ raise DestroyedError unless @ptr
266
+ self_p = @ptr
267
+ size = Integer(size)
268
+ result = ::CZMQ::FFI.zmsg_addmem(self_p, src, size)
269
+ result
270
+ end
271
+
272
+ # Push string as new frame to front of message.
273
+ # Returns 0 on success, -1 on error.
274
+ #
275
+ # @param string [String, #to_str, #to_s]
276
+ # @return [Integer]
277
+ def pushstr(string)
278
+ raise DestroyedError unless @ptr
279
+ self_p = @ptr
280
+ string = String(string)
281
+ result = ::CZMQ::FFI.zmsg_pushstr(self_p, string)
282
+ result
283
+ end
284
+
285
+ # Push string as new frame to end of message.
286
+ # Returns 0 on success, -1 on error.
287
+ #
288
+ # @param string [String, #to_str, #to_s]
289
+ # @return [Integer]
290
+ def addstr(string)
291
+ raise DestroyedError unless @ptr
292
+ self_p = @ptr
293
+ string = String(string)
294
+ result = ::CZMQ::FFI.zmsg_addstr(self_p, string)
295
+ result
296
+ end
297
+
298
+ # Push formatted string as new frame to front of message.
299
+ # Returns 0 on success, -1 on error.
300
+ #
301
+ # @param format [String, #to_str, #to_s]
302
+ # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
303
+ # @return [Integer]
304
+ def pushstrf(format, *args)
305
+ raise DestroyedError unless @ptr
306
+ self_p = @ptr
307
+ format = String(format)
308
+ result = ::CZMQ::FFI.zmsg_pushstrf(self_p, format, *args)
309
+ result
310
+ end
311
+
312
+ # Push formatted string as new frame to end of message.
313
+ # Returns 0 on success, -1 on error.
314
+ #
315
+ # @param format [String, #to_str, #to_s]
316
+ # @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
317
+ # @return [Integer]
318
+ def addstrf(format, *args)
319
+ raise DestroyedError unless @ptr
320
+ self_p = @ptr
321
+ format = String(format)
322
+ result = ::CZMQ::FFI.zmsg_addstrf(self_p, format, *args)
323
+ result
324
+ end
325
+
326
+ # Pop frame off front of message, return as fresh string. If there were
327
+ # no more frames in the message, returns NULL.
328
+ #
329
+ # @return [::FFI::AutoPointer]
330
+ def popstr()
331
+ raise DestroyedError unless @ptr
332
+ self_p = @ptr
333
+ result = ::CZMQ::FFI.zmsg_popstr(self_p)
334
+ result = ::FFI::AutoPointer.new(result, LibC.method(:free))
335
+ result
336
+ end
337
+
338
+ # Push encoded message as a new frame. Message takes ownership of
339
+ # submessage, so the original is destroyed in this call. Returns 0 on
340
+ # success, -1 on error.
341
+ #
342
+ # @param msg_p [#__ptr_give_ref]
343
+ # @return [Integer]
344
+ def addmsg(msg_p)
345
+ raise DestroyedError unless @ptr
346
+ self_p = @ptr
347
+ msg_p = msg_p.__ptr_give_ref
348
+ result = ::CZMQ::FFI.zmsg_addmsg(self_p, msg_p)
349
+ result
350
+ end
351
+
352
+ # Remove first submessage from message, if any. Returns zmsg_t, or NULL if
353
+ # decoding was not succesful.
354
+ #
355
+ # @return [Zmsg]
356
+ def popmsg()
357
+ raise DestroyedError unless @ptr
358
+ self_p = @ptr
359
+ result = ::CZMQ::FFI.zmsg_popmsg(self_p)
360
+ result = Zmsg.__new result, true
361
+ result
362
+ end
363
+
364
+ # Remove specified frame from list, if present. Does not destroy frame.
365
+ #
366
+ # @param frame [Zframe, #__ptr]
367
+ # @return [void]
368
+ def remove(frame)
369
+ raise DestroyedError unless @ptr
370
+ self_p = @ptr
371
+ frame = frame.__ptr if frame
372
+ result = ::CZMQ::FFI.zmsg_remove(self_p, frame)
373
+ result
374
+ end
375
+
376
+ # Set cursor to first frame in message. Returns frame, or NULL, if the
377
+ # message is empty. Use this to navigate the frames as a list.
378
+ #
379
+ # @return [Zframe]
380
+ def first()
381
+ raise DestroyedError unless @ptr
382
+ self_p = @ptr
383
+ result = ::CZMQ::FFI.zmsg_first(self_p)
384
+ result = Zframe.__new result, false
385
+ result
386
+ end
387
+
388
+ # Return the next frame. If there are no more frames, returns NULL. To move
389
+ # to the first frame call zmsg_first(). Advances the cursor.
390
+ #
391
+ # @return [Zframe]
392
+ def next()
393
+ raise DestroyedError unless @ptr
394
+ self_p = @ptr
395
+ result = ::CZMQ::FFI.zmsg_next(self_p)
396
+ result = Zframe.__new result, false
397
+ result
398
+ end
399
+
400
+ # Return the last frame. If there are no frames, returns NULL.
401
+ #
402
+ # @return [Zframe]
403
+ def last()
404
+ raise DestroyedError unless @ptr
405
+ self_p = @ptr
406
+ result = ::CZMQ::FFI.zmsg_last(self_p)
407
+ result = Zframe.__new result, false
408
+ result
409
+ end
410
+
411
+ # Save message to an open file, return 0 if OK, else -1. The message is
412
+ # saved as a series of frames, each with length and data. Note that the
413
+ # file is NOT guaranteed to be portable between operating systems, not
414
+ # versions of CZMQ. The file format is at present undocumented and liable
415
+ # to arbitrary change.
416
+ #
417
+ # @param file [::FFI::Pointer, #to_ptr]
418
+ # @return [Integer]
419
+ def save(file)
420
+ raise DestroyedError unless @ptr
421
+ self_p = @ptr
422
+ result = ::CZMQ::FFI.zmsg_save(self_p, file)
423
+ result
424
+ end
425
+
426
+ # Serialize multipart message to a single buffer. Use this method to send
427
+ # structured messages across transports that do not support multipart data.
428
+ # Allocates and returns a new buffer containing the serialized message.
429
+ # To decode a serialized message buffer, use zmsg_decode ().
430
+ #
431
+ # @param buffer [::FFI::Pointer, #to_ptr]
432
+ # @return [Integer]
433
+ def encode(buffer)
434
+ raise DestroyedError unless @ptr
435
+ self_p = @ptr
436
+ result = ::CZMQ::FFI.zmsg_encode(self_p, buffer)
437
+ result
438
+ end
439
+
440
+ # Create copy of message, as new message object. Returns a fresh zmsg_t
441
+ # object. If message is null, or memory was exhausted, returns null.
442
+ #
443
+ # @return [Zmsg]
444
+ def dup()
445
+ raise DestroyedError unless @ptr
446
+ self_p = @ptr
447
+ result = ::CZMQ::FFI.zmsg_dup(self_p)
448
+ result = Zmsg.__new result, true
449
+ result
450
+ end
451
+
452
+ # Send message to zsys log sink (may be stdout, or system facility as
453
+ # configured by zsys_set_logstream).
454
+ #
455
+ # @return [void]
456
+ def print()
457
+ raise DestroyedError unless @ptr
458
+ self_p = @ptr
459
+ result = ::CZMQ::FFI.zmsg_print(self_p)
460
+ result
461
+ end
462
+
463
+ # Return true if the two messages have the same number of frames and each
464
+ # frame in the first message is identical to the corresponding frame in the
465
+ # other message. As with zframe_eq, return false if either message is NULL.
466
+ #
467
+ # @param other [Zmsg, #__ptr]
468
+ # @return [Boolean]
469
+ def eq(other)
470
+ raise DestroyedError unless @ptr
471
+ self_p = @ptr
472
+ other = other.__ptr if other
473
+ result = ::CZMQ::FFI.zmsg_eq(self_p, other)
474
+ result
475
+ end
476
+
477
+ # Return signal value, 0 or greater, if message is a signal, -1 if not.
478
+ #
479
+ # @return [Integer]
480
+ def signal()
481
+ raise DestroyedError unless @ptr
482
+ self_p = @ptr
483
+ result = ::CZMQ::FFI.zmsg_signal(self_p)
484
+ result
485
+ end
486
+
487
+ # Probe the supplied object, and report if it looks like a zmsg_t.
488
+ #
489
+ # @param self_ [::FFI::Pointer, #to_ptr]
490
+ # @return [Boolean]
491
+ def self.is(self_)
492
+ result = ::CZMQ::FFI.zmsg_is(self_)
493
+ result
494
+ end
495
+
496
+ # Self test of this class.
497
+ #
498
+ # @param verbose [Boolean]
499
+ # @return [void]
500
+ def self.test(verbose)
501
+ verbose = !(0==verbose||!verbose) # boolean
502
+ result = ::CZMQ::FFI.zmsg_test(verbose)
503
+ result
504
+ end
505
+ end
506
+ end
507
+ end
508
+
509
+ ################################################################################
510
+ # THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
511
+ # Please refer to the README for information about making permanent changes. #
512
+ ################################################################################