Class: UringMachine::Stream
- Inherits:
-
Object
- Object
- UringMachine::Stream
- Defined in:
- ext/um/um_stream_class.c
Defined Under Namespace
Classes: RESPError
Class Method Summary collapse
Instance Method Summary collapse
- #get_line(buf, limit) ⇒ Object
- #get_string(buf, len) ⇒ Object
- #initialize(machine, fd) ⇒ Object constructor
- #resp_decode ⇒ Object
Constructor Details
#initialize(machine, fd) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'ext/um/um_stream_class.c', line 38
VALUE Stream_initialize(VALUE self, VALUE machine, VALUE fd) {
struct um_stream *stream = Stream_data(self);
stream->machine = um_get_machine(machine);
stream->fd = NUM2ULONG(fd);
stream->buffer = rb_utf8_str_new_literal("");
rb_str_resize(stream->buffer, 1 << 16); // 64KB
rb_str_set_len(stream->buffer, 0);
stream->len = 0;
stream->pos = 0;
stream->eof = 0;
return self;
}
|
Class Method Details
.resp_encode(str, obj) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'ext/um/um_stream_class.c', line 78
VALUE Stream_resp_encode(VALUE self, VALUE str, VALUE obj) {
struct um_write_buffer buf;
write_buffer_init(&buf, str);
rb_str_modify(str);
resp_encode(&buf, obj);
write_buffer_update_len(&buf);
return str;
}
|
Instance Method Details
#get_line(buf, limit) ⇒ Object
54 55 56 57 58 59 |
# File 'ext/um/um_stream_class.c', line 54
VALUE Stream_get_line(VALUE self, VALUE buf, VALUE limit) {
struct um_stream *stream = Stream_data(self);
if (unlikely(stream->eof)) return Qnil;
return stream_get_line(stream, buf, NUM2LONG(limit));
}
|
#get_string(buf, len) ⇒ Object
61 62 63 64 65 66 |
# File 'ext/um/um_stream_class.c', line 61
VALUE Stream_get_string(VALUE self, VALUE buf, VALUE len) {
struct um_stream *stream = Stream_data(self);
if (unlikely(stream->eof)) return Qnil;
return stream_get_string(stream, buf, NUM2LONG(len));
}
|
#resp_decode ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'ext/um/um_stream_class.c', line 68
VALUE Stream_resp_decode(VALUE self) {
struct um_stream *stream = Stream_data(self);
if (unlikely(stream->eof)) return Qnil;
VALUE out_buffer = rb_utf8_str_new_literal("");
VALUE obj = resp_decode(stream, out_buffer);
RB_GC_GUARD(out_buffer);
return obj;
}
|