czmq-ffi-gen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/czmq-ffi-gen.rb +4 -0
- data/lib/czmq-ffi-gen/czmq/ffi.rb +558 -0
- data/lib/czmq-ffi-gen/czmq/ffi/version.rb +15 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zactor.rb +179 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zarmour.rb +259 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zconfig.rb +449 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zdir.rb +280 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zdir_patch.rb +182 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zfile.rb +347 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zframe.rb +311 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhash.rb +421 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zhashx.rb +595 -0
- data/lib/czmq-ffi-gen/czmq/ffi/ziflist.rb +182 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zlist.rb +355 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zloop.rb +385 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zmsg.rb +512 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zpoller.rb +184 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zsock.rb +3242 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zstr.rb +201 -0
- data/lib/czmq-ffi-gen/czmq/ffi/ztrie.rb +217 -0
- data/lib/czmq-ffi-gen/czmq/ffi/zuuid.rb +221 -0
- data/lib/czmq-ffi-gen/gem_version.rb +5 -0
- data/lib/czmq-ffi-gen/library_version.rb +5 -0
- metadata +138 -0
@@ -0,0 +1,311 @@
|
|
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 single message frames
|
10
|
+
# @note This class is 100% generated using zproject.
|
11
|
+
class Zframe
|
12
|
+
# Raised when one tries to use an instance of {Zframe} 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.zframe_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 frame. If size is not null, allocates the frame data
|
70
|
+
# to the specified size. If additionally, data is not null, copies
|
71
|
+
# size octets from the specified data into the frame body.
|
72
|
+
# @param data [::FFI::Pointer, #to_ptr]
|
73
|
+
# @param size [Integer, #to_int, #to_i]
|
74
|
+
# @return [CZMQ::Zframe]
|
75
|
+
def self.new(data, size)
|
76
|
+
size = Integer(size)
|
77
|
+
ptr = ::CZMQ::FFI.zframe_new(data, size)
|
78
|
+
__new ptr
|
79
|
+
end
|
80
|
+
|
81
|
+
# Create an empty (zero-sized) frame
|
82
|
+
# @return [CZMQ::Zframe]
|
83
|
+
def self.new_empty()
|
84
|
+
ptr = ::CZMQ::FFI.zframe_new_empty()
|
85
|
+
__new ptr
|
86
|
+
end
|
87
|
+
|
88
|
+
# Create a frame with a specified string content.
|
89
|
+
# @param string [String, #to_str, #to_s]
|
90
|
+
# @return [CZMQ::Zframe]
|
91
|
+
def self.from(string)
|
92
|
+
string = String(string)
|
93
|
+
ptr = ::CZMQ::FFI.zframe_from(string)
|
94
|
+
__new ptr
|
95
|
+
end
|
96
|
+
|
97
|
+
# Receive frame from socket, returns zframe_t object or NULL if the recv
|
98
|
+
# was interrupted. Does a blocking recv, if you want to not block then use
|
99
|
+
# zpoller or zloop.
|
100
|
+
# @param source [::FFI::Pointer, #to_ptr]
|
101
|
+
# @return [CZMQ::Zframe]
|
102
|
+
def self.recv(source)
|
103
|
+
ptr = ::CZMQ::FFI.zframe_recv(source)
|
104
|
+
__new ptr
|
105
|
+
end
|
106
|
+
|
107
|
+
# Destroy a frame
|
108
|
+
#
|
109
|
+
# @return [void]
|
110
|
+
def destroy()
|
111
|
+
return unless @ptr
|
112
|
+
self_p = __ptr_give_ref
|
113
|
+
result = ::CZMQ::FFI.zframe_destroy(self_p)
|
114
|
+
result
|
115
|
+
end
|
116
|
+
|
117
|
+
# Send a frame to a socket, destroy frame after sending.
|
118
|
+
# Return -1 on error, 0 on success.
|
119
|
+
#
|
120
|
+
# @param self_p [#__ptr_give_ref]
|
121
|
+
# @param dest [::FFI::Pointer, #to_ptr]
|
122
|
+
# @param flags [Integer, #to_int, #to_i]
|
123
|
+
# @return [Integer]
|
124
|
+
def self.send(self_p, dest, flags)
|
125
|
+
self_p = self_p.__ptr_give_ref
|
126
|
+
flags = Integer(flags)
|
127
|
+
result = ::CZMQ::FFI.zframe_send(self_p, dest, flags)
|
128
|
+
result
|
129
|
+
end
|
130
|
+
|
131
|
+
# Return number of bytes in frame data
|
132
|
+
#
|
133
|
+
# @return [Integer]
|
134
|
+
def size()
|
135
|
+
raise DestroyedError unless @ptr
|
136
|
+
self_p = @ptr
|
137
|
+
result = ::CZMQ::FFI.zframe_size(self_p)
|
138
|
+
result
|
139
|
+
end
|
140
|
+
|
141
|
+
# Return address of frame data
|
142
|
+
#
|
143
|
+
# @return [::FFI::Pointer]
|
144
|
+
def data()
|
145
|
+
raise DestroyedError unless @ptr
|
146
|
+
self_p = @ptr
|
147
|
+
result = ::CZMQ::FFI.zframe_data(self_p)
|
148
|
+
result
|
149
|
+
end
|
150
|
+
|
151
|
+
# Create a new frame that duplicates an existing frame. If frame is null,
|
152
|
+
# or memory was exhausted, returns null.
|
153
|
+
#
|
154
|
+
# @return [Zframe]
|
155
|
+
def dup()
|
156
|
+
raise DestroyedError unless @ptr
|
157
|
+
self_p = @ptr
|
158
|
+
result = ::CZMQ::FFI.zframe_dup(self_p)
|
159
|
+
result = Zframe.__new result, true
|
160
|
+
result
|
161
|
+
end
|
162
|
+
|
163
|
+
# Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
|
164
|
+
# Caller must free string when finished with it.
|
165
|
+
#
|
166
|
+
# @return [::FFI::AutoPointer]
|
167
|
+
def strhex()
|
168
|
+
raise DestroyedError unless @ptr
|
169
|
+
self_p = @ptr
|
170
|
+
result = ::CZMQ::FFI.zframe_strhex(self_p)
|
171
|
+
result = ::FFI::AutoPointer.new(result, LibC.method(:free))
|
172
|
+
result
|
173
|
+
end
|
174
|
+
|
175
|
+
# Return frame data copied into freshly allocated string
|
176
|
+
# Caller must free string when finished with it.
|
177
|
+
#
|
178
|
+
# @return [::FFI::AutoPointer]
|
179
|
+
def strdup()
|
180
|
+
raise DestroyedError unless @ptr
|
181
|
+
self_p = @ptr
|
182
|
+
result = ::CZMQ::FFI.zframe_strdup(self_p)
|
183
|
+
result = ::FFI::AutoPointer.new(result, LibC.method(:free))
|
184
|
+
result
|
185
|
+
end
|
186
|
+
|
187
|
+
# Return TRUE if frame body is equal to string, excluding terminator
|
188
|
+
#
|
189
|
+
# @param string [String, #to_str, #to_s]
|
190
|
+
# @return [Boolean]
|
191
|
+
def streq(string)
|
192
|
+
raise DestroyedError unless @ptr
|
193
|
+
self_p = @ptr
|
194
|
+
string = String(string)
|
195
|
+
result = ::CZMQ::FFI.zframe_streq(self_p, string)
|
196
|
+
result
|
197
|
+
end
|
198
|
+
|
199
|
+
# Return frame MORE indicator (1 or 0), set when reading frame from socket
|
200
|
+
# or by the zframe_set_more() method
|
201
|
+
#
|
202
|
+
# @return [Integer]
|
203
|
+
def more()
|
204
|
+
raise DestroyedError unless @ptr
|
205
|
+
self_p = @ptr
|
206
|
+
result = ::CZMQ::FFI.zframe_more(self_p)
|
207
|
+
result
|
208
|
+
end
|
209
|
+
|
210
|
+
# Set frame MORE indicator (1 or 0). Note this is NOT used when sending
|
211
|
+
# frame to socket, you have to specify flag explicitly.
|
212
|
+
#
|
213
|
+
# @param more [Integer, #to_int, #to_i]
|
214
|
+
# @return [void]
|
215
|
+
def set_more(more)
|
216
|
+
raise DestroyedError unless @ptr
|
217
|
+
self_p = @ptr
|
218
|
+
more = Integer(more)
|
219
|
+
result = ::CZMQ::FFI.zframe_set_more(self_p, more)
|
220
|
+
result
|
221
|
+
end
|
222
|
+
|
223
|
+
# Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
|
224
|
+
# Else returns zero.
|
225
|
+
#
|
226
|
+
# @return [Integer]
|
227
|
+
def routing_id()
|
228
|
+
raise DestroyedError unless @ptr
|
229
|
+
self_p = @ptr
|
230
|
+
result = ::CZMQ::FFI.zframe_routing_id(self_p)
|
231
|
+
result
|
232
|
+
end
|
233
|
+
|
234
|
+
# Set routing ID on frame. This is used if/when the frame is sent to a
|
235
|
+
# ZMQ_SERVER socket.
|
236
|
+
#
|
237
|
+
# @param routing_id [Integer, #to_int, #to_i]
|
238
|
+
# @return [void]
|
239
|
+
def set_routing_id(routing_id)
|
240
|
+
raise DestroyedError unless @ptr
|
241
|
+
self_p = @ptr
|
242
|
+
routing_id = Integer(routing_id)
|
243
|
+
result = ::CZMQ::FFI.zframe_set_routing_id(self_p, routing_id)
|
244
|
+
result
|
245
|
+
end
|
246
|
+
|
247
|
+
# Return TRUE if two frames have identical size and data
|
248
|
+
# If either frame is NULL, equality is always false.
|
249
|
+
#
|
250
|
+
# @param other [Zframe, #__ptr]
|
251
|
+
# @return [Boolean]
|
252
|
+
def eq(other)
|
253
|
+
raise DestroyedError unless @ptr
|
254
|
+
self_p = @ptr
|
255
|
+
other = other.__ptr if other
|
256
|
+
result = ::CZMQ::FFI.zframe_eq(self_p, other)
|
257
|
+
result
|
258
|
+
end
|
259
|
+
|
260
|
+
# Set new contents for frame
|
261
|
+
#
|
262
|
+
# @param data [::FFI::Pointer, #to_ptr]
|
263
|
+
# @param size [Integer, #to_int, #to_i]
|
264
|
+
# @return [void]
|
265
|
+
def reset(data, size)
|
266
|
+
raise DestroyedError unless @ptr
|
267
|
+
self_p = @ptr
|
268
|
+
size = Integer(size)
|
269
|
+
result = ::CZMQ::FFI.zframe_reset(self_p, data, size)
|
270
|
+
result
|
271
|
+
end
|
272
|
+
|
273
|
+
# Send message to zsys log sink (may be stdout, or system facility as
|
274
|
+
# configured by zsys_set_logstream). Prefix shows before frame, if not null.
|
275
|
+
#
|
276
|
+
# @param prefix [String, #to_str, #to_s]
|
277
|
+
# @return [void]
|
278
|
+
def print(prefix)
|
279
|
+
raise DestroyedError unless @ptr
|
280
|
+
self_p = @ptr
|
281
|
+
prefix = String(prefix)
|
282
|
+
result = ::CZMQ::FFI.zframe_print(self_p, prefix)
|
283
|
+
result
|
284
|
+
end
|
285
|
+
|
286
|
+
# Probe the supplied object, and report if it looks like a zframe_t.
|
287
|
+
#
|
288
|
+
# @param self_ [::FFI::Pointer, #to_ptr]
|
289
|
+
# @return [Boolean]
|
290
|
+
def self.is(self_)
|
291
|
+
result = ::CZMQ::FFI.zframe_is(self_)
|
292
|
+
result
|
293
|
+
end
|
294
|
+
|
295
|
+
# Self test of this class.
|
296
|
+
#
|
297
|
+
# @param verbose [Boolean]
|
298
|
+
# @return [void]
|
299
|
+
def self.test(verbose)
|
300
|
+
verbose = !(0==verbose||!verbose) # boolean
|
301
|
+
result = ::CZMQ::FFI.zframe_test(verbose)
|
302
|
+
result
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
################################################################################
|
309
|
+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
|
310
|
+
# Please refer to the README for information about making permanent changes. #
|
311
|
+
################################################################################
|
@@ -0,0 +1,421 @@
|
|
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
|
+
# generic type-free hash container (simple)
|
10
|
+
# @note This class is 100% generated using zproject.
|
11
|
+
class Zhash
|
12
|
+
# Raised when one tries to use an instance of {Zhash} 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.zhash_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 zhash_freefn method
|
71
|
+
# typedef void (zhash_free_fn) (
|
72
|
+
# void *data);
|
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.free_fn
|
79
|
+
::FFI::Function.new :void, [:pointer], blocking: true do |data|
|
80
|
+
result = yield data
|
81
|
+
result
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Create a new callback of the following type:
|
86
|
+
# DEPRECATED as clumsy -- use zhash_first/_next instead
|
87
|
+
# typedef int (zhash_foreach_fn) (
|
88
|
+
# const char *key, void *item, void *argument);
|
89
|
+
#
|
90
|
+
# @note WARNING: If your Ruby code doesn't retain a reference to the
|
91
|
+
# FFI::Function object after passing it to a C function call,
|
92
|
+
# it may be garbage collected while C still holds the pointer,
|
93
|
+
# potentially resulting in a segmentation fault.
|
94
|
+
def self.foreach_fn
|
95
|
+
::FFI::Function.new :int, [:string, :pointer, :pointer], blocking: true do |key, item, argument|
|
96
|
+
result = yield key, item, argument
|
97
|
+
result = Integer(result)
|
98
|
+
result
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Create a new, empty hash container
|
103
|
+
# @return [CZMQ::Zhash]
|
104
|
+
def self.new()
|
105
|
+
ptr = ::CZMQ::FFI.zhash_new()
|
106
|
+
__new ptr
|
107
|
+
end
|
108
|
+
|
109
|
+
# Unpack binary frame into a new hash table. Packed data must follow format
|
110
|
+
# defined by zhash_pack. Hash table is set to autofree. An empty frame
|
111
|
+
# unpacks to an empty hash table.
|
112
|
+
# @param frame [Zframe, #__ptr]
|
113
|
+
# @return [CZMQ::Zhash]
|
114
|
+
def self.unpack(frame)
|
115
|
+
frame = frame.__ptr if frame
|
116
|
+
ptr = ::CZMQ::FFI.zhash_unpack(frame)
|
117
|
+
__new ptr
|
118
|
+
end
|
119
|
+
|
120
|
+
# Destroy a hash container and all items in it
|
121
|
+
#
|
122
|
+
# @return [void]
|
123
|
+
def destroy()
|
124
|
+
return unless @ptr
|
125
|
+
self_p = __ptr_give_ref
|
126
|
+
result = ::CZMQ::FFI.zhash_destroy(self_p)
|
127
|
+
result
|
128
|
+
end
|
129
|
+
|
130
|
+
# Insert item into hash table with specified key and item.
|
131
|
+
# If key is already present returns -1 and leaves existing item unchanged
|
132
|
+
# Returns 0 on success.
|
133
|
+
#
|
134
|
+
# @param key [String, #to_str, #to_s]
|
135
|
+
# @param item [::FFI::Pointer, #to_ptr]
|
136
|
+
# @return [Integer]
|
137
|
+
def insert(key, item)
|
138
|
+
raise DestroyedError unless @ptr
|
139
|
+
self_p = @ptr
|
140
|
+
key = String(key)
|
141
|
+
result = ::CZMQ::FFI.zhash_insert(self_p, key, item)
|
142
|
+
result
|
143
|
+
end
|
144
|
+
|
145
|
+
# Update item into hash table with specified key and item.
|
146
|
+
# If key is already present, destroys old item and inserts new one.
|
147
|
+
# Use free_fn method to ensure deallocator is properly called on item.
|
148
|
+
#
|
149
|
+
# @param key [String, #to_str, #to_s]
|
150
|
+
# @param item [::FFI::Pointer, #to_ptr]
|
151
|
+
# @return [void]
|
152
|
+
def update(key, item)
|
153
|
+
raise DestroyedError unless @ptr
|
154
|
+
self_p = @ptr
|
155
|
+
key = String(key)
|
156
|
+
result = ::CZMQ::FFI.zhash_update(self_p, key, item)
|
157
|
+
result
|
158
|
+
end
|
159
|
+
|
160
|
+
# Remove an item specified by key from the hash table. If there was no such
|
161
|
+
# item, this function does nothing.
|
162
|
+
#
|
163
|
+
# @param key [String, #to_str, #to_s]
|
164
|
+
# @return [void]
|
165
|
+
def delete(key)
|
166
|
+
raise DestroyedError unless @ptr
|
167
|
+
self_p = @ptr
|
168
|
+
key = String(key)
|
169
|
+
result = ::CZMQ::FFI.zhash_delete(self_p, key)
|
170
|
+
result
|
171
|
+
end
|
172
|
+
|
173
|
+
# Return the item at the specified key, or null
|
174
|
+
#
|
175
|
+
# @param key [String, #to_str, #to_s]
|
176
|
+
# @return [::FFI::Pointer]
|
177
|
+
def lookup(key)
|
178
|
+
raise DestroyedError unless @ptr
|
179
|
+
self_p = @ptr
|
180
|
+
key = String(key)
|
181
|
+
result = ::CZMQ::FFI.zhash_lookup(self_p, key)
|
182
|
+
result
|
183
|
+
end
|
184
|
+
|
185
|
+
# Reindexes an item from an old key to a new key. If there was no such
|
186
|
+
# item, does nothing. Returns 0 if successful, else -1.
|
187
|
+
#
|
188
|
+
# @param old_key [String, #to_str, #to_s]
|
189
|
+
# @param new_key [String, #to_str, #to_s]
|
190
|
+
# @return [Integer]
|
191
|
+
def rename(old_key, new_key)
|
192
|
+
raise DestroyedError unless @ptr
|
193
|
+
self_p = @ptr
|
194
|
+
old_key = String(old_key)
|
195
|
+
new_key = String(new_key)
|
196
|
+
result = ::CZMQ::FFI.zhash_rename(self_p, old_key, new_key)
|
197
|
+
result
|
198
|
+
end
|
199
|
+
|
200
|
+
# Set a free function for the specified hash table item. When the item is
|
201
|
+
# destroyed, the free function, if any, is called on that item.
|
202
|
+
# Use this when hash items are dynamically allocated, to ensure that
|
203
|
+
# you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
|
204
|
+
# Returns the item, or NULL if there is no such item.
|
205
|
+
#
|
206
|
+
# @param key [String, #to_str, #to_s]
|
207
|
+
# @param free_fn [::FFI::Pointer, #to_ptr]
|
208
|
+
# @return [::FFI::Pointer]
|
209
|
+
def freefn(key, free_fn)
|
210
|
+
raise DestroyedError unless @ptr
|
211
|
+
self_p = @ptr
|
212
|
+
key = String(key)
|
213
|
+
result = ::CZMQ::FFI.zhash_freefn(self_p, key, free_fn)
|
214
|
+
result
|
215
|
+
end
|
216
|
+
|
217
|
+
# Return the number of keys/items in the hash table
|
218
|
+
#
|
219
|
+
# @return [Integer]
|
220
|
+
def size()
|
221
|
+
raise DestroyedError unless @ptr
|
222
|
+
self_p = @ptr
|
223
|
+
result = ::CZMQ::FFI.zhash_size(self_p)
|
224
|
+
result
|
225
|
+
end
|
226
|
+
|
227
|
+
# Make copy of hash table; if supplied table is null, returns null.
|
228
|
+
# Does not copy items themselves. Rebuilds new table so may be slow on
|
229
|
+
# very large tables. NOTE: only works with item values that are strings
|
230
|
+
# since there's no other way to know how to duplicate the item value.
|
231
|
+
#
|
232
|
+
# @return [Zhash]
|
233
|
+
def dup()
|
234
|
+
raise DestroyedError unless @ptr
|
235
|
+
self_p = @ptr
|
236
|
+
result = ::CZMQ::FFI.zhash_dup(self_p)
|
237
|
+
result = Zhash.__new result, true
|
238
|
+
result
|
239
|
+
end
|
240
|
+
|
241
|
+
# Return keys for items in table
|
242
|
+
#
|
243
|
+
# @return [Zlist]
|
244
|
+
def keys()
|
245
|
+
raise DestroyedError unless @ptr
|
246
|
+
self_p = @ptr
|
247
|
+
result = ::CZMQ::FFI.zhash_keys(self_p)
|
248
|
+
result = Zlist.__new result, true
|
249
|
+
result
|
250
|
+
end
|
251
|
+
|
252
|
+
# Simple iterator; returns first item in hash table, in no given order,
|
253
|
+
# or NULL if the table is empty. This method is simpler to use than the
|
254
|
+
# foreach() method, which is deprecated. To access the key for this item
|
255
|
+
# use zhash_cursor(). NOTE: do NOT modify the table while iterating.
|
256
|
+
#
|
257
|
+
# @return [::FFI::Pointer]
|
258
|
+
def first()
|
259
|
+
raise DestroyedError unless @ptr
|
260
|
+
self_p = @ptr
|
261
|
+
result = ::CZMQ::FFI.zhash_first(self_p)
|
262
|
+
result
|
263
|
+
end
|
264
|
+
|
265
|
+
# Simple iterator; returns next item in hash table, in no given order,
|
266
|
+
# or NULL if the last item was already returned. Use this together with
|
267
|
+
# zhash_first() to process all items in a hash table. If you need the
|
268
|
+
# items in sorted order, use zhash_keys() and then zlist_sort(). To
|
269
|
+
# access the key for this item use zhash_cursor(). NOTE: do NOT modify
|
270
|
+
# the table while iterating.
|
271
|
+
#
|
272
|
+
# @return [::FFI::Pointer]
|
273
|
+
def next()
|
274
|
+
raise DestroyedError unless @ptr
|
275
|
+
self_p = @ptr
|
276
|
+
result = ::CZMQ::FFI.zhash_next(self_p)
|
277
|
+
result
|
278
|
+
end
|
279
|
+
|
280
|
+
# After a successful first/next method, returns the key for the item that
|
281
|
+
# was returned. This is a constant string that you may not modify or
|
282
|
+
# deallocate, and which lasts as long as the item in the hash. After an
|
283
|
+
# unsuccessful first/next, returns NULL.
|
284
|
+
#
|
285
|
+
# @return [String]
|
286
|
+
def cursor()
|
287
|
+
raise DestroyedError unless @ptr
|
288
|
+
self_p = @ptr
|
289
|
+
result = ::CZMQ::FFI.zhash_cursor(self_p)
|
290
|
+
result
|
291
|
+
end
|
292
|
+
|
293
|
+
# Add a comment to hash table before saving to disk. You can add as many
|
294
|
+
# comment lines as you like. These comment lines are discarded when loading
|
295
|
+
# the file. If you use a null format, all comments are deleted.
|
296
|
+
#
|
297
|
+
# @param format [String, #to_str, #to_s]
|
298
|
+
# @param args [Array<Object>] see https://github.com/ffi/ffi/wiki/examples#using-varargs
|
299
|
+
# @return [void]
|
300
|
+
def comment(format, *args)
|
301
|
+
raise DestroyedError unless @ptr
|
302
|
+
self_p = @ptr
|
303
|
+
format = String(format)
|
304
|
+
result = ::CZMQ::FFI.zhash_comment(self_p, format, *args)
|
305
|
+
result
|
306
|
+
end
|
307
|
+
|
308
|
+
# Serialize hash table to a binary frame that can be sent in a message.
|
309
|
+
# The packed format is compatible with the 'dictionary' type defined in
|
310
|
+
# http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
|
311
|
+
#
|
312
|
+
# ; A list of name/value pairs
|
313
|
+
# dictionary = dict-count *( dict-name dict-value )
|
314
|
+
# dict-count = number-4
|
315
|
+
# dict-value = longstr
|
316
|
+
# dict-name = string
|
317
|
+
#
|
318
|
+
# ; Strings are always length + text contents
|
319
|
+
# longstr = number-4 *VCHAR
|
320
|
+
# string = number-1 *VCHAR
|
321
|
+
#
|
322
|
+
# ; Numbers are unsigned integers in network byte order
|
323
|
+
# number-1 = 1OCTET
|
324
|
+
# number-4 = 4OCTET
|
325
|
+
#
|
326
|
+
# Comments are not included in the packed data. Item values MUST be
|
327
|
+
# strings.
|
328
|
+
#
|
329
|
+
# @return [Zframe]
|
330
|
+
def pack()
|
331
|
+
raise DestroyedError unless @ptr
|
332
|
+
self_p = @ptr
|
333
|
+
result = ::CZMQ::FFI.zhash_pack(self_p)
|
334
|
+
result = Zframe.__new result, true
|
335
|
+
result
|
336
|
+
end
|
337
|
+
|
338
|
+
# Save hash table to a text file in name=value format. Hash values must be
|
339
|
+
# printable strings; keys may not contain '=' character. Returns 0 if OK,
|
340
|
+
# else -1 if a file error occurred.
|
341
|
+
#
|
342
|
+
# @param filename [String, #to_str, #to_s]
|
343
|
+
# @return [Integer]
|
344
|
+
def save(filename)
|
345
|
+
raise DestroyedError unless @ptr
|
346
|
+
self_p = @ptr
|
347
|
+
filename = String(filename)
|
348
|
+
result = ::CZMQ::FFI.zhash_save(self_p, filename)
|
349
|
+
result
|
350
|
+
end
|
351
|
+
|
352
|
+
# Load hash table from a text file in name=value format; hash table must
|
353
|
+
# already exist. Hash values must printable strings; keys may not contain
|
354
|
+
# '=' character. Returns 0 if OK, else -1 if a file was not readable.
|
355
|
+
#
|
356
|
+
# @param filename [String, #to_str, #to_s]
|
357
|
+
# @return [Integer]
|
358
|
+
def load(filename)
|
359
|
+
raise DestroyedError unless @ptr
|
360
|
+
self_p = @ptr
|
361
|
+
filename = String(filename)
|
362
|
+
result = ::CZMQ::FFI.zhash_load(self_p, filename)
|
363
|
+
result
|
364
|
+
end
|
365
|
+
|
366
|
+
# When a hash table was loaded from a file by zhash_load, this method will
|
367
|
+
# reload the file if it has been modified since, and is "stable", i.e. not
|
368
|
+
# still changing. Returns 0 if OK, -1 if there was an error reloading the
|
369
|
+
# file.
|
370
|
+
#
|
371
|
+
# @return [Integer]
|
372
|
+
def refresh()
|
373
|
+
raise DestroyedError unless @ptr
|
374
|
+
self_p = @ptr
|
375
|
+
result = ::CZMQ::FFI.zhash_refresh(self_p)
|
376
|
+
result
|
377
|
+
end
|
378
|
+
|
379
|
+
# Set hash for automatic value destruction
|
380
|
+
#
|
381
|
+
# @return [void]
|
382
|
+
def autofree()
|
383
|
+
raise DestroyedError unless @ptr
|
384
|
+
self_p = @ptr
|
385
|
+
result = ::CZMQ::FFI.zhash_autofree(self_p)
|
386
|
+
result
|
387
|
+
end
|
388
|
+
|
389
|
+
# DEPRECATED as clumsy -- use zhash_first/_next instead
|
390
|
+
# Apply function to each item in the hash table. Items are iterated in no
|
391
|
+
# defined order. Stops if callback function returns non-zero and returns
|
392
|
+
# final return code from callback function (zero = success).
|
393
|
+
# Callback function for zhash_foreach method
|
394
|
+
#
|
395
|
+
# @param callback [::FFI::Pointer, #to_ptr]
|
396
|
+
# @param argument [::FFI::Pointer, #to_ptr]
|
397
|
+
# @return [Integer]
|
398
|
+
def foreach(callback, argument)
|
399
|
+
raise DestroyedError unless @ptr
|
400
|
+
self_p = @ptr
|
401
|
+
result = ::CZMQ::FFI.zhash_foreach(self_p, callback, argument)
|
402
|
+
result
|
403
|
+
end
|
404
|
+
|
405
|
+
# Self test of this class.
|
406
|
+
#
|
407
|
+
# @param verbose [Boolean]
|
408
|
+
# @return [void]
|
409
|
+
def self.test(verbose)
|
410
|
+
verbose = !(0==verbose||!verbose) # boolean
|
411
|
+
result = ::CZMQ::FFI.zhash_test(verbose)
|
412
|
+
result
|
413
|
+
end
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
################################################################################
|
419
|
+
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
|
420
|
+
# Please refer to the README for information about making permanent changes. #
|
421
|
+
################################################################################
|