/** * Document-method: MessagePack::Unpacker#stream= * * call-seq: * unpacker.stream = stream * * Resets the input stream. You can set nil not to use input stream. */ static VALUE MessagePack_Unpacker_stream_set(VALUE self, VALUE val) { UNPACKER(self, mp); mp->user.stream = val; mp->user.stream_append_method = append_method_of(val); return val; }
/** * Document-method: MessagePack::Unpacker#initialize * * call-seq: * MessagePack::Unpacker.new(stream = nil) * * Creates instance of MessagePack::Unpacker. * * You can specify a _stream_ for input stream. * It is required to implement *sysread* or *readpartial* method. * * With the input stream, buffers will be feeded into the deserializer automatically. * * Without the input stream, use *feed* method manually. Or you can manage the buffer manually * with *execute*, *finished?*, *data* and *reset* methods. */ static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self) { VALUE stream; switch(argc) { case 0: stream = Qnil; break; case 1: stream = argv[0]; break; default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); } UNPACKER(self, mp); template_init(mp); mp->user.finished = 0; mp->user.offset = 0; mp->user.buffer.size = 0; mp->user.buffer.free = 0; mp->user.buffer.ptr = NULL; mp->user.stream = stream; mp->user.streambuf = rb_str_buf_new(MSGPACK_UNPACKER_BUFFER_RESERVE_SIZE); mp->user.stream_append_method = append_method_of(stream); return self; }