gitlab-cbor 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.gitlab-ci.yml +44 -0
  4. data/.travis.yml +24 -0
  5. data/CHANGELOG.md +30 -0
  6. data/ChangeLog +106 -0
  7. data/Gemfile +11 -0
  8. data/README.rdoc +191 -0
  9. data/Rakefile +97 -0
  10. data/ci/test.rb +31 -0
  11. data/doclib/cbor/buffer.rb +193 -0
  12. data/doclib/cbor/core_ext.rb +133 -0
  13. data/doclib/cbor/error.rb +14 -0
  14. data/doclib/cbor/packer.rb +133 -0
  15. data/doclib/cbor/simple.rb +15 -0
  16. data/doclib/cbor/tagged.rb +16 -0
  17. data/doclib/cbor/unpacker.rb +138 -0
  18. data/doclib/cbor.rb +80 -0
  19. data/ext/cbor/buffer.c +693 -0
  20. data/ext/cbor/buffer.h +484 -0
  21. data/ext/cbor/buffer_class.c +561 -0
  22. data/ext/cbor/buffer_class.h +41 -0
  23. data/ext/cbor/cbor.h +69 -0
  24. data/ext/cbor/compat.h +147 -0
  25. data/ext/cbor/core_ext.c +199 -0
  26. data/ext/cbor/core_ext.h +35 -0
  27. data/ext/cbor/extconf.rb +29 -0
  28. data/ext/cbor/packer.c +169 -0
  29. data/ext/cbor/packer.h +370 -0
  30. data/ext/cbor/packer_class.c +345 -0
  31. data/ext/cbor/packer_class.h +40 -0
  32. data/ext/cbor/rbinit.c +57 -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 +787 -0
  40. data/ext/cbor/unpacker.h +135 -0
  41. data/ext/cbor/unpacker_class.c +483 -0
  42. data/ext/cbor/unpacker_class.h +39 -0
  43. data/gitlab-cbor.gemspec +27 -0
  44. data/lib/cbor/version.rb +3 -0
  45. data/lib/cbor.rb +6 -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 +603 -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 +189 -0
