hx_cbor 2021.8.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +30 -0
  3. data/.travis.yml +24 -0
  4. data/ChangeLog +106 -0
  5. data/Gemfile +11 -0
  6. data/README.rdoc +191 -0
  7. data/Rakefile +97 -0
  8. data/doclib/cbor.rb +80 -0
  9. data/doclib/cbor/buffer.rb +193 -0
  10. data/doclib/cbor/core_ext.rb +133 -0
  11. data/doclib/cbor/error.rb +14 -0
  12. data/doclib/cbor/packer.rb +133 -0
  13. data/doclib/cbor/simple.rb +15 -0
  14. data/doclib/cbor/tagged.rb +16 -0
  15. data/doclib/cbor/unpacker.rb +138 -0
  16. data/ext/cbor/3424.i.rb +29 -0
  17. data/ext/cbor/buffer.c +693 -0
  18. data/ext/cbor/buffer.h +484 -0
  19. data/ext/cbor/buffer_class.c +516 -0
  20. data/ext/cbor/buffer_class.h +41 -0
  21. data/ext/cbor/cbor.h +69 -0
  22. data/ext/cbor/compat.h +147 -0
  23. data/ext/cbor/core_ext.c +201 -0
  24. data/ext/cbor/core_ext.h +35 -0
  25. data/ext/cbor/example.rb +10 -0
  26. data/ext/cbor/extconf.rb +29 -0
  27. data/ext/cbor/install.sh +1 -0
  28. data/ext/cbor/packer.c +169 -0
  29. data/ext/cbor/packer.h +362 -0
  30. data/ext/cbor/packer_class.c +304 -0
  31. data/ext/cbor/packer_class.h +39 -0
  32. data/ext/cbor/rbinit.c +51 -0
  33. data/ext/cbor/renamer.h +56 -0
  34. data/ext/cbor/rmem.c +103 -0
  35. data/ext/cbor/rmem.h +118 -0
  36. data/ext/cbor/sysdep.h +139 -0
  37. data/ext/cbor/sysdep_endian.h +59 -0
  38. data/ext/cbor/sysdep_types.h +55 -0
  39. data/ext/cbor/unpacker.c +784 -0
  40. data/ext/cbor/unpacker.h +135 -0
  41. data/ext/cbor/unpacker_class.c +439 -0
  42. data/ext/cbor/unpacker_class.h +39 -0
  43. data/hx_cbor.gemspec +25 -0
  44. data/lib/cbor.rb +6 -0
  45. data/lib/cbor/version.rb +3 -0
  46. data/spec/buffer_io_spec.rb +260 -0
  47. data/spec/buffer_spec.rb +576 -0
  48. data/spec/cases.cbor +0 -0
  49. data/spec/cases.cbor_stream +0 -0
  50. data/spec/cases.json +1 -0
  51. data/spec/cases.msg +0 -0
  52. data/spec/cases_compact.msg +0 -0
  53. data/spec/cases_spec.rb +39 -0
  54. data/spec/format_spec.rb +540 -0
  55. data/spec/packer_spec.rb +127 -0
  56. data/spec/random_compat.rb +24 -0
  57. data/spec/spec_helper.rb +68 -0
  58. data/spec/unpacker_spec.rb +260 -0
  59. metadata +198 -0
