Class: MessagePack::Unpacker

Inherits:
Object
  • Object
show all
Defined in:
ext/msgpack/unpacker_class.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/msgpack/unpacker_class.c', line 61

static VALUE Unpacker_initialize(int argc, VALUE* argv, VALUE self)
{
    VALUE io = Qnil;
    VALUE options = Qnil;

    if(argc == 0 || (argc == 1 && argv[0] == Qnil)) {
        /* Qnil */

    } else if(argc == 1) {
        VALUE v = argv[0];
        if(rb_type(v) == T_HASH) {
            options = v;
            if(rb_type(options) != T_HASH) {
                rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
            }
        } else {
            io = v;
        }

    } else if(argc == 2) {
        io = argv[0];
        options = argv[1];
        if(rb_type(options) != T_HASH) {
            rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
        }

    } else {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
    }

    UNPACKER(self, uk);

    MessagePack_Unpacker_initialize(uk, io, options);

    return self;
}

Instance Method Details

#bufferObject



126
127
128
129
130
# File 'ext/msgpack/unpacker_class.c', line 126

static VALUE Unpacker_buffer(VALUE self)
{
    UNPACKER(self, uk);
    return uk->buffer_ref;
}

#eachObject



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'ext/msgpack/unpacker_class.c', line 266

static VALUE Unpacker_each(VALUE self)
{
    UNPACKER(self, uk);

#ifdef RETURN_ENUMERATOR
    RETURN_ENUMERATOR(self, 0, 0);
#endif

    if(msgpack_buffer_has_io(UNPACKER_BUFFER_(uk))) {
        /* rescue EOFError only if io is set */
        return rb_rescue2(Unpacker_each_impl, self,
                Unpacker_rescue_EOFError, self,
                rb_eEOFError, NULL);
    } else {
        return Unpacker_each_impl(self);
    }
}

#feed(data) ⇒ Object

rb_define_method(cMessagePack_Unpacker, “peek_next_type”, Unpacker_peek_next_type, 0); // TODO



226
227
228
229
230
231
232
233
234
235
# File 'ext/msgpack/unpacker_class.c', line 226

static VALUE Unpacker_feed(VALUE self, VALUE data)
{
    UNPACKER(self, uk);

    StringValue(data);

    msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), data);

    return self;
}

#feed_each(data) ⇒ Object



284
285
286
287
288
289
# File 'ext/msgpack/unpacker_class.c', line 284

static VALUE Unpacker_feed_each(VALUE self, VALUE data)
{
    // TODO optimize
    Unpacker_feed(self, data);
    return Unpacker_each(self);
}

#readObject Also known as: unpack



132
133
134
135
136
137
138
139
140
141
142
# File 'ext/msgpack/unpacker_class.c', line 132

static VALUE Unpacker_read(VALUE self)
{
    UNPACKER(self, uk);

    int r = msgpack_unpacker_read(uk, 0);
    if(r < 0) {
        raise_unpacker_error(r);
    }

    return msgpack_unpacker_get_last_object(uk);
}

#read_array_headerObject



171
172
173
174
175
176
177
178
179
180
181
182
# File 'ext/msgpack/unpacker_class.c', line 171

static VALUE Unpacker_read_array_header(VALUE self)
{
    UNPACKER(self, uk);

    uint32_t size;
    int r = msgpack_unpacker_read_array_header(uk, &size);
    if(r < 0) {
        raise_unpacker_error(r);
    }

    return ULONG2NUM(size);
}

#read_map_headerObject



184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/msgpack/unpacker_class.c', line 184

static VALUE Unpacker_read_map_header(VALUE self)
{
    UNPACKER(self, uk);

    uint32_t size;
    int r = msgpack_unpacker_read_map_header(uk, &size);
    if(r < 0) {
        raise_unpacker_error((int)r);
    }

    return ULONG2NUM(size);
}

#resetObject



291
292
293
294
295
296
297
298
# File 'ext/msgpack/unpacker_class.c', line 291

static VALUE Unpacker_reset(VALUE self)
{
    UNPACKER(self, uk);

    msgpack_unpacker_reset(uk);

    return Qnil;
}

#skipObject



144
145
146
147
148
149
150
151
152
153
154
# File 'ext/msgpack/unpacker_class.c', line 144

static VALUE Unpacker_skip(VALUE self)
{
    UNPACKER(self, uk);

    int r = msgpack_unpacker_skip(uk, 0);
    if(r < 0) {
        raise_unpacker_error(r);
    }

    return Qnil;
}

#skip_nilObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'ext/msgpack/unpacker_class.c', line 156

static VALUE Unpacker_skip_nil(VALUE self)
{
    UNPACKER(self, uk);

    int r = msgpack_unpacker_skip_nil(uk);
    if(r < 0) {
        raise_unpacker_error(r);
    }

    if(r) {
        return Qtrue;
    }
    return Qfalse;
}