Class: CZMQ::FFI::Zmsg
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zmsg
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zmsg.rb
Overview
This class is 100% generated using zproject.
working with multipart messages
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.decode(frame) ⇒ CZMQ::Zmsg
Decodes a serialized message frame created by zmsg_encode () and returns a new zmsg_t object.
-
.is(self_) ⇒ Boolean
Probe the supplied object, and report if it looks like a zmsg_t.
-
.load(file) ⇒ CZMQ::Zmsg
Load/append an open file into new message, return the message.
-
.new ⇒ CZMQ::Zmsg
Create a new empty message object.
-
.new_signal(status) ⇒ CZMQ::Zmsg
Generate a signal message encoding the given status.
-
.recv(source) ⇒ CZMQ::Zmsg
Receive message from socket, returns zmsg_t object or NULL if the recv was interrupted.
-
.send(self_p, dest) ⇒ Integer
Send message to destination socket, and destroy the message after sending it successfully.
-
.sendm(self_p, dest) ⇒ Integer
Send message to destination socket as part of a multipart sequence, and destroy the message after sending it successfully.
-
.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.
-
#addmem(data, size) ⇒ Integer
Add block of memory to the end of the message, as a new frame.
-
#addmsg(msg_p) ⇒ Integer
Push encoded message as a new frame.
-
#addstr(string) ⇒ Integer
Push string as new frame to end of message.
-
#addstrf(format, *args) ⇒ Integer
Push formatted string as new frame to end of message.
-
#append(frame_p) ⇒ Integer
Add frame to the end of the message, i.e.
-
#content_size ⇒ Integer
Return total size of all frames in message.
-
#destroy ⇒ void
Destroy a message object and all frames it contains.
-
#dup ⇒ Zmsg
Create copy of message, as new message object.
-
#encode ⇒ Zframe
Serialize multipart message to a single message frame.
-
#eq(other) ⇒ Boolean
Return true if the two messages have the same number of frames and each frame in the first message is identical to the corresponding frame in the other message.
-
#first ⇒ Zframe
Set cursor to first frame in message.
-
#initialize(ptr, finalize = true) ⇒ Zmsg
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#last ⇒ Zframe
Return the last frame.
-
#next ⇒ Zframe
Return the next frame.
- #null? ⇒ Boolean
-
#pop ⇒ Zframe
Remove first frame from message, if any.
-
#popmsg ⇒ Zmsg
Remove first submessage from message, if any.
-
#popstr ⇒ ::FFI::AutoPointer
Pop frame off front of message, return as fresh string.
-
#prepend(frame_p) ⇒ Integer
Push frame to the front of the message, i.e.
-
#print ⇒ void
Send message to zsys log sink (may be stdout, or system facility as configured by zsys_set_logstream).
-
#pushmem(data, size) ⇒ Integer
Push block of memory to front of message, as a new frame.
-
#pushstr(string) ⇒ Integer
Push string as new frame to front of message.
-
#pushstrf(format, *args) ⇒ Integer
Push formatted string as new frame to front of message.
-
#remove(frame) ⇒ void
Remove specified frame from list, if present.
-
#routing_id ⇒ Integer
Return message routing ID, if the message came from a ZMQ_SERVER socket.
-
#save(file) ⇒ Integer
Save message to an open file, return 0 if OK, else -1.
-
#set_routing_id(routing_id) ⇒ void
Set routing ID on message.
-
#signal ⇒ Integer
Return signal value, 0 or greater, if message is a signal, -1 if not.
-
#size ⇒ Integer
Return size of message, i.e.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zmsg
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/zmsg.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
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 18 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 35 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer ptr ::CZMQ::FFI.zmsg_destroy ptr_ptr end end |
.decode(frame) ⇒ CZMQ::Zmsg
Decodes a serialized message frame created by zmsg_encode () and returns a new zmsg_t object. Returns NULL if the frame was badly formatted or there was insufficient memory to work.
108 109 110 111 112 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 108 def self.decode(frame) frame = frame.__ptr if frame ptr = ::CZMQ::FFI.zmsg_decode(frame) __new ptr end |
.is(self_) ⇒ Boolean
Probe the supplied object, and report if it looks like a zmsg_t.
494 495 496 497 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 494 def self.is(self_) result = ::CZMQ::FFI.zmsg_is(self_) result end |
.load(file) ⇒ CZMQ::Zmsg
Load/append an open file into new message, return the message. Returns NULL if the message could not be loaded.
98 99 100 101 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 98 def self.load(file) ptr = ::CZMQ::FFI.zmsg_load(file) __new ptr end |
.new ⇒ CZMQ::Zmsg
Create a new empty message object
78 79 80 81 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 78 def self.new() ptr = ::CZMQ::FFI.zmsg_new() __new ptr end |
.new_signal(status) ⇒ CZMQ::Zmsg
Generate a signal message encoding the given status. A signal is a short message carrying a 1-byte success/failure code (by convention, 0 means OK). Signals are encoded to be distinguishable from “normal” messages.
119 120 121 122 123 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 119 def self.new_signal(status) status = Integer(status) ptr = ::CZMQ::FFI.zmsg_new_signal(status) __new ptr end |
.recv(source) ⇒ CZMQ::Zmsg
Receive message from socket, returns zmsg_t object or NULL if the recv was interrupted. Does a blocking recv. If you want to not block then use the zloop class or zmsg_recv_nowait or zmq_poll to check for socket input before receiving.
89 90 91 92 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 89 def self.recv(source) ptr = ::CZMQ::FFI.zmsg_recv(source) __new ptr end |
.send(self_p, dest) ⇒ Integer
Send message to destination socket, and destroy the message after sending it successfully. If the message has no frames, sends nothing but destroys the message anyhow. Nullifies the caller’s reference to the message (as it is a destructor).
143 144 145 146 147 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 143 def self.send(self_p, dest) self_p = self_p.__ptr_give_ref result = ::CZMQ::FFI.zmsg_send(self_p, dest) result end |
.sendm(self_p, dest) ⇒ Integer
Send message to destination socket as part of a multipart sequence, and destroy the message after sending it successfully. Note that after a zmsg_sendm, you must call zmsg_send or another method that sends a final message part. If the message has no frames, sends nothing but destroys the message anyhow. Nullifies the caller’s reference to the message (as it is a destructor).
159 160 161 162 163 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 159 def self.sendm(self_p, dest) self_p = self_p.__ptr_give_ref result = ::CZMQ::FFI.zmsg_sendm(self_p, dest) result end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
48 49 50 51 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 48 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.
59 60 61 62 63 64 65 66 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 59 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.
71 72 73 74 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 71 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#addmem(data, size) ⇒ Integer
Add block of memory to the end of the message, as a new frame. Returns 0 on success, -1 on error.
270 271 272 273 274 275 276 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 270 def addmem(data, size) raise DestroyedError unless @ptr self_p = @ptr size = Integer(size) result = ::CZMQ::FFI.zmsg_addmem(self_p, data, size) result end |
#addmsg(msg_p) ⇒ Integer
Push encoded message as a new frame. Message takes ownership of submessage, so the original is destroyed in this call. Returns 0 on success, -1 on error.
346 347 348 349 350 351 352 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 346 def addmsg(msg_p) raise DestroyedError unless @ptr self_p = @ptr msg_p = msg_p.__ptr_give_ref result = ::CZMQ::FFI.zmsg_addmsg(self_p, msg_p) result end |
#addstr(string) ⇒ Integer
Push string as new frame to end of message. Returns 0 on success, -1 on error.
295 296 297 298 299 300 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 295 def addstr(string) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_addstr(self_p, string) result end |
#addstrf(format, *args) ⇒ Integer
Push formatted string as new frame to end of message. Returns 0 on success, -1 on error.
321 322 323 324 325 326 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 321 def addstrf(format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_addstrf(self_p, format, *args) result end |
#append(frame_p) ⇒ Integer
Add frame to the end of the message, i.e. after all other frames. Message takes ownership of frame, will destroy it when message is sent. Returns 0 on success. Deprecates zmsg_add, which did not nullify the caller’s frame reference.
231 232 233 234 235 236 237 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 231 def append(frame_p) raise DestroyedError unless @ptr self_p = @ptr frame_p = frame_p.__ptr_give_ref result = ::CZMQ::FFI.zmsg_append(self_p, frame_p) result end |
#content_size ⇒ Integer
Return total size of all frames in message.
178 179 180 181 182 183 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 178 def content_size() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_content_size(self_p) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a message object and all frames it contains
128 129 130 131 132 133 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 128 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zmsg_destroy(self_p) result end |
#dup ⇒ Zmsg
Create copy of message, as new message object. Returns a fresh zmsg_t object. If message is null, or memory was exhausted, returns null.
447 448 449 450 451 452 453 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 447 def dup() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_dup(self_p) result = Zmsg.__new result, true result end |
#encode ⇒ Zframe
Serialize multipart message to a single message frame. Use this method to send structured messages across transports that do not support multipart data. Allocates and returns a new frame containing the serialized message. To decode a serialized message frame, use zmsg_decode ().
435 436 437 438 439 440 441 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 435 def encode() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_encode(self_p) result = Zframe.__new result, true result end |
#eq(other) ⇒ Boolean
Return true if the two messages have the same number of frames and each frame in the first message is identical to the corresponding frame in the other message. As with zframe_eq, return false if either message is NULL.
472 473 474 475 476 477 478 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 472 def eq(other) raise DestroyedError unless @ptr self_p = @ptr other = other.__ptr if other result = ::CZMQ::FFI.zmsg_eq(self_p, other) result end |
#first ⇒ Zframe
Set cursor to first frame in message. Returns frame, or NULL, if the message is empty. Use this to navigate the frames as a list.
382 383 384 385 386 387 388 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 382 def first() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_first(self_p) result = Zframe.__new result, false result end |
#last ⇒ Zframe
Return the last frame. If there are no frames, returns NULL.
405 406 407 408 409 410 411 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 405 def last() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_last(self_p) result = Zframe.__new result, false result end |
#next ⇒ Zframe
Return the next frame. If there are no more frames, returns NULL. To move to the first frame call zmsg_first(). Advances the cursor.
394 395 396 397 398 399 400 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 394 def next() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_next(self_p) result = Zframe.__new result, false result end |
#null? ⇒ Boolean
43 44 45 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 43 def null? !@ptr or @ptr.null? end |
#pop ⇒ Zframe
Remove first frame from message, if any. Returns frame, or NULL.
242 243 244 245 246 247 248 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 242 def pop() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_pop(self_p) result = Zframe.__new result, true result end |
#popmsg ⇒ Zmsg
Remove first submessage from message, if any. Returns zmsg_t, or NULL if decoding was not successful.
358 359 360 361 362 363 364 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 358 def popmsg() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_popmsg(self_p) result = Zmsg.__new result, true result end |
#popstr ⇒ ::FFI::AutoPointer
Pop frame off front of message, return as fresh string. If there were no more frames in the message, returns NULL.
332 333 334 335 336 337 338 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 332 def popstr() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_popstr(self_p) result = ::FFI::AutoPointer.new(result, LibC.method(:free)) result end |
#prepend(frame_p) ⇒ Integer
Push frame to the front of the message, i.e. before all other frames. Message takes ownership of frame, will destroy it when message is sent. Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not nullify the caller’s frame reference.
216 217 218 219 220 221 222 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 216 def prepend(frame_p) raise DestroyedError unless @ptr self_p = @ptr frame_p = frame_p.__ptr_give_ref result = ::CZMQ::FFI.zmsg_prepend(self_p, frame_p) result end |
#print ⇒ 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).
459 460 461 462 463 464 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 459 def print() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_print(self_p) result end |
#pushmem(data, size) ⇒ Integer
Push block of memory to front of message, as a new frame. Returns 0 on success, -1 on error.
256 257 258 259 260 261 262 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 256 def pushmem(data, size) raise DestroyedError unless @ptr self_p = @ptr size = Integer(size) result = ::CZMQ::FFI.zmsg_pushmem(self_p, data, size) result end |
#pushstr(string) ⇒ Integer
Push string as new frame to front of message. Returns 0 on success, -1 on error.
283 284 285 286 287 288 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 283 def pushstr(string) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_pushstr(self_p, string) result end |
#pushstrf(format, *args) ⇒ Integer
Push formatted string as new frame to front of message. Returns 0 on success, -1 on error.
308 309 310 311 312 313 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 308 def pushstrf(format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_pushstrf(self_p, format, *args) result end |
#remove(frame) ⇒ void
This method returns an undefined value.
Remove specified frame from list, if present. Does not destroy frame.
370 371 372 373 374 375 376 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 370 def remove(frame) raise DestroyedError unless @ptr self_p = @ptr frame = frame.__ptr if frame result = ::CZMQ::FFI.zmsg_remove(self_p, frame) result end |
#routing_id ⇒ Integer
Return message routing ID, if the message came from a ZMQ_SERVER socket. Else returns zero.
189 190 191 192 193 194 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 189 def routing_id() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_routing_id(self_p) result end |
#save(file) ⇒ Integer
Save message to an open file, return 0 if OK, else -1. The message is saved as a series of frames, each with length and data. Note that the file is NOT guaranteed to be portable between operating systems, not versions of CZMQ. The file format is at present undocumented and liable to arbitrary change.
421 422 423 424 425 426 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 421 def save(file) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_save(self_p, file) result end |
#set_routing_id(routing_id) ⇒ void
This method returns an undefined value.
Set routing ID on message. This is used if/when the message is sent to a ZMQ_SERVER socket.
201 202 203 204 205 206 207 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 201 def set_routing_id(routing_id) raise DestroyedError unless @ptr self_p = @ptr routing_id = Integer(routing_id) result = ::CZMQ::FFI.zmsg_set_routing_id(self_p, routing_id) result end |
#signal ⇒ Integer
Return signal value, 0 or greater, if message is a signal, -1 if not.
483 484 485 486 487 488 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 483 def signal() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_signal(self_p) result end |
#size ⇒ Integer
Return size of message, i.e. number of frames (0 or more).
168 169 170 171 172 173 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zmsg.rb', line 168 def size() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zmsg_size(self_p) result end |