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
- #fd ⇒ Object
- #get_line(buf, limit) ⇒ Object
- #get_string(buf, len) ⇒ Object
- #initialize(machine, fd) ⇒ Object constructor
- #machine ⇒ Object
- #resp_decode ⇒ Object
-
#skip(len) ⇒ Object
encountered.
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
96 97 98 99 100 101 102 103 |
# File 'ext/um/um_stream_class.c', line 96 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; } |
.resp_encode_cmd(*args) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/um/um_stream_class.c', line 105 VALUE Stream_resp_encode_cmd(int argc, VALUE *argv, VALUE self) { struct um_write_buffer buf; VALUE str; rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS); str = argv[0]; write_buffer_init(&buf, str); rb_str_modify(str); resp_encode_cmd(&buf, argc - 1, argv + 1); write_buffer_update_len(&buf); return str; } |
Instance Method Details
#fd ⇒ Object
59 60 61 62 |
# File 'ext/um/um_stream_class.c', line 59 VALUE Stream_fd(VALUE self) { struct um_stream *stream = Stream_data(self); return ULONG2NUM(stream->fd); } |
#get_line(buf, limit) ⇒ Object
64 65 66 67 68 69 |
# File 'ext/um/um_stream_class.c', line 64 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
71 72 73 74 75 76 |
# File 'ext/um/um_stream_class.c', line 71 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)); } |
#machine ⇒ Object
54 55 56 57 |
# File 'ext/um/um_stream_class.c', line 54 VALUE Stream_machine(VALUE self) { struct um_stream *stream = Stream_data(self); return stream->machine->self; } |
#resp_decode ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'ext/um/um_stream_class.c', line 86 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; } |
#skip(len) ⇒ Object
encountered.
80 81 82 83 84 |
# File 'ext/um/um_stream_class.c', line 80 VALUE Stream_skip(VALUE self, VALUE len) { struct um_stream *stream = Stream_data(self); return stream_skip(stream, NUM2LONG(len)); } |