class CZMQ::FFI::Zframe

working with single message frames @note This class is 100% generated using zproject.

Constants

DONTWAIT
MORE
REUSE

Public Class Methods

__new(data, size)
Alias for: new
create_finalizer_for(ptr) click to toggle source

@param ptr [::FFI::Pointer] @return [Proc]

# 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
destructor_fn() { |hint| ... } click to toggle source

Create a new callback of the following type: Destroy an item

typedef void (zframe_destructor_fn) (
    void **hint);

@note WARNING: If your Ruby code doesn't retain a reference to the

FFI::Function object after passing it to a C function call,
it may be garbage collected while C still holds the pointer,
potentially resulting in a segmentation fault.
# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 94
def self.destructor_fn
  ::FFI::Function.new :void, [:pointer], blocking: true do |hint|
    result = yield hint
    result
  end
end
from(string) click to toggle source

Create a frame with a specified string content. @param string [String, to_s, nil] @return [CZMQ::Zframe]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 123
def self.from(string)
  ptr = ::CZMQ::FFI.zframe_from(string)
  __new ptr
end
frommem(data, size, destructor, hint) click to toggle source

Create a new frame from memory. Take ownership of the memory and calling the destructor on destroy. @param data [::FFI::Pointer, to_ptr] @param size [Integer, to_int, to_i] @param destructor [::FFI::Pointer, to_ptr] @param hint [::FFI::Pointer, to_ptr] @return [CZMQ::Zframe]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 135
def self.frommem(data, size, destructor, hint)
  size = Integer(size)
  ptr = ::CZMQ::FFI.zframe_frommem(data, size, destructor, hint)
  __new ptr
end
is(self_) click to toggle source

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

@param self_ [::FFI::Pointer, to_ptr] @return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 385
def self.is(self_)
  result = ::CZMQ::FFI.zframe_is(self_)
  result
end
new(ptr, finalize = true) click to toggle source

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary. @param ptr [::FFI::Pointer] @param finalize [Boolean]

# 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
new(data, size) click to toggle source

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. @param data [::FFI::Pointer, to_ptr] @param size [Integer, to_int, to_i] @return [CZMQ::Zframe]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 107
def self.new(data, size)
  size = Integer(size)
  ptr = ::CZMQ::FFI.zframe_new(data, size)
  __new ptr
end
Also aliased as: __new
new_empty() click to toggle source

Create an empty (zero-sized) frame @return [CZMQ::Zframe]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 115
def self.new_empty()
  ptr = ::CZMQ::FFI.zframe_new_empty()
  __new ptr
end
recv(source) click to toggle source

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. @param source [::FFI::Pointer, to_ptr] @return [CZMQ::Zframe]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 146
def self.recv(source)
  ptr = ::CZMQ::FFI.zframe_recv(source)
  __new ptr
end
send(self_p, dest, flags) click to toggle source

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

@param self_p [#__ptr_give_ref] @param dest [::FFI::Pointer, to_ptr] @param flags [Integer, to_int, to_i] @return [Integer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 168
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) click to toggle source

Self test of this class.

@param verbose [Boolean] @return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 394
def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zframe_test(verbose)
  result
end

Public Instance Methods

__ptr() click to toggle source

Return internal pointer @return [::FFI::Pointer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 57
def __ptr
  raise DestroyedError unless @ptr
  @ptr
end
Also aliased as: to_ptr
__ptr_give_ref() click to toggle source

Nullify internal pointer and return pointer pointer. @note This detaches the current instance from the native object

and thus makes it unusable.

@return [::FFI::MemoryPointer] the pointer pointing to a pointer

pointing to the native object
# 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_finalizer() click to toggle source

Undefines the finalizer for this object. @note Only use this if you need to and can guarantee that the native

object will be freed by other means.

@return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 80
def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end
data() click to toggle source

Return address of frame data

@return [::FFI::Pointer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 188
def data()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_data(self_p)
  result
end
destroy() click to toggle source

Destroy a frame

@return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 154
def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zframe_destroy(self_p)
  result
end
dup() click to toggle source

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

@return [Zframe]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 212
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) click to toggle source

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

@param other [Zframe, #__ptr] @return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 331
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
group() click to toggle source

Return frame group of radio-dish pattern.

@return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 306
def group()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_group(self_p)
  result
end
meta(property) click to toggle source

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

@param property [String, to_s, nil] @return [String]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 201
def meta(property)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_meta(self_p, property)
  result
end
more() click to toggle source

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

@return [Integer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 259
def more()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_more(self_p)
  result
end
null?() click to toggle source

@return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 52
def null?
  !@ptr or @ptr.null?
end
print(prefix) click to toggle source

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. Long messages are truncated.

@param prefix [String, to_s, nil] @return [void]

print_n(prefix, length) click to toggle source

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. Message length is specified; no truncation unless length is zero. Backwards compatible with zframe_print when length is zero.

@param prefix [String, to_s, nil] @param length [Integer, to_int, to_i] @return [void]

reset(data, size) click to toggle source

Set new contents for frame

@param data [::FFI::Pointer, to_ptr] @param size [Integer, to_int, to_i] @return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 344
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_id() click to toggle source

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

@return [Integer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 283
def routing_id()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_routing_id(self_p)
  result
end
set_group(group) click to toggle source

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.

@param group [String, to_s, nil] @return [Integer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 319
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) click to toggle source

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

@param more [Integer, to_int, to_i] @return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 271
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) click to toggle source

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

@param routing_id [Integer, to_int, to_i] @return [void]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 295
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
size() click to toggle source

Return number of bytes in frame data

@return [Integer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 178
def size()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_size(self_p)
  result
end
strdup() click to toggle source

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

@return [::FFI::AutoPointer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 236
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) click to toggle source

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

@param string [String, to_s, nil] @return [Boolean]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 248
def streq(string)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zframe_streq(self_p, string)
  result
end
strhex() click to toggle source

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

@return [::FFI::AutoPointer]

# File lib/czmq-ffi-gen/czmq/ffi/zframe.rb, line 224
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
to_ptr()

So external Libraries can just pass the Object to a FFI function which expects a :pointer

Alias for: __ptr