Class: CZMQ::FFI::Zframe

Inherits:
Object
  • Object
show all
Defined in:
lib/czmq-ffi-gen/czmq/ffi/zframe.rb

Overview

Note:

This class is 100% generated using zproject.

working with single message frames

Defined Under Namespace

Classes: DestroyedError

Constant Summary collapse

MORE =
1
REUSE =
2
DONTWAIT =
4

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zframe

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


33
34
35
36
37
38
39
40
41
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 33

def initialize(ptr, finalize = true)
  @ptr = ptr
  if @ptr.null?
    @ptr = nil # Remove null pointers so we don't have to test for them.
  elsif finalize
    @finalizer = self.class.create_finalizer_for @ptr
    ObjectSpace.define_finalizer self, @finalizer
  end
end

Class Method Details

.__newObject



27
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 27

alias :__new :new

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


44
45
46
47
48
49
50
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 44

def self.create_finalizer_for(ptr)
  Proc.new do
    ptr_ptr = ::FFI::MemoryPointer.new :pointer
    ptr_ptr.write_pointer ptr
    ::CZMQ::FFI.zframe_destroy ptr_ptr
  end
end

.from(string) ⇒ CZMQ::Zframe

Create a frame with a specified string content.

Parameters:

  • string (String, #to_s, nil)

Returns:

  • (CZMQ::Zframe)


107
108
109
110
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 107

def self.from(string)
  ptr = ::CZMQ::FFI.zframe_from(string)
  __new ptr
end

.is(self_) ⇒ Boolean

Probe the supplied object, and report if it looks like a zframe_t.

Parameters:

  • self_ (::FFI::Pointer, #to_ptr)

Returns:

  • (Boolean)


339
340
341
342
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 339

def self.is(self_)
  result = ::CZMQ::FFI.zframe_is(self_)
  result
end

.new(data, size) ⇒ CZMQ::Zframe

Create a new frame. If size is not null, allocates the frame data to the specified size. If additionally, data is not null, copies size octets from the specified data into the frame body.

Parameters:

  • data (::FFI::Pointer, #to_ptr)
  • size (Integer, #to_int, #to_i)

Returns:

  • (CZMQ::Zframe)


91
92
93
94
95
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 91

def self.new(data, size)
  size = Integer(size)
  ptr = ::CZMQ::FFI.zframe_new(data, size)
  __new ptr
end

.new_emptyCZMQ::Zframe

Create an empty (zero-sized) frame

Returns:

  • (CZMQ::Zframe)


99
100
101
102
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 99

def self.new_empty()
  ptr = ::CZMQ::FFI.zframe_new_empty()
  __new ptr
end

.recv(source) ⇒ CZMQ::Zframe

Receive frame from socket, returns zframe_t object or NULL if the recv was interrupted. Does a blocking recv, if you want to not block then use zpoller or zloop.

Parameters:

  • source (::FFI::Pointer, #to_ptr)

Returns:

  • (CZMQ::Zframe)


117
118
119
120
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 117

def self.recv(source)
  ptr = ::CZMQ::FFI.zframe_recv(source)
  __new ptr
end

.send(self_p, dest, flags) ⇒ Integer

Send a frame to a socket, destroy frame after sending. Return -1 on error, 0 on success.

Parameters:

Returns:

  • (Integer)


139
140
141
142
143
144
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 139

def self.send(self_p, dest, flags)
  self_p = self_p.__ptr_give_ref
  flags = Integer(flags)
  result = ::CZMQ::FFI.zframe_send(self_p, dest, flags)
  result
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


348
349
350
351
352
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 348

def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zframe_test(verbose)
  result
end

Instance Method Details

#__ptr::FFI::Pointer Also known as: to_ptr

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



57
58
59
60
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 57

def __ptr
  raise DestroyedError unless @ptr
  @ptr
end

#__ptr_give_ref::FFI::MemoryPointer

Note:

This detaches the current instance from the native object and thus makes it unusable.

Nullify internal pointer and return pointer pointer.

Returns:

  • (::FFI::MemoryPointer)

    the pointer pointing to a pointer pointing to the native object

Raises:



68
69
70
71
72
73
74
75
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 68

def __ptr_give_ref
  raise DestroyedError unless @ptr
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
  ptr_ptr.write_pointer @ptr
  __undef_finalizer if @finalizer
  @ptr = nil
  ptr_ptr
end

#__undef_finalizervoid

Note:

Only use this if you need to and can guarantee that the native object will be freed by other means.

This method returns an undefined value.

Undefines the finalizer for this object.



80
81
82
83
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 80

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#data::FFI::Pointer

Return address of frame data

Returns:

  • (::FFI::Pointer)

Raises:



159
160
161
162
163
164
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 159

def data()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_data(self_p)
  result
end

#destroyvoid

This method returns an undefined value.

Destroy a frame



125
126
127
128
129
130
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 125

def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zframe_destroy(self_p)
  result
end

#dupZframe

Create a new frame that duplicates an existing frame. If frame is null, or memory was exhausted, returns null.

Returns:

Raises:



183
184
185
186
187
188
189
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 183

def dup()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_dup(self_p)
  result = Zframe.__new result, true
  result
end

#eq(other) ⇒ Boolean

Return TRUE if two frames have identical size and data If either frame is NULL, equality is always false.

Parameters:

Returns:

  • (Boolean)

Raises:



302
303
304
305
306
307
308
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 302

def eq(other)
  raise DestroyedError unless @ptr
  self_p = @ptr
  other = other.__ptr if other
  result = ::CZMQ::FFI.zframe_eq(self_p, other)
  result
end

#groupString

Return frame group of radio-dish pattern.

Returns:

  • (String)

Raises:



277
278
279
280
281
282
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 277

def group()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_group(self_p)
  result
end

#meta(property) ⇒ String

Return meta data property for frame The caller shall not modify or free the returned value, which shall be owned by the message.

Parameters:

  • property (String, #to_s, nil)

Returns:

  • (String)

Raises:



172
173
174
175
176
177
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 172

def meta(property)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_meta(self_p, property)
  result
end

#moreInteger

Return frame MORE indicator (1 or 0), set when reading frame from socket or by the zframe_set_more() method

Returns:

  • (Integer)

Raises:



230
231
232
233
234
235
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 230

def more()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_more(self_p)
  result
end

#null?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 52

def null?
  !@ptr or @ptr.null?
end

This method returns an undefined value.

Send message to zsys log sink (may be stdout, or system facility as configured by zsys_set_logstream). Prefix shows before frame, if not null.

Parameters:

  • prefix (String, #to_s, nil)

Raises:



328
329
330
331
332
333
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 328

def print(prefix)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_print(self_p, prefix)
  result
end

#reset(data, size) ⇒ void

This method returns an undefined value.

Set new contents for frame

Parameters:

  • data (::FFI::Pointer, #to_ptr)
  • size (Integer, #to_int, #to_i)

Raises:



315
316
317
318
319
320
321
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 315

def reset(data, size)
  raise DestroyedError unless @ptr
  self_p = @ptr
  size = Integer(size)
  result = ::CZMQ::FFI.zframe_reset(self_p, data, size)
  result
end

#routing_idInteger

Return frame routing ID, if the frame came from a ZMQ_SERVER socket. Else returns zero.

Returns:

  • (Integer)

Raises:



254
255
256
257
258
259
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 254

def routing_id()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_routing_id(self_p)
  result
end

#set_group(group) ⇒ Integer

Set group on frame. This is used if/when the frame is sent to a ZMQ_RADIO socket. Return -1 on error, 0 on success.

Parameters:

  • group (String, #to_s, nil)

Returns:

  • (Integer)

Raises:



290
291
292
293
294
295
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 290

def set_group(group)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_set_group(self_p, group)
  result
end

#set_more(more) ⇒ void

This method returns an undefined value.

Set frame MORE indicator (1 or 0). Note this is NOT used when sending frame to socket, you have to specify flag explicitly.

Parameters:

  • more (Integer, #to_int, #to_i)

Raises:



242
243
244
245
246
247
248
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 242

def set_more(more)
  raise DestroyedError unless @ptr
  self_p = @ptr
  more = Integer(more)
  result = ::CZMQ::FFI.zframe_set_more(self_p, more)
  result
end

#set_routing_id(routing_id) ⇒ void

This method returns an undefined value.

Set routing ID on frame. This is used if/when the frame is sent to a ZMQ_SERVER socket.

Parameters:

  • routing_id (Integer, #to_int, #to_i)

Raises:



266
267
268
269
270
271
272
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 266

def set_routing_id(routing_id)
  raise DestroyedError unless @ptr
  self_p = @ptr
  routing_id = Integer(routing_id)
  result = ::CZMQ::FFI.zframe_set_routing_id(self_p, routing_id)
  result
end

#sizeInteger

Return number of bytes in frame data

Returns:

  • (Integer)

Raises:



149
150
151
152
153
154
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 149

def size()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_size(self_p)
  result
end

#strdup::FFI::AutoPointer

Return frame data copied into freshly allocated string Caller must free string when finished with it.

Returns:

  • (::FFI::AutoPointer)

Raises:



207
208
209
210
211
212
213
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 207

def strdup()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_strdup(self_p)
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end

#streq(string) ⇒ Boolean

Return TRUE if frame body is equal to string, excluding terminator

Parameters:

  • string (String, #to_s, nil)

Returns:

  • (Boolean)

Raises:



219
220
221
222
223
224
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 219

def streq(string)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_streq(self_p, string)
  result
end

#strhex::FFI::AutoPointer

Return frame data encoded as printable hex string, useful for 0MQ UUIDs. Caller must free string when finished with it.

Returns:

  • (::FFI::AutoPointer)

Raises:



195
196
197
198
199
200
201
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 195

def strhex()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_strhex(self_p)
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end