Class: CZMQ::FFI::Zstr
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zstr
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zstr.rb
Overview
This class is 100% generated using zproject.
sending and receiving strings
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .create_finalizer_for(ptr) ⇒ Proc
-
.free(string_p) ⇒ void
Free a provided string, and nullify the parent pointer.
-
.recv(source) ⇒ ::FFI::AutoPointer
Receive C string from socket.
-
.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.
-
.recvx(source, string_p, *args) ⇒ Integer
Receive a series of strings (until NULL) from multipart data.
-
.send(dest, string) ⇒ Integer
Send a C string to a socket, as a frame.
-
.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.
-
.sendf(dest, format, *args) ⇒ Integer
Send a formatted string to a socket.
-
.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.
-
.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.
-
.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.
-
.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.
-
.str(source) ⇒ ::FFI::AutoPointer
Accepts a void pointer and returns a fresh character string.
-
.test(verbose) ⇒ void
Self test of this class.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#initialize(ptr, finalize = true) ⇒ Zstr
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
- #null? ⇒ Boolean
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zstr
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
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
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.
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.
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.
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.
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 “”.
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.
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).
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.
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.
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.
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.
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.
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 |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
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
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
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_finalizer ⇒ void
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
42 43 44 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zstr.rb', line 42 def null? !@ptr or @ptr.null? end |