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).
-
#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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'ext/rbczmq/frame.c', line 68
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();
}
ZmqRegisterFrame(fr);
frame = Data_Wrap_Struct(rb_cZmqFrame, 0, rb_czmq_free_frame_gc, fr);
rb_obj_call_init(frame, 0, NULL);
return frame;
}
|
Instance Method Details
#<=>(other) ⇒ Boolean
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'ext/rbczmq/frame.c', line 309
static VALUE rb_czmq_frame_cmp(VALUE obj, VALUE other_frame)
{
long diff;
zframe_t *other = NULL;
if (obj == other_frame) return INT2NUM(0);
ZmqGetFrame(obj);
ZmqAssertFrame(other_frame);
Data_Get_Struct(other_frame, zframe_t, other);
if (!other) rb_raise(rb_eTypeError, "uninitialized ZMQ frame!"); \
if (!(st_lookup(frames_map, (st_data_t)other, 0))) rb_raise(rb_eZmqError, "object %p has been destroyed by the ZMQ framework", (void *)other_frame);
diff = (zframe_size(frame) - zframe_size(other));
if (diff == 0) return INT2NUM(0);
if (diff > 0) return INT2NUM(1);
return INT2NUM(-1);
}
|
#==(other) ⇒ Boolean
290 291 292 293 294 |
# File 'ext/rbczmq/frame.c', line 290
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
143 144 145 146 147 148 149 |
# File 'ext/rbczmq/frame.c', line 143
static VALUE rb_czmq_frame_data(VALUE obj)
{
size_t size;
ZmqGetFrame(obj);
size = zframe_size(frame);
return ZmqEncode(rb_str_new((char *)zframe_data(frame), (long)size));
}
|
#data_equals?("data") ⇒ Boolean
227 228 229 230 231 232 |
# File 'ext/rbczmq/frame.c', line 227
static VALUE rb_czmq_frame_data_equals_p(VALUE obj, VALUE data)
{
ZmqGetFrame(obj);
Check_Type(data, T_STRING);
return (zframe_streq(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
104 105 106 107 108 109 |
# File 'ext/rbczmq/frame.c', line 104
static VALUE rb_czmq_frame_destroy(VALUE obj)
{
ZmqGetFrame(obj);
rb_czmq_free_frame(frame);
return Qnil;
}
|
#dup ⇒ ZMQ::Frame
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'ext/rbczmq/frame.c', line 198
static VALUE rb_czmq_frame_dup(VALUE obj)
{
VALUE dup;
zframe_t *dup_fr = NULL;
errno = 0;
ZmqGetFrame(obj);
dup_fr = zframe_dup(frame);
if (dup_fr == NULL) {
ZmqAssertSysError();
rb_memerror();
}
ZmqRegisterFrame(dup_fr);
dup = Data_Wrap_Struct(rb_cZmqFrame, 0, rb_czmq_free_frame_gc, dup_fr);
rb_obj_call_init(dup, 0, NULL);
return dup;
}
|
#eql?(other) ⇒ Boolean
265 266 267 268 269 270 271 272 273 274 |
# File 'ext/rbczmq/frame.c', line 265
static VALUE rb_czmq_frame_eql_p(VALUE obj, VALUE other_frame)
{
zframe_t *other = NULL;
ZmqGetFrame(obj);
ZmqAssertFrame(other_frame);
Data_Get_Struct(other_frame, zframe_t, other);
if (!other) rb_raise(rb_eTypeError, "uninitialized ZMQ frame!"); \
if (!(st_lookup(frames_map, (st_data_t)other, 0))) rb_raise(rb_eZmqError, "object %p has been destroyed by the ZMQ framework", (void *)other_frame);
return (zframe_eq(frame, other)) ? Qtrue : Qfalse;
}
|
#more? ⇒ Boolean
246 247 248 249 250 |
# File 'ext/rbczmq/frame.c', line 246
static VALUE rb_czmq_frame_more_p(VALUE obj)
{
ZmqGetFrame(obj);
return (zframe_more(frame) == ZFRAME_MORE) ? Qtrue : Qfalse;
}
|
#print ⇒ nil Also known as: dump
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'ext/rbczmq/frame.c', line 337
static VALUE rb_czmq_frame_print(int argc, VALUE *argv, VALUE obj)
{
VALUE prefix;
const char *print_prefix = NULL;
ZmqGetFrame(obj);
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, (char *)print_prefix);
return Qnil;
}
|
#reset("new") ⇒ nil
366 367 368 369 370 371 372 373 374 |
# File 'ext/rbczmq/frame.c', line 366
static VALUE rb_czmq_frame_reset(VALUE obj, VALUE data)
{
errno = 0;
ZmqGetFrame(obj);
Check_Type(data, T_STRING);
zframe_reset(frame, (char *)RSTRING_PTR(data), (size_t)RSTRING_LEN(data));
ZmqAssertSysError();
return Qnil;
}
|
#size ⇒ Fixnum
123 124 125 126 127 128 129 |
# File 'ext/rbczmq/frame.c', line 123
static VALUE rb_czmq_frame_size(VALUE obj)
{
size_t size;
ZmqGetFrame(obj);
size = zframe_size(frame);
return LONG2FIX(size);
}
|
#strhex ⇒ String
180 181 182 183 184 |
# File 'ext/rbczmq/frame.c', line 180
static VALUE rb_czmq_frame_strhex(VALUE obj)
{
ZmqGetFrame(obj);
return rb_str_new2(zframe_strhex(frame));
}
|
#to_s ⇒ String
163 164 165 166 |
# File 'ext/rbczmq/frame.c', line 163
static VALUE rb_czmq_frame_to_s(VALUE obj)
{
return rb_funcall(obj, intern_data, 0, 0);
}
|