@@ -0,0 +1,135 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+ #ifndef MSGPACK_RUBY_UNPACKER_H__
28
+ #define MSGPACK_RUBY_UNPACKER_H__
29
+
30
+ #include "buffer.h"
31
+
32
+ #ifndef MSGPACK_UNPACKER_STACK_CAPACITY
33
+ #define MSGPACK_UNPACKER_STACK_CAPACITY 128
34
+ #endif
35
+
36
+ struct msgpack_unpacker_t;
37
+ typedef struct msgpack_unpacker_t msgpack_unpacker_t;
38
+
39
+ enum stack_type_t {
40
+ STACK_TYPE_ARRAY,
41
+ STACK_TYPE_MAP_KEY,
42
+ STACK_TYPE_MAP_VALUE,
43
+ STACK_TYPE_TAG, /* > TAG = indef */
44
+ STACK_TYPE_MAP_VALUE_INDEF, /* Cannot BREAK up to here */
45
+ STACK_TYPE_MAP_KEY_INDEF,
46
+ STACK_TYPE_ARRAY_INDEF,
47
+ STACK_TYPE_STRING_INDEF,
48
+ };
49
+
50
+ typedef struct {
51
+ size_t count;
52
+ enum stack_type_t type;
53
+ VALUE object;
54
+ VALUE key;
55
+ uint64_t tag; /* could be union... */
56
+ } msgpack_unpacker_stack_t;
57
+
58
+ #define MSGPACK_UNPACKER_STACK_SIZE (8+4+8+8+8) /* assumes size_t <= 64bit, enum <= 32bit, VALUE <= 64bit */
59
+
60
+ struct msgpack_unpacker_t {
61
+ msgpack_buffer_t buffer;
62
+
63
+ unsigned int head_byte;
64
+
65
+ msgpack_unpacker_stack_t* stack;
66
+ size_t stack_depth;
67
+ size_t stack_capacity;
68
+
69
+ VALUE last_object;
70
+
71
+ VALUE reading_raw;
72
+ size_t reading_raw_remaining;
73
+ int textflag;
74
+
75
+ bool keys_as_symbols; /* Experimental */
76
+
77
+ bool tolerant; //!< Tolerant.
78
+
79
+ VALUE buffer_ref;
80
+ };
81
+
82
+ #define UNPACKER_BUFFER_(uk) (&(uk)->buffer)
83
+
84
+ enum msgpack_unpacker_object_type {
85
+ TYPE_NIL = 0,
86
+ TYPE_BOOLEAN,
87
+ TYPE_INTEGER,
88
+ TYPE_FLOAT,
89
+ TYPE_RAW,
90
+ TYPE_ARRAY,
91
+ TYPE_MAP,
92
+ };
93
+
94
+ void msgpack_unpacker_static_init();
95
+
96
+ void msgpack_unpacker_static_destroy();
97
+
98
+ void msgpack_unpacker_init(msgpack_unpacker_t* uk);
99
+
100
+ void msgpack_unpacker_destroy(msgpack_unpacker_t* uk);
101
+
102
+ void msgpack_unpacker_mark(msgpack_unpacker_t* uk);
103
+
104
+ void msgpack_unpacker_reset(msgpack_unpacker_t* uk);
105
+
106
+
107
+ /* error codes */
108
+ #define PRIMITIVE_CONTAINER_START 1
109
+ #define PRIMITIVE_OBJECT_COMPLETE 0
110
+ #define PRIMITIVE_EOF -1
111
+ #define PRIMITIVE_INVALID_BYTE -2
112
+ #define PRIMITIVE_STACK_TOO_DEEP -3
113
+ #define PRIMITIVE_UNEXPECTED_TYPE -4
114
+ #define PRIMITIVE_BREAK 2
115
+
116
+ int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth);
117
+
118
+ int msgpack_unpacker_skip(msgpack_unpacker_t* uk, size_t target_stack_depth);
119
+
120
+ static inline VALUE msgpack_unpacker_get_last_object(msgpack_unpacker_t* uk)
121
+ {
122
+ return uk->last_object;
123
+ }
124
+
125
+
126
+ int msgpack_unpacker_peek_next_object_type(msgpack_unpacker_t* uk);
127
+
128
+ int msgpack_unpacker_skip_nil(msgpack_unpacker_t* uk);
129
+
130
+ int msgpack_unpacker_read_array_header(msgpack_unpacker_t* uk, uint64_t* result_size);
131
+
132
+ int msgpack_unpacker_read_map_header(msgpack_unpacker_t* uk, uint64_t* result_size);
133
+
134
+ #endif
135
+
@@ -0,0 +1,439 @@
1
+ /*
2
+ * CBOR for Ruby
3
+ *
4
+ * Copyright (C) 2013 Carsten Bormann
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License").
7
+ *
8
+ * Based on:
9
+ ***********/
10
+ /*
11
+ * MessagePack for Ruby
12
+ *
13
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ #include "unpacker.h"
29
+ #include "unpacker_class.h"
30
+ #include "buffer_class.h"
31
+
32
+ VALUE cMessagePack_Unpacker;
33
+
34
+ //static VALUE s_unpacker_value;
35
+ //static msgpack_unpacker_t* s_unpacker;
36
+
37
+ static VALUE eUnpackError;
38
+ static VALUE eMalformedFormatError;
39
+ static VALUE eStackError;
40
+ static VALUE eTypeError;
41
+
42
+ #define UNPACKER(from, name) \
43
+ msgpack_unpacker_t *name = NULL; \
44
+ Data_Get_Struct(from, msgpack_unpacker_t, name); \
45
+ if(name == NULL) { \
46
+ rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
47
+ }
48
+
49
+ static void Unpacker_free(msgpack_unpacker_t* uk)
50
+ {
51
+ if(uk == NULL) {
52
+ return;
53
+ }
54
+ msgpack_unpacker_destroy(uk);
55
+ free(uk);
56
+ }
57
+
58
+ static VALUE Unpacker_alloc(VALUE klass)
59
+ {
60
+ msgpack_unpacker_t* uk = ALLOC_N(msgpack_unpacker_t, 1);
61
+ msgpack_unpacker_init(uk);
62
+
63
+ VALUE self = Data_Wrap_Struct(klass, msgpack_unpacker_mark, Unpacker_free, uk);
64
+
65
+ uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self);
66
+
67
+ return self;
68
+ }
69
+
70
+ static VALUE Unpacker_initialize(int argc, VALUE* argv, VALUE self)
71
+ {
72
+ VALUE io = Qnil;
73
+ VALUE options = Qnil;
74
+
75
+ if(argc == 0 || (argc == 1 && argv[0] == Qnil)) {
76
+ /* Qnil */
77
+
78
+ } else if(argc == 1) {
79
+ VALUE v = argv[0];
80
+ if(rb_type(v) == T_HASH) {
81
+ options = v;
82
+ } else {
83
+ io = v;
84
+ }
85
+
86
+ } else if(argc == 2) {
87
+ io = argv[0];
88
+ options = argv[1];
89
+ if(rb_type(options) != T_HASH) {
90
+ rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
91
+ }
92
+
93
+ } else {
94
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
95
+ }
96
+
97
+ UNPACKER(self, uk);
98
+ if(io != Qnil || options != Qnil) {
99
+ MessagePack_Buffer_initialize(UNPACKER_BUFFER_(uk), io, options);
100
+ if (options != Qnil) {
101
+ VALUE v;
102
+ v = rb_hash_aref(options, ID2SYM(rb_intern("symbolize_keys")));
103
+ uk->keys_as_symbols = RTEST(v);
104
+ }
105
+ }
106
+
107
+ // TODO options
108
+
109
+ return self;
110
+ }
111
+
112
+ static void raise_unpacker_error(int r)
113
+ {
114
+ switch(r) {
115
+ case PRIMITIVE_EOF:
116
+ rb_raise(rb_eEOFError, "end of buffer reached");
117
+ case PRIMITIVE_INVALID_BYTE:
118
+ rb_raise(eMalformedFormatError, "invalid byte");
119
+ case PRIMITIVE_STACK_TOO_DEEP:
120
+ rb_raise(eStackError, "stack level too deep");
121
+ case PRIMITIVE_UNEXPECTED_TYPE:
122
+ rb_raise(eTypeError, "unexpected type");
123
+ default:
124
+ rb_raise(eUnpackError, "logically unknown error %d", r);
125
+ }
126
+ }
127
+
128
+ static VALUE Unpacker_buffer(VALUE self)
129
+ {
130
+ UNPACKER(self, uk);
131
+ return uk->buffer_ref;
132
+ }
133
+
134
+ static VALUE Unpacker_read(VALUE self)
135
+ {
136
+ UNPACKER(self, uk);
137
+
138
+ int r = msgpack_unpacker_read(uk, 0);
139
+ if(r < 0) {
140
+ raise_unpacker_error(r);
141
+ }
142
+
143
+ return msgpack_unpacker_get_last_object(uk);
144
+ }
145
+
146
+ static VALUE Unpacker_skip(VALUE self)
147
+ {
148
+ UNPACKER(self, uk);
149
+
150
+ int r = msgpack_unpacker_skip(uk, 0);
151
+ if(r < 0) {
152
+ raise_unpacker_error(r);
153
+ }
154
+
155
+ return Qnil;
156
+ }
157
+
158
+ static VALUE Unpacker_skip_nil(VALUE self)
159
+ {
160
+ UNPACKER(self, uk);
161
+
162
+ int r = msgpack_unpacker_skip_nil(uk);
163
+ if(r < 0) {
164
+ raise_unpacker_error(r);
165
+ }
166
+
167
+ if(r) {
168
+ return Qtrue;
169
+ }
170
+ return Qfalse;
171
+ }
172
+
173
+ static VALUE Unpacker_read_array_header(VALUE self)
174
+ {
175
+ UNPACKER(self, uk);
176
+
177
+ uint64_t size;
178
+ int r = msgpack_unpacker_read_array_header(uk, &size);
179
+ if(r < 0) {
180
+ raise_unpacker_error(r);
181
+ }
182
+
183
+ return rb_ull2inum(size);
184
+ }
185
+
186
+ static VALUE Unpacker_read_map_header(VALUE self)
187
+ {
188
+ UNPACKER(self, uk);
189
+
190
+ uint64_t size;
191
+ int r = msgpack_unpacker_read_map_header(uk, &size);
192
+ if(r < 0) {
193
+ raise_unpacker_error((int)r);
194
+ }
195
+
196
+ return rb_ull2inum(size);
197
+ }
198
+
199
+ #if 0
200
+ static VALUE Unpacker_peek_next_type(VALUE self)
201
+ {
202
+ UNPACKER(self, uk);
203
+
204
+ int r = msgpack_unpacker_peek_next_object_type(uk);
205
+ if(r < 0) {
206
+ raise_unpacker_error(r);
207
+ }
208
+
209
+ switch((enum msgpack_unpacker_object_type) r) {
210
+ case TYPE_NIL:
211
+ return rb_intern("nil");
212
+ case TYPE_BOOLEAN:
213
+ return rb_intern("boolean");
214
+ case TYPE_INTEGER:
215
+ return rb_intern("integer");
216
+ case TYPE_FLOAT:
217
+ return rb_intern("float");
218
+ case TYPE_RAW:
219
+ return rb_intern("raw");
220
+ case TYPE_ARRAY:
221
+ return rb_intern("array");
222
+ case TYPE_MAP:
223
+ return rb_intern("map");
224
+ default:
225
+ rb_raise(eUnpackError, "logically unknown type %d", r);
226
+ }
227
+ }
228
+ #endif
229
+
230
+ static VALUE Unpacker_feed(VALUE self, VALUE data)
231
+ {
232
+ UNPACKER(self, uk);
233
+
234
+ StringValue(data);
235
+
236
+ msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), data);
237
+
238
+ return self;
239
+ }
240
+
241
+ static VALUE Unpacker_each_impl(VALUE self)
242
+ {
243
+ UNPACKER(self, uk);
244
+
245
+ while(true) {
246
+ int r = msgpack_unpacker_read(uk, 0);
247
+ if(r < 0) {
248
+ if(r == PRIMITIVE_EOF) {
249
+ return Qnil;
250
+ }
251
+ raise_unpacker_error(r);
252
+ }
253
+ VALUE v = msgpack_unpacker_get_last_object(uk);
254
+ #ifdef JRUBY
255
+ /* TODO JRuby's rb_yield behaves differently from Ruby 1.9.3 or Rubinius. */
256
+ if(rb_type(v) == T_ARRAY) {
257
+ v = rb_ary_new3(1, v);
258
+ }
259
+ #endif
260
+ rb_yield(v);
261
+ }
262
+ }
263
+
264
+ static VALUE Unpacker_rescue_EOFError(VALUE self)
265
+ {
266
+ UNUSED(self);
267
+ return Qnil;
268
+ }
269
+
270
+ static VALUE Unpacker_each(VALUE self)
271
+ {
272
+ UNPACKER(self, uk);
273
+
274
+ #ifdef RETURN_ENUMERATOR
275
+ RETURN_ENUMERATOR(self, 0, 0);
276
+ #endif
277
+
278
+ if(msgpack_buffer_has_io(UNPACKER_BUFFER_(uk))) {
279
+ /* rescue EOFError only if io is set */
280
+ return rb_rescue2(Unpacker_each_impl, self,
281
+ Unpacker_rescue_EOFError, self,
282
+ rb_eEOFError, NULL);
283
+ } else {
284
+ return Unpacker_each_impl(self);
285
+ }
286
+ }
287
+
288
+ static VALUE Unpacker_feed_each(VALUE self, VALUE data)
289
+ {
290
+ // TODO optimize
291
+ Unpacker_feed(self, data);
292
+ return Unpacker_each(self);
293
+ }
294
+
295
+ static VALUE Unpacker_reset(VALUE self)
296
+ {
297
+ UNPACKER(self, uk);
298
+
299
+ msgpack_unpacker_reset(uk);
300
+
301
+ return Qnil;
302
+ }
303
+
304
+ VALUE MessagePack_unpack(int argc, VALUE* argv)
305
+ {
306
+ VALUE src;
307
+ VALUE options = Qnil;
308
+ bool keys_as_symbols = false;
309
+ bool tolerant = false;
310
+
311
+ switch(argc) {
312
+ case 2:
313
+ options = argv[1]; /* Experimental! */
314
+ if (options == ID2SYM(rb_intern("keys_as_symbols"))) /* backward compat */
315
+ keys_as_symbols = true;
316
+ else if (options != Qnil) {
317
+ VALUE v;
318
+ if (!RB_TYPE_P(options, T_HASH)) {
319
+ rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
320
+ }
321
+ v = rb_hash_aref(options, ID2SYM(rb_intern("symbolize_keys")));
322
+ keys_as_symbols = RTEST(v);
323
+
324
+ v = rb_hash_aref(options, ID2SYM(rb_intern("tolerant")));
325
+ tolerant = RTEST(v);
326
+ }
327
+ /* fall through */
328
+ case 1:
329
+ src = argv[0];
330
+ break;
331
+ default:
332
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
333
+ }
334
+
335
+ VALUE io = Qnil;
336
+ if(rb_type(src) != T_STRING) {
337
+ io = src;
338
+ src = Qnil;
339
+ }
340
+
341
+ VALUE self = Unpacker_alloc(cMessagePack_Unpacker);
342
+ UNPACKER(self, uk);
343
+ //msgpack_unpacker_reset(s_unpacker);
344
+ //msgpack_buffer_reset_io(UNPACKER_BUFFER_(s_unpacker));
345
+
346
+ /* prefer reference than copying */
347
+ msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(uk), 0);
348
+
349
+ uk->keys_as_symbols = keys_as_symbols;
350
+ uk->tolerant = tolerant;
351
+
352
+ if(io != Qnil) {
353
+ MessagePack_Buffer_initialize(UNPACKER_BUFFER_(uk), io, Qnil);
354
+ }
355
+
356
+ if(src != Qnil) {
357
+ /* prefer reference than copying; see MessagePack_Unpacker_module_init */
358
+ msgpack_buffer_append_string(UNPACKER_BUFFER_(uk), src);
359
+ }
360
+
361
+ int r = msgpack_unpacker_read(uk, 0);
362
+ if(r < 0) {
363
+ if (!tolerant)
364
+ {
365
+ raise_unpacker_error(r);
366
+ }
367
+ }
368
+
369
+ /* raise if extra bytes follow */
370
+ if(msgpack_buffer_top_readable_size(UNPACKER_BUFFER_(uk)) > 0) {
371
+ if (!tolerant)
372
+ {
373
+ rb_raise(eMalformedFormatError, "extra bytes follow after a deserialized object");
374
+ }
375
+ }
376
+
377
+ #ifdef RB_GC_GUARD
378
+ /* This prevents compilers from optimizing out the `self` variable
379
+ * from stack. Otherwise GC free()s it. */
380
+ RB_GC_GUARD(self);
381
+ #endif
382
+
383
+ return msgpack_unpacker_get_last_object(uk);
384
+ }
385
+
386
+ static VALUE MessagePack_load_module_method(int argc, VALUE* argv, VALUE mod)
387
+ {
388
+ UNUSED(mod);
389
+ return MessagePack_unpack(argc, argv);
390
+ }
391
+
392
+ static VALUE MessagePack_unpack_module_method(int argc, VALUE* argv, VALUE mod)
393
+ {
394
+ UNUSED(mod);
395
+ return MessagePack_unpack(argc, argv);
396
+ }
397
+
398
+ void MessagePack_Unpacker_module_init(VALUE mMessagePack)
399
+ {
400
+ msgpack_unpacker_static_init();
401
+
402
+ cMessagePack_Unpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
403
+
404
+ eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
405
+
406
+ eMalformedFormatError = rb_define_class_under(mMessagePack, "MalformedFormatError", eUnpackError);
407
+
408
+ eStackError = rb_define_class_under(mMessagePack, "StackError", eUnpackError);
409
+
410
+ eTypeError = rb_define_class_under(mMessagePack, "TypeError", rb_eStandardError);
411
+
412
+ rb_define_alloc_func(cMessagePack_Unpacker, Unpacker_alloc);
413
+
414
+ rb_define_method(cMessagePack_Unpacker, "initialize", Unpacker_initialize, -1);
415
+ rb_define_method(cMessagePack_Unpacker, "buffer", Unpacker_buffer, 0);
416
+ rb_define_method(cMessagePack_Unpacker, "read", Unpacker_read, 0);
417
+ rb_define_alias(cMessagePack_Unpacker, "unpack", "read");
418
+ rb_define_method(cMessagePack_Unpacker, "skip", Unpacker_skip, 0);
419
+ rb_define_method(cMessagePack_Unpacker, "skip_nil", Unpacker_skip_nil, 0);
420
+ rb_define_method(cMessagePack_Unpacker, "read_array_header", Unpacker_read_array_header, 0);
421
+ rb_define_method(cMessagePack_Unpacker, "read_map_header", Unpacker_read_map_header, 0);
422
+ //rb_define_method(cMessagePack_Unpacker, "peek_next_type", Unpacker_peek_next_type, 0); // TODO
423
+ rb_define_method(cMessagePack_Unpacker, "feed", Unpacker_feed, 1);
424
+ rb_define_method(cMessagePack_Unpacker, "each", Unpacker_each, 0);
425
+ rb_define_method(cMessagePack_Unpacker, "feed_each", Unpacker_feed_each, 1);
426
+ rb_define_method(cMessagePack_Unpacker, "reset", Unpacker_reset, 0);
427
+
428
+ //s_unpacker_value = Unpacker_alloc(cMessagePack_Unpacker);
429
+ //rb_gc_register_address(&s_unpacker_value);
430
+ //Data_Get_Struct(s_unpacker_value, msgpack_unpacker_t, s_unpacker);
431
+ /* prefer reference than copying */
432
+ //msgpack_buffer_set_write_reference_threshold(UNPACKER_BUFFER_(s_unpacker), 0);
433
+
434
+ /* MessagePack.unpack(x) */
435
+ rb_define_module_function(mMessagePack, "load", MessagePack_load_module_method, -1);
436
+ rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack_module_method, -1);
437
+ rb_define_module_function(mMessagePack, "decode", MessagePack_unpack_module_method, -1);
438
+ }
439
+