Class: CZMQ::FFI::Zstr

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

Overview

Note:

This class is 100% generated using zproject.

sending and receiving strings

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zstr

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

Parameters:

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


24
25
26
27
28
29
30
31
32
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 24

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

.create_finalizer_for(ptr) ⇒ Proc

Returns:

  • (Proc)


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

def self.create_finalizer_for(ptr)
  Proc.new do
    "WARNING: "\
    "Objects of type #{self} cannot be destroyed implicitly. "\
    "Please call the correct destroy method with the relevant arguments."
  end
end

.free(string_p) ⇒ void

This method returns an undefined value.

Free a provided string, and nullify the parent pointer. Safe to call on a null pointer.

Parameters:

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


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

def self.free(string_p)
  result = ::CZMQ::FFI.zstr_free(string_p)
  result
end

.recv(source) ⇒ ::FFI::AutoPointer

Receive C string from socket. Caller must free returned string using zstr_free(). Returns NULL if the context is being terminated or the process was interrupted.

Parameters:

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

Returns:

  • (::FFI::AutoPointer)


81
82
83
84
85
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 81

def self.recv(source)
  result = ::CZMQ::FFI.zstr_recv(source)
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end

.recv_compress(source) ⇒ ::FFI::AutoPointer

De-compress and receive C string from socket, received as a message with two frames: size of the uncompressed string, and the string itself. Caller must free returned string using zstr_free(). Returns NULL if the context is being terminated or the process was interrupted.

Parameters:

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

Returns:

  • (::FFI::AutoPointer)


111
112
113
114
115
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 111

def self.recv_compress(source)
  result = ::CZMQ::FFI.zstr_recv_compress(source)
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end

.recvx(source, string_p, *args) ⇒ Integer

Receive a series of strings (until NULL) from multipart data. Each string is allocated and filled with string data; if there are not enough frames, unallocated strings are set to NULL. Returns -1 if the message could not be read, else returns the number of strings filled, zero or more. Free each returned string using zstr_free(). If not enough strings are provided, remaining multipart frames in the message are dropped.

Parameters:

Returns:

  • (Integer)


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

def self.recvx(source, string_p, *args)
  result = ::CZMQ::FFI.zstr_recvx(source, string_p, *args)
  result
end

.send(dest, string) ⇒ Integer

Send a C string to a socket, as a frame. The string is sent without trailing null byte; to read this you can use zstr_recv, or a similar method that adds a null terminator on the received string. String may be NULL, which is sent as “”.

Parameters:

  • dest (::FFI::Pointer, #to_ptr)
  • string (String, #to_s, nil)

Returns:

  • (Integer)


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

def self.send(dest, string)
  result = ::CZMQ::FFI.zstr_send(dest, string)
  result
end

.send_compress(dest, string) ⇒ Integer

Compress and send a C string to a socket, as a message with two frames: size of the uncompressed string, and the string itself. The string is sent without trailing null byte; to read this you can use zstr_recv_compress, or a similar method that de-compresses and adds a null terminator on the received string.

Parameters:

  • dest (::FFI::Pointer, #to_ptr)
  • string (String, #to_s, nil)

Returns:

  • (Integer)


188
189
190
191
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 188

def self.send_compress(dest, string)
  result = ::CZMQ::FFI.zstr_send_compress(dest, string)
  result
end

.sendf(dest, format, *args) ⇒ Integer

Send a formatted string to a socket. Note that you should NOT use user-supplied strings in the format (they may contain ‘%’ which will create security holes).

Parameters:

Returns:

  • (Integer)


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

def self.sendf(dest, format, *args)
  result = ::CZMQ::FFI.zstr_sendf(dest, format, *args)
  result
end

.sendfm(dest, format, *args) ⇒ Integer

Send a formatted string to a socket, as for zstr_sendf(), with a MORE flag, so that you can send further strings in the same multi-part message.

Parameters:

Returns:

  • (Integer)


162
163
164
165
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 162

def self.sendfm(dest, format, *args)
  result = ::CZMQ::FFI.zstr_sendfm(dest, format, *args)
  result
end

.sendm(dest, string) ⇒ Integer

Send a C string to a socket, as zstr_send(), with a MORE flag, so that you can send further strings in the same multi-part message.

Parameters:

  • dest (::FFI::Pointer, #to_ptr)
  • string (String, #to_s, nil)

Returns:

  • (Integer)


136
137
138
139
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 136

def self.sendm(dest, string)
  result = ::CZMQ::FFI.zstr_sendm(dest, string)
  result
end

.sendm_compress(dest, string) ⇒ Integer

Compress and send a C string to a socket, as zstr_send_compress(), with a MORE flag, so that you can send further strings in the same multi-part message.

Parameters:

  • dest (::FFI::Pointer, #to_ptr)
  • string (String, #to_s, nil)

Returns:

  • (Integer)


200
201
202
203
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 200

def self.sendm_compress(dest, string)
  result = ::CZMQ::FFI.zstr_sendm_compress(dest, string)
  result
end

.sendx(dest, string, *args) ⇒ Integer

Send a series of strings (until NULL) as multipart data Returns 0 if the strings could be sent OK, or -1 on error.

Parameters:

Returns:

  • (Integer)


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

def self.sendx(dest, string, *args)
  result = ::CZMQ::FFI.zstr_sendx(dest, string, *args)
  result
end

.str(source) ⇒ ::FFI::AutoPointer

Accepts a void pointer and returns a fresh character string. If source is null, returns an empty string.

Parameters:

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

Returns:

  • (::FFI::AutoPointer)


210
211
212
213
214
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 210

def self.str(source)
  result = ::CZMQ::FFI.zstr_str(source)
  result = ::FFI::AutoPointer.new(result, LibC.method(:free))
  result
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


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

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

Instance Method Details

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

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



47
48
49
50
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 47

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:



58
59
60
61
62
63
64
65
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 58

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.



70
71
72
73
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 70

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#null?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 42

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