Class: CZMQ::FFI::Zframe
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zframe
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zframe.rb
Overview
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
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.destructor_fn ⇒ Object
Create a new callback of the following type: Destroy an item typedef void (zframe_destructor_fn) ( void **hint);.
-
.from(string) ⇒ CZMQ::Zframe
Create a frame with a specified string content.
-
.frommem(data, size, destructor, hint) ⇒ CZMQ::Zframe
Create a new frame from memory.
-
.is(self_) ⇒ Boolean
Probe the supplied object, and report if it looks like a zframe_t.
-
.new(data, size) ⇒ CZMQ::Zframe
Create a new frame.
-
.new_empty ⇒ CZMQ::Zframe
Create an empty (zero-sized) frame.
-
.recv(source) ⇒ CZMQ::Zframe
Receive frame from socket, returns zframe_t object or NULL if the recv was interrupted.
-
.send(self_p, dest, flags) ⇒ Integer
Send a frame to a socket, destroy frame after sending.
-
.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.
-
#data ⇒ ::FFI::Pointer
Return address of frame data.
-
#destroy ⇒ void
Destroy a frame.
-
#dup ⇒ Zframe
Create a new frame that duplicates an existing frame.
-
#eq(other) ⇒ Boolean
Return TRUE if two frames have identical size and data If either frame is NULL, equality is always false.
-
#group ⇒ String
Return frame group of radio-dish pattern.
-
#initialize(ptr, finalize = true) ⇒ Zframe
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#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.
-
#more ⇒ Integer
Return frame MORE indicator (1 or 0), set when reading frame from socket or by the zframe_set_more() method.
- #null? ⇒ Boolean
-
#print(prefix) ⇒ void
Send message to zsys log sink (may be stdout, or system facility as configured by zsys_set_logstream).
-
#print_n(prefix, length) ⇒ void
Send message to zsys log sink (may be stdout, or system facility as configured by zsys_set_logstream).
-
#reset(data, size) ⇒ void
Set new contents for frame.
-
#routing_id ⇒ Integer
Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
-
#set_group(group) ⇒ Integer
Set group on frame.
-
#set_more(more) ⇒ void
Set frame MORE indicator (1 or 0).
-
#set_routing_id(routing_id) ⇒ void
Set routing ID on frame.
-
#size ⇒ Integer
Return number of bytes in frame data.
-
#strdup ⇒ ::FFI::AutoPointer
Return frame data copied into freshly allocated string Caller must free string when finished with it.
-
#streq(string) ⇒ Boolean
Return TRUE if frame body is equal to string, excluding terminator.
-
#strhex ⇒ ::FFI::AutoPointer
Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zframe
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
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
.__new ⇒ Object
27 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 27 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
44 45 46 47 48 49 50 51 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 44 def self.create_finalizer_for(ptr) ptr_ptr = ::FFI::MemoryPointer.new :pointer Proc.new do ptr_ptr.write_pointer ptr ::CZMQ::FFI.zframe_destroy ptr_ptr end end |
.destructor_fn ⇒ Object
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.
Create a new callback of the following type: Destroy an item
typedef void (zframe_destructor_fn) (
void **hint);
95 96 97 98 99 100 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 95 def self.destructor_fn ::FFI::Function.new :void, [:pointer], blocking: true do |hint| result = yield hint result end end |
.from(string) ⇒ CZMQ::Zframe
Create a frame with a specified string content.
124 125 126 127 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 124 def self.from(string) ptr = ::CZMQ::FFI.zframe_from(string) __new ptr end |
.frommem(data, size, destructor, hint) ⇒ CZMQ::Zframe
Create a new frame from memory. Take ownership of the memory and calling the destructor on destroy.
136 137 138 139 140 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 136 def self.frommem(data, size, destructor, hint) size = Integer(size) ptr = ::CZMQ::FFI.zframe_frommem(data, size, destructor, hint) __new ptr end |
.is(self_) ⇒ Boolean
Probe the supplied object, and report if it looks like a zframe_t.
386 387 388 389 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 386 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.
108 109 110 111 112 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 108 def self.new(data, size) size = Integer(size) ptr = ::CZMQ::FFI.zframe_new(data, size) __new ptr end |
.new_empty ⇒ CZMQ::Zframe
Create an empty (zero-sized) frame
116 117 118 119 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 116 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.
147 148 149 150 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 147 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.
169 170 171 172 173 174 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 169 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 |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
58 59 60 61 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 58 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.
69 70 71 72 73 74 75 76 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 69 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.
81 82 83 84 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 81 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#data ⇒ ::FFI::Pointer
Return address of frame data
189 190 191 192 193 194 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 189 def data() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zframe_data(self_p) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a frame
155 156 157 158 159 160 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 155 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zframe_destroy(self_p) result end |
#dup ⇒ Zframe
Create a new frame that duplicates an existing frame. If frame is null, or memory was exhausted, returns null.
213 214 215 216 217 218 219 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 213 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.
332 333 334 335 336 337 338 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 332 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 ⇒ String
Return frame group of radio-dish pattern.
307 308 309 310 311 312 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 307 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.
202 203 204 205 206 207 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 202 def (property) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.(self_p, property) result end |
#more ⇒ Integer
Return frame MORE indicator (1 or 0), set when reading frame from socket or by the zframe_set_more() method
260 261 262 263 264 265 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 260 def more() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zframe_more(self_p) result end |
#null? ⇒ Boolean
53 54 55 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 53 def null? !@ptr or @ptr.null? end |
#print(prefix) ⇒ void
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. Long messages are truncated.
359 360 361 362 363 364 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 359 def print(prefix) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zframe_print(self_p, prefix) result end |
#print_n(prefix, length) ⇒ void
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. Message length is specified; no truncation unless length is zero. Backwards compatible with zframe_print when length is zero.
374 375 376 377 378 379 380 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 374 def print_n(prefix, length) raise DestroyedError unless @ptr self_p = @ptr length = Integer(length) result = ::CZMQ::FFI.zframe_print_n(self_p, prefix, length) result end |
#reset(data, size) ⇒ void
This method returns an undefined value.
Set new contents for frame
345 346 347 348 349 350 351 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 345 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 ⇒ Integer
Return frame routing ID, if the frame came from a ZMQ_SERVER socket. Else returns zero.
284 285 286 287 288 289 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 284 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.
320 321 322 323 324 325 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 320 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.
272 273 274 275 276 277 278 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 272 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.
296 297 298 299 300 301 302 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 296 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 ⇒ Integer
Return number of bytes in frame data
179 180 181 182 183 184 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 179 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.
237 238 239 240 241 242 243 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 237 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
249 250 251 252 253 254 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 249 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.
225 226 227 228 229 230 231 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zframe.rb', line 225 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 |