@@ -0,0 +1,561 @@
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 "compat.h"
29
+ #include "ruby.h"
30
+ #include "buffer.h"
31
+ #include "buffer_class.h"
32
+
33
+ VALUE cMessagePack_Buffer;
34
+
35
+ static ID s_read;
36
+ static ID s_readpartial;
37
+ static ID s_write;
38
+ static ID s_append;
39
+ static ID s_close;
40
+
41
+ static msgpack_buffer_t* Buffer_get(VALUE self);
42
+
43
+ #define BUFFER(from, name) \
44
+ msgpack_buffer_t *name = Buffer_get(from); \
45
+ if(name == NULL) { \
46
+ rb_raise(rb_eArgError, "NULL found for " # name " when shouldn't be."); \
47
+ }
48
+
49
+ #define CHECK_STRING_TYPE(value) \
50
+ value = rb_check_string_type(value); \
51
+ if( NIL_P(value) ) { \
52
+ rb_raise(rb_eTypeError, "instance of String needed"); \
53
+ }
54
+
55
+ static void Buffer_mark(void* data)
56
+ {
57
+ msgpack_buffer_t* b = data;
58
+ msgpack_buffer_mark(b);
59
+ }
60
+
61
+ static void Buffer_free(void* data)
62
+ {
63
+ if(data == NULL) {
64
+ return;
65
+ }
66
+ msgpack_buffer_t* b = data;
67
+ msgpack_buffer_destroy(b);
68
+ xfree(data);
69
+ }
70
+
71
+ #ifdef TypedData_Make_Struct
72
+ static size_t Buffer_memsize(const void* data)
73
+ {
74
+ return data == NULL ? 0 : sizeof(msgpack_buffer_t);
75
+ }
76
+
77
+ static const rb_data_type_t buffer_data_type = {
78
+ "CBOR::Buffer",
79
+ {Buffer_mark, Buffer_free, Buffer_memsize,},
80
+ NULL, NULL, 0
81
+ };
82
+
83
+ static const rb_data_type_t wrapped_buffer_data_type = {
84
+ "CBOR::WrappedBuffer",
85
+ {Buffer_mark, NULL, Buffer_memsize,},
86
+ &buffer_data_type, NULL, 0
87
+ };
88
+ #endif
89
+
90
+ static msgpack_buffer_t* Buffer_get(VALUE self)
91
+ {
92
+ msgpack_buffer_t* b = NULL;
93
+ #ifdef TypedData_Make_Struct
94
+ TypedData_Get_Struct(self, msgpack_buffer_t, &buffer_data_type, b);
95
+ #else
96
+ Data_Get_Struct(self, msgpack_buffer_t, b);
97
+ #endif
98
+ return b;
99
+ }
100
+
101
+ static VALUE Buffer_alloc(VALUE klass)
102
+ {
103
+ msgpack_buffer_t* b;
104
+ VALUE self;
105
+ #ifdef TypedData_Make_Struct
106
+ self = TypedData_Make_Struct(klass, msgpack_buffer_t, &buffer_data_type, b);
107
+ #else
108
+ self = Data_Make_Struct(klass, msgpack_buffer_t, Buffer_mark, Buffer_free, b);
109
+ #endif
110
+ msgpack_buffer_init(b);
111
+
112
+ return self;
113
+ }
114
+
115
+ static ID get_partial_read_method(VALUE io)
116
+ {
117
+ if(rb_respond_to(io, s_readpartial)) {
118
+ return s_readpartial;
119
+ } else {
120
+ return s_read;
121
+ }
122
+ }
123
+
124
+ static ID get_write_all_method(VALUE io)
125
+ {
126
+ if(rb_respond_to(io, s_write)) {
127
+ return s_write;
128
+ } else if(rb_respond_to(io, s_append)) {
129
+ return s_append;
130
+ } else {
131
+ return s_write;
132
+ }
133
+ }
134
+
135
+ void MessagePack_Buffer_initialize(msgpack_buffer_t* b, VALUE io, VALUE options)
136
+ {
137
+ b->io = io;
138
+ b->io_partial_read_method = get_partial_read_method(io);
139
+ b->io_write_all_method = get_write_all_method(io);
140
+
141
+ if(options != Qnil) {
142
+ VALUE v;
143
+
144
+ v = rb_hash_aref(options, ID2SYM(rb_intern("read_reference_threshold")));
145
+ if(v != Qnil) {
146
+ msgpack_buffer_set_read_reference_threshold(b, NUM2ULONG(v));
147
+ }
148
+
149
+ v = rb_hash_aref(options, ID2SYM(rb_intern("write_reference_threshold")));
150
+ if(v != Qnil) {
151
+ msgpack_buffer_set_write_reference_threshold(b, NUM2ULONG(v));
152
+ }
153
+
154
+ v = rb_hash_aref(options, ID2SYM(rb_intern("io_buffer_size")));
155
+ if(v != Qnil) {
156
+ msgpack_buffer_set_io_buffer_size(b, NUM2ULONG(v));
157
+ }
158
+ }
159
+ }
160
+
161
+ VALUE MessagePack_Buffer_wrap(msgpack_buffer_t* b, VALUE owner)
162
+ {
163
+ b->owner = owner;
164
+ #ifdef TypedData_Make_Struct
165
+ return TypedData_Wrap_Struct(cMessagePack_Buffer, &wrapped_buffer_data_type, b);
166
+ #else
167
+ return Data_Wrap_Struct(cMessagePack_Buffer, Buffer_mark, NULL, b);
168
+ #endif
169
+ }
170
+
171
+ static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self)
172
+ {
173
+ VALUE io = Qnil;
174
+ VALUE options = Qnil;
175
+
176
+ if(argc == 0 || (argc == 1 && argv[0] == Qnil)) {
177
+ /* Qnil */
178
+
179
+ } else if(argc == 1) {
180
+ VALUE v = argv[0];
181
+ if(rb_type(v) == T_HASH) {
182
+ options = v;
183
+ } else {
184
+ io = v;
185
+ }
186
+
187
+ } else if(argc == 2) {
188
+ io = argv[0];
189
+ options = argv[1];
190
+ if(rb_type(options) != T_HASH) {
191
+ rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(io));
192
+ }
193
+
194
+ } else {
195
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc);
196
+ }
197
+
198
+ BUFFER(self, b);
199
+
200
+ MessagePack_Buffer_initialize(b, io, options);
201
+
202
+ return self;
203
+ }
204
+
205
+ static VALUE Buffer_clear(VALUE self)
206
+ {
207
+ BUFFER(self, b);
208
+ msgpack_buffer_clear(b);
209
+ return Qnil;
210
+ }
211
+
212
+ static VALUE Buffer_size(VALUE self)
213
+ {
214
+ BUFFER(self, b);
215
+ size_t size = msgpack_buffer_all_readable_size(b);
216
+ return SIZET2NUM(size);
217
+ }
218
+
219
+ static VALUE Buffer_empty_p(VALUE self)
220
+ {
221
+ BUFFER(self, b);
222
+ if(msgpack_buffer_top_readable_size(b) == 0) {
223
+ return Qtrue;
224
+ } else {
225
+ return Qfalse;
226
+ }
227
+ }
228
+
229
+ static VALUE Buffer_write(VALUE self, VALUE string_or_buffer)
230
+ {
231
+ BUFFER(self, b);
232
+
233
+ VALUE string = string_or_buffer; // TODO optimize if string_or_buffer is a Buffer
234
+ StringValue(string);
235
+
236
+ size_t length = msgpack_buffer_append_string(b, string);
237
+
238
+ return SIZET2NUM(length);
239
+ }
240
+
241
+ static VALUE Buffer_append(VALUE self, VALUE string_or_buffer)
242
+ {
243
+ BUFFER(self, b);
244
+
245
+ VALUE string = string_or_buffer; // TODO optimize if string_or_buffer is a Buffer
246
+ StringValue(string);
247
+
248
+ msgpack_buffer_append_string(b, string);
249
+
250
+ return self;
251
+ }
252
+
253
+
254
+ #define MAKE_EMPTY_STRING(orig) \
255
+ if(orig == Qnil) { \
256
+ orig = rb_str_buf_new(0); \
257
+ } else { \
258
+ rb_str_resize(orig, 0); \
259
+ }
260
+
261
+ static VALUE read_until_eof_rescue(VALUE args)
262
+ {
263
+ msgpack_buffer_t* b = (void*) ((VALUE*) args)[0];
264
+ VALUE out = ((VALUE*) args)[1];
265
+ unsigned long max = ((VALUE*) args)[2];
266
+ size_t* sz = (void*) ((VALUE*) args)[3];
267
+
268
+ while(true) {
269
+ size_t rl;
270
+ if(max == 0) {
271
+ if(out == Qnil) {
272
+ rl = msgpack_buffer_skip(b, b->io_buffer_size);
273
+ } else {
274
+ rl = msgpack_buffer_read_to_string(b, out, b->io_buffer_size);
275
+ }
276
+ if(rl == 0) {
277
+ break;
278
+ }
279
+ *sz += rl;
280
+
281
+ } else {
282
+ if(out == Qnil) {
283
+ rl = msgpack_buffer_skip(b, max);
284
+ } else {
285
+ rl = msgpack_buffer_read_to_string(b, out, max);
286
+ }
287
+ if(rl == 0) {
288
+ break;
289
+ }
290
+ *sz += rl;
291
+ if(max <= rl) {
292
+ break;
293
+ } else {
294
+ max -= rl;
295
+ }
296
+ }
297
+ }
298
+
299
+ return Qnil;
300
+ }
301
+
302
+ static VALUE read_until_eof_error(VALUE args, VALUE error)
303
+ {
304
+ /* ignore EOFError */
305
+ UNUSED(args);
306
+ UNUSED(error);
307
+ return Qnil;
308
+ }
309
+
310
+ static inline size_t read_until_eof(msgpack_buffer_t* b, VALUE out, unsigned long max)
311
+ {
312
+ if(msgpack_buffer_has_io(b)) {
313
+ size_t sz = 0;
314
+ VALUE args[4] = { (VALUE)(void*) b, out, (VALUE) max, (VALUE)(void*) &sz };
315
+ rb_rescue2(read_until_eof_rescue, (VALUE)(void*) args,
316
+ read_until_eof_error, (VALUE)(void*) args,
317
+ rb_eEOFError, NULL);
318
+ return sz;
319
+
320
+ } else {
321
+ if(max == 0) {
322
+ max = ULONG_MAX;
323
+ }
324
+ if(out == Qnil) {
325
+ return msgpack_buffer_skip_nonblock(b, max);
326
+ } else {
327
+ return msgpack_buffer_read_to_string_nonblock(b, out, max);
328
+ }
329
+ }
330
+ }
331
+
332
+ static inline VALUE read_all(msgpack_buffer_t* b, VALUE out)
333
+ {
334
+ #ifndef DISABLE_BUFFER_READ_TO_S_OPTIMIZE
335
+ if(out == Qnil && !msgpack_buffer_has_io(b)) {
336
+ /* same as to_s && clear; optimize */
337
+ VALUE str = msgpack_buffer_all_as_string(b);
338
+ msgpack_buffer_clear(b);
339
+ return str;
340
+ }
341
+ #endif
342
+ MAKE_EMPTY_STRING(out);
343
+ read_until_eof(b, out, 0);
344
+ return out;
345
+ }
346
+
347
+ static VALUE Buffer_skip(VALUE self, VALUE sn)
348
+ {
349
+ BUFFER(self, b);
350
+
351
+ unsigned long n = FIX2ULONG(sn);
352
+
353
+ /* do nothing */
354
+ if(n == 0) {
355
+ return ULONG2NUM(0);
356
+ }
357
+
358
+ size_t sz = read_until_eof(b, Qnil, n);
359
+ return ULONG2NUM(sz);
360
+ }
361
+
362
+ static VALUE Buffer_skip_all(VALUE self, VALUE sn)
363
+ {
364
+ BUFFER(self, b);
365
+
366
+ unsigned long n = FIX2ULONG(sn);
367
+
368
+ /* do nothing */
369
+ if(n == 0) {
370
+ return self;
371
+ }
372
+
373
+ if(!msgpack_buffer_ensure_readable(b, n)) {
374
+ rb_raise(rb_eEOFError, "end of buffer reached");
375
+ }
376
+
377
+ msgpack_buffer_skip_nonblock(b, n);
378
+
379
+ return self;
380
+ }
381
+
382
+ static VALUE Buffer_read_all(int argc, VALUE* argv, VALUE self)
383
+ {
384
+ VALUE out = Qnil;
385
+ unsigned long n = 0;
386
+ bool all = false;
387
+
388
+ switch(argc) {
389
+ case 2:
390
+ out = argv[1];
391
+ /* pass through */
392
+ case 1:
393
+ n = FIX2ULONG(argv[0]);
394
+ break;
395
+ case 0:
396
+ all = true;
397
+ break;
398
+ default:
399
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
400
+ }
401
+
402
+ BUFFER(self, b);
403
+
404
+ if(out != Qnil) {
405
+ CHECK_STRING_TYPE(out);
406
+ }
407
+
408
+ if(all) {
409
+ return read_all(b, out);
410
+ }
411
+
412
+ if(n == 0) {
413
+ /* do nothing */
414
+ MAKE_EMPTY_STRING(out);
415
+ return out;
416
+ }
417
+
418
+ if(!msgpack_buffer_ensure_readable(b, n)) {
419
+ rb_raise(rb_eEOFError, "end of buffer reached");
420
+ }
421
+
422
+ MAKE_EMPTY_STRING(out);
423
+ msgpack_buffer_read_to_string_nonblock(b, out, n);
424
+
425
+ return out;
426
+ }
427
+
428
+ static VALUE Buffer_read(int argc, VALUE* argv, VALUE self)
429
+ {
430
+ VALUE out = Qnil;
431
+ unsigned long n = -1;
432
+ bool all = false;
433
+
434
+ switch(argc) {
435
+ case 2:
436
+ out = argv[1];
437
+ /* pass through */
438
+ case 1:
439
+ n = FIX2ULONG(argv[0]);
440
+ break;
441
+ case 0:
442
+ all = true;
443
+ break;
444
+ default:
445
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc);
446
+ }
447
+
448
+ BUFFER(self, b);
449
+
450
+ if(out != Qnil) {
451
+ CHECK_STRING_TYPE(out);
452
+ }
453
+
454
+ if(all) {
455
+ return read_all(b, out);
456
+ }
457
+
458
+ if(n == 0) {
459
+ /* do nothing */
460
+ MAKE_EMPTY_STRING(out);
461
+ return out;
462
+ }
463
+
464
+ #ifndef DISABLE_BUFFER_READ_TO_S_OPTIMIZE
465
+ if(!msgpack_buffer_has_io(b) && out == Qnil &&
466
+ msgpack_buffer_all_readable_size(b) <= n) {
467
+ /* same as to_s && clear; optimize */
468
+ VALUE str = msgpack_buffer_all_as_string(b);
469
+ msgpack_buffer_clear(b);
470
+
471
+ if(RSTRING_LEN(str) == 0) {
472
+ return Qnil;
473
+ } else {
474
+ return str;
475
+ }
476
+ }
477
+ #endif
478
+
479
+ MAKE_EMPTY_STRING(out);
480
+ read_until_eof(b, out, n);
481
+
482
+ if(RSTRING_LEN(out) == 0) {
483
+ return Qnil;
484
+ } else {
485
+ return out;
486
+ }
487
+ }
488
+
489
+ static VALUE Buffer_to_str(VALUE self)
490
+ {
491
+ BUFFER(self, b);
492
+ return msgpack_buffer_all_as_string(b);
493
+ }
494
+
495
+ static VALUE Buffer_to_a(VALUE self)
496
+ {
497
+ BUFFER(self, b);
498
+ return msgpack_buffer_all_as_string_array(b);
499
+ }
500
+
501
+ static VALUE Buffer_flush(VALUE self)
502
+ {
503
+ BUFFER(self, b);
504
+ msgpack_buffer_flush(b);
505
+ return self;
506
+ }
507
+
508
+ static VALUE Buffer_io(VALUE self)
509
+ {
510
+ BUFFER(self, b);
511
+ return b->io;
512
+ }
513
+
514
+ static VALUE Buffer_close(VALUE self)
515
+ {
516
+ BUFFER(self, b);
517
+ if(b->io != Qnil) {
518
+ return rb_funcall(b->io, s_close, 0);
519
+ }
520
+ return Qnil;
521
+ }
522
+
523
+ static VALUE Buffer_write_to(VALUE self, VALUE io)
524
+ {
525
+ BUFFER(self, b);
526
+ size_t sz = msgpack_buffer_flush_to_io(b, io, s_write, true);
527
+ return ULONG2NUM(sz);
528
+ }
529
+
530
+ void MessagePack_Buffer_module_init(VALUE mMessagePack)
531
+ {
532
+ s_read = rb_intern("read");
533
+ s_readpartial = rb_intern("readpartial");
534
+ s_write = rb_intern("write");
535
+ s_append = rb_intern("<<");
536
+ s_close = rb_intern("close");
537
+
538
+ msgpack_buffer_static_init();
539
+
540
+ cMessagePack_Buffer = rb_define_class_under(mMessagePack, "Buffer", rb_cObject);
541
+
542
+ rb_define_alloc_func(cMessagePack_Buffer, Buffer_alloc);
543
+
544
+ rb_define_method(cMessagePack_Buffer, "initialize", Buffer_initialize, -1);
545
+ rb_define_method(cMessagePack_Buffer, "clear", Buffer_clear, 0);
546
+ rb_define_method(cMessagePack_Buffer, "size", Buffer_size, 0);
547
+ rb_define_method(cMessagePack_Buffer, "empty?", Buffer_empty_p, 0);
548
+ rb_define_method(cMessagePack_Buffer, "write", Buffer_write, 1);
549
+ rb_define_method(cMessagePack_Buffer, "<<", Buffer_append, 1);
550
+ rb_define_method(cMessagePack_Buffer, "skip", Buffer_skip, 1);
551
+ rb_define_method(cMessagePack_Buffer, "skip_all", Buffer_skip_all, 1);
552
+ rb_define_method(cMessagePack_Buffer, "read", Buffer_read, -1);
553
+ rb_define_method(cMessagePack_Buffer, "read_all", Buffer_read_all, -1);
554
+ rb_define_method(cMessagePack_Buffer, "io", Buffer_io, 0);
555
+ rb_define_method(cMessagePack_Buffer, "flush", Buffer_flush, 0);
556
+ rb_define_method(cMessagePack_Buffer, "close", Buffer_close, 0);
557
+ rb_define_method(cMessagePack_Buffer, "write_to", Buffer_write_to, 1);
558
+ rb_define_method(cMessagePack_Buffer, "to_str", Buffer_to_str, 0);
559
+ rb_define_alias(cMessagePack_Buffer, "to_s", "to_str");
560
+ rb_define_method(cMessagePack_Buffer, "to_a", Buffer_to_a, 0);
561
+ }
@@ -0,0 +1,41 @@
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_BUFFER_CLASS_H__
28
+ #define MSGPACK_RUBY_BUFFER_CLASS_H__
29
+
30
+ #include "buffer.h"
31
+
32
+ extern VALUE cMessagePack_Buffer;
33
+
34
+ void MessagePack_Buffer_module_init(VALUE mMessagePack);
35
+
36
+ VALUE MessagePack_Buffer_wrap(msgpack_buffer_t* b, VALUE owner);
37
+
38
+ void MessagePack_Buffer_initialize(msgpack_buffer_t* b, VALUE io, VALUE options);
39
+
40
+ #endif
41
+
data/ext/cbor/cbor.h ADDED
@@ -0,0 +1,69 @@
1
+ #ifndef CBOR_RUBY_BUFFER_H__
2
+ #define CBOR_RUBY_BUFFER_H__
3
+
4
+ /* The 8 major types */
5
+ #define MT_UNSIGNED 0
6
+ #define MT_NEGATIVE 1
7
+ #define MT_BYTES 2
8
+ #define MT_TEXT 3
9
+ #define MT_ARRAY 4
10
+ #define MT_MAP 5
11
+ #define MT_TAG 6
12
+ #define MT_PRIM 7
13
+
14
+ /* The initial bytes resulting from those */
15
+ #define IB_UNSIGNED (MT_UNSIGNED << 5)
16
+ #define IB_NEGATIVE (MT_NEGATIVE << 5)
17
+ #define IB_BYTES (MT_BYTES << 5)
18
+ #define IB_TEXT (MT_TEXT << 5)
19
+ #define IB_ARRAY (MT_ARRAY << 5)
20
+ #define IB_MAP (MT_MAP << 5)
21
+ #define IB_TAG (MT_TAG << 5)
22
+ #define IB_PRIM (MT_PRIM << 5)
23
+
24
+ #define IB_NEGFLAG (IB_NEGATIVE - IB_UNSIGNED)
25
+ #define IB_NEGFLAG_AS_BIT(ib) ((ib) >> 5)
26
+ #define IB_TEXTFLAG (IB_TEXT - IB_BYTES)
27
+
28
+ #define IB_AI(ib) ((ib) & 0x1F)
29
+ #define IB_MT(ib) ((ib) >> 5)
30
+
31
+ /* Tag numbers handled by this implementation */
32
+ #define TAG_TIME_EPOCH 1
33
+ #define TAG_BIGNUM 2
34
+ #define TAG_BIGNUM_NEG 3
35
+ #define TAG_URI 32
36
+ #define TAG_RE 35
37
+
38
+ /* Initial bytes of those tag numbers */
39
+ #define IB_TIME_EPOCH (IB_TAG + TAG_TIME_EPOCH)
40
+ #define IB_BIGNUM (IB_TAG + TAG_BIGNUM)
41
+ #define IB_BIGNUM_NEG (IB_TAG + TAG_BIGNUM_NEG)
42
+ /* TAG_URI and TAG_RE are non-immediate tags */
43
+
44
+ /* Simple values handled by this implementation */
45
+ #define VAL_NIL 22
46
+ #define VAL_FALSE 20
47
+ #define VAL_TRUE 21
48
+
49
+ /* Initial bytes of those simple values */
50
+ #define IB_NIL (IB_PRIM + VAL_NIL)
51
+ #define IB_FALSE (IB_PRIM + VAL_FALSE)
52
+ #define IB_TRUE (IB_PRIM + VAL_TRUE)
53
+
54
+ /* AI values with more data in head */
55
+ #define AI_1 24
56
+ #define AI_2 25
57
+ #define AI_4 26
58
+ #define AI_8 27
59
+ #define AI_INDEF 31
60
+ #define IB_BREAK (IB_PRIM + AI_INDEF)
61
+ /* For */
62
+ #define IB_UNUSED (IB_TAG + AI_INDEF)
63
+
64
+ /* Floating point initial bytes */
65
+ #define IB_FLOAT2 (IB_PRIM + AI_2)
66
+ #define IB_FLOAT4 (IB_PRIM + AI_4)
67
+ #define IB_FLOAT8 (IB_PRIM + AI_8)
68
+
69
+ #endif