Class: ZMQ::Frame
- Inherits:
-
Object
- Object
- ZMQ::Frame
- Includes:
- Comparable
- Defined in:
- lib/zmq/frame.rb,
ext/rbczmq/frame.c
Constant Summary collapse
- MORE =
INT2NUM(ZFRAME_MORE)
- REUSE =
INT2NUM(ZFRAME_REUSE)
- DONTWAIT =
INT2NUM(ZFRAME_DONTWAIT)
Class Method Summary collapse
-
.new(*args) ⇒ Object
Creates a new ZMQ::Frame instance.
Instance Method Summary collapse
-
#<=>(other) ⇒ Boolean
Comparable support for ZMQ::Frame instances.
-
#==(other) ⇒ Boolean
Determines if the current frame is equal to another (identical size and data).
-
#data ⇒ String
Returns the data represented by the frame as a string.
-
#data_equals?("data") ⇒ Boolean
Determines if the current frame’s payload matches a given string.
-
#destroy ⇒ nil
Explicitly destroys an allocated ZMQ::Frame instance.
-
#dup ⇒ ZMQ::Frame
Returns a copy of the current frame.
-
#eql?(other) ⇒ Boolean
Determines if the current frame is equal to another (identical size and data).
-
#gone?(# = > false) ⇒ Boolean
frame.gone? #=> true.
-
#more? ⇒ Boolean
Determines if the current frame is part of a multipart message.
-
#print ⇒ nil
(also: #dump)
Dumps out frame contents to stderr.
-
#reset("new") ⇒ nil
Sets new content for this frame.
-
#size ⇒ Fixnum
Returns the size of the frame.
-
#strhex ⇒ String
Returns a printable hex representation of this frame.
-
#to_s ⇒ String
Returns a String representation of this frame.
-
#to_s ⇒ String
Returns a String representation of this frame.
Class Method Details
.ZMQ::Frame.new ⇒ ZMQ::Frame .ZMQ::Frame.new("data") ⇒ ZMQ::Frame
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/rbczmq/frame.c', line 65
static VALUE rb_czmq_frame_s_new(int argc, VALUE *argv, VALUE frame)
{
VALUE data;
errno = 0;
zframe_t *fr;
rb_scan_args(argc, argv, "01", &data);
if (NIL_P(data)) {
fr = zframe_new(NULL, 0);
} else {
Check_Type(data, T_STRING);
fr = zframe_new(RSTRING_PTR(data), (size_t)RSTRING_LEN(data));
}
if (fr == NULL) {
ZmqAssertSysError();
rb_memerror();
}
return rb_czmq_alloc_frame(fr);
}
|
Instance Method Details
#<=>(other) ⇒ Boolean
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'ext/rbczmq/frame.c', line 306
static VALUE rb_czmq_frame_cmp(VALUE obj, VALUE other_frame)
{
long diff;
zmq_frame_wrapper *other = NULL;
if (obj == other_frame) return INT2NUM(0);
ZmqGetFrame(obj);
ZmqAssertFrameOwned(frame);
ZmqAssertFrame(other_frame);
Data_Get_Struct(other_frame, zmq_frame_wrapper, other);
if (!other || !other->frame) rb_raise(rb_eTypeError, "uninitialized ZMQ frame!");
ZmqAssertFrameOwned(frame);
diff = (zframe_size(frame->frame) - zframe_size(other->frame));
if (diff == 0) return INT2NUM(0);
if (diff > 0) return INT2NUM(1);
return INT2NUM(-1);
}
|
#==(other) ⇒ Boolean
287 288 289 290 291 |
# File 'ext/rbczmq/frame.c', line 287
static VALUE rb_czmq_frame_equals(VALUE obj, VALUE other_frame)
{
if (obj == other_frame) return Qtrue;
return rb_czmq_frame_eql_p(obj, other_frame);
}
|
#data ⇒ String
139 140 141 142 143 144 145 146 |
# File 'ext/rbczmq/frame.c', line 139
static VALUE rb_czmq_frame_data(VALUE obj)
{
size_t size;
ZmqGetFrame(obj);
ZmqReturnNilUnlessFrameOwned(frame);
size = zframe_size(frame->frame);
return ZmqEncode(rb_str_new((char *)zframe_data(frame->frame), (long)size));
}
|
#data_equals?("data") ⇒ Boolean
221 222 223 224 225 226 227 |
# File 'ext/rbczmq/frame.c', line 221
static VALUE rb_czmq_frame_data_equals_p(VALUE obj, VALUE data)
{
ZmqGetFrame(obj);
ZmqAssertFrameOwned(frame);
Check_Type(data, T_STRING);
return (zframe_streq(frame->frame, RSTRING_PTR(data)) == true) ? Qtrue : Qfalse;
}
|
#destroy ⇒ nil
Explicitly destroys an allocated ZMQ::Frame instance. Useful for manual memory management, otherwise the GC will take the same action if a frame object is not reachable anymore on the next GC cycle. This is a lower level API.
Examples
frame = ZMQ::Frame.new("data") => ZMQ::Frame
frame.destroy => nil
98 99 100 101 102 103 104 |
# File 'ext/rbczmq/frame.c', line 98
static VALUE rb_czmq_frame_destroy(VALUE obj)
{
ZmqGetFrame(obj);
ZmqAssertFrameOwned(frame);
rb_czmq_free_frame(frame);
return Qnil;
}
|
#dup ⇒ ZMQ::Frame
196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'ext/rbczmq/frame.c', line 196
static VALUE rb_czmq_frame_dup(VALUE obj)
{
zframe_t *dup_fr = NULL;
ZmqGetFrame(obj);
ZmqAssertFrameOwned(frame);
dup_fr = zframe_dup(frame->frame);
if (dup_fr == NULL) {
ZmqAssertSysError();
rb_memerror();
}
return rb_czmq_alloc_frame(dup_fr);
}
|
#eql?(other) ⇒ Boolean
261 262 263 264 265 266 267 268 269 270 271 |
# File 'ext/rbczmq/frame.c', line 261
static VALUE rb_czmq_frame_eql_p(VALUE obj, VALUE other_frame)
{
zmq_frame_wrapper *other = NULL;
ZmqGetFrame(obj);
ZmqAssertFrameOwned(frame);
ZmqAssertFrame(other_frame);
Data_Get_Struct(other_frame, zmq_frame_wrapper, other);
if (!other || !other->frame) rb_raise(rb_eTypeError, "uninitialized ZMQ frame!"); \
ZmqAssertFrameOwned(other);
return (zframe_eq(frame->frame, other->frame)) ? Qtrue : Qfalse;
}
|
#gone?(# = > false) ⇒ Boolean
frame.gone? #=> true
Return boolean indicating if the ZMQ::Frame is gone (sent or destroyed). If the message is gone, accessor methods will return nil and methods requiring data or methods that mutate the message will raise an exception.
387 388 389 390 391 392 393 |
# File 'ext/rbczmq/frame.c', line 387
static VALUE rb_czmq_frame_gone(VALUE obj)
{
ZmqGetFrame(obj);
return (frame->flags & ZMQ_FRAME_OWNED) ||
(frame->message != NULL && (frame->message->flags & ZMQ_MESSAGE_OWNED))
? Qfalse : Qtrue;
}
|
#more? ⇒ Boolean
241 242 243 244 245 246 |
# File 'ext/rbczmq/frame.c', line 241
static VALUE rb_czmq_frame_more_p(VALUE obj)
{
ZmqGetFrame(obj);
ZmqReturnNilUnlessFrameOwned(frame);
return (zframe_more(frame->frame) == ZFRAME_MORE) ? Qtrue : Qfalse;
}
|
#print ⇒ nil Also known as: dump
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'ext/rbczmq/frame.c', line 335
static VALUE rb_czmq_frame_print(int argc, VALUE *argv, VALUE obj)
{
VALUE prefix;
const char *print_prefix = NULL;
ZmqGetFrame(obj);
ZmqAssertFrameOwned(frame);
rb_scan_args(argc, argv, "01", &prefix);
if (NIL_P(prefix)) {
print_prefix = "";
} else {
Check_Type(prefix, T_STRING);
print_prefix = RSTRING_PTR(prefix);
}
zframe_print(frame->frame, (char *)print_prefix);
return Qnil;
}
|
#reset("new") ⇒ nil
365 366 367 368 369 370 371 372 373 374 |
# File 'ext/rbczmq/frame.c', line 365
static VALUE rb_czmq_frame_reset(VALUE obj, VALUE data)
{
errno = 0;
ZmqGetFrame(obj);
ZmqAssertFrameOwned(frame);
Check_Type(data, T_STRING);
zframe_reset(frame->frame, (char *)RSTRING_PTR(data), (size_t)RSTRING_LEN(data));
ZmqAssertSysError();
return Qnil;
}
|
#size ⇒ Fixnum
118 119 120 121 122 123 124 125 |
# File 'ext/rbczmq/frame.c', line 118
static VALUE rb_czmq_frame_size(VALUE obj)
{
size_t size;
ZmqGetFrame(obj);
ZmqReturnNilUnlessFrameOwned(frame);
size = zframe_size(frame->frame);
return LONG2FIX(size);
}
|
#strhex ⇒ String
177 178 179 180 181 182 |
# File 'ext/rbczmq/frame.c', line 177
static VALUE rb_czmq_frame_strhex(VALUE obj)
{
ZmqGetFrame(obj);
ZmqReturnNilUnlessFrameOwned(frame);
return rb_str_new2(zframe_strhex(frame->frame));
}
|
#to_s ⇒ String
160 161 162 163 |
# File 'ext/rbczmq/frame.c', line 160
static VALUE rb_czmq_frame_to_s(VALUE obj)
{
return rb_funcall(obj, intern_data, 0, 0);
}
|