Class: CZMQ::FFI::Zmsg

Inherits:
Object
  • Object
show all
Includes:
Wrapper
Defined in:
lib/cztop/ffi.rb

Overview


Zmsg

Constant Summary collapse

DestroyedError =
CZMQ::FFI::DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Wrapper

#__ptr_give_ref, included, #null?, #to_ptr

Constructor Details

#initializeZmsg

Returns a new instance of Zmsg.



402
403
404
405
406
407
408
409
# File 'lib/cztop/ffi.rb', line 402

def initialize
  @ptr = CZMQ::FFI.zmsg_new
  @moved = false
  unless @ptr.null?
    ObjectSpace.define_finalizer(self,
      self.class.prevent_leak(@ptr, :zmsg_destroy))
  end
end

Class Method Details

.recv(source) ⇒ Object



431
432
433
434
435
# File 'lib/cztop/ffi.rb', line 431

def self.recv(source)
  source_ptr = source.respond_to?(:to_ptr) ? source.to_ptr : source
  ptr = CZMQ::FFI.zmsg_recv(source_ptr)
  _wrap(ptr)
end

.send(msg, dest) ⇒ Object

Override Object#send: int zmsg_send(zmsg_t **self_p, void *dest) Called as: Zmsg.send(zmsg_wrapper_or_ptr, destination)



425
426
427
428
429
# File 'lib/cztop/ffi.rb', line 425

def self.send(msg, dest)
  msg_ptr = msg.respond_to?(:__ptr_give_ref) ? msg.__ptr_give_ref : msg
  dest_ptr = dest.respond_to?(:to_ptr) ? dest.to_ptr : dest
  CZMQ::FFI.zmsg_send(msg_ptr, dest_ptr)
end

Instance Method Details

#add_buffer(str) ⇒ Object

Appends a Ruby string directly without intermediate MemoryPointer copy. Uses :buffer_in to pass the string's internal buffer pointer to C.



439
440
441
# File 'lib/cztop/ffi.rb', line 439

def add_buffer(str)
  CZMQ::FFI.zmsg_addmem_s(@ptr, str, str.bytesize)
end

#firstObject



443
444
445
446
447
# File 'lib/cztop/ffi.rb', line 443

def first
  ptr = CZMQ::FFI.zmsg_first(@ptr)
  return nil if ptr.null?
  _borrowed_frame(ptr)
end

#nextObject



449
450
451
452
453
# File 'lib/cztop/ffi.rb', line 449

def next
  ptr = CZMQ::FFI.zmsg_next(@ptr)
  return nil if ptr.null?
  _borrowed_frame(ptr)
end