/**
 * 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.stream = stream;
        mp->user.streambuf = rb_str_buf_new(MSGPACK_UNPACKER_BUFFER_RESERVE_SIZE);
        mp->user.stream_append_method = append_method_of(stream);
        mp->user.buffer_free_size = MSGPACK_BUFFER_FREE_SIZE;

        return self;
}