msgpack 0.6.0pre1-x64-mingw32

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 (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +26 -0
  4. data/ChangeLog +117 -0
  5. data/Dockerfile +30 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +177 -0
  8. data/README.rdoc +129 -0
  9. data/Rakefile +114 -0
  10. data/bench/pack.rb +23 -0
  11. data/bench/pack_log.rb +33 -0
  12. data/bench/pack_log_long.rb +65 -0
  13. data/bench/run.sh +14 -0
  14. data/bench/run_long.sh +35 -0
  15. data/bench/unpack.rb +21 -0
  16. data/bench/unpack_log.rb +34 -0
  17. data/bench/unpack_log_long.rb +67 -0
  18. data/cross-build.sh +9 -0
  19. data/doclib/msgpack/buffer.rb +193 -0
  20. data/doclib/msgpack/core_ext.rb +101 -0
  21. data/doclib/msgpack/error.rb +14 -0
  22. data/doclib/msgpack/packer.rb +134 -0
  23. data/doclib/msgpack/unpacker.rb +146 -0
  24. data/doclib/msgpack.rb +77 -0
  25. data/ext/java/org/msgpack/jruby/Buffer.java +221 -0
  26. data/ext/java/org/msgpack/jruby/Decoder.java +201 -0
  27. data/ext/java/org/msgpack/jruby/Encoder.java +308 -0
  28. data/ext/java/org/msgpack/jruby/ExtensionValue.java +136 -0
  29. data/ext/java/org/msgpack/jruby/MessagePackLibrary.java +107 -0
  30. data/ext/java/org/msgpack/jruby/Packer.java +78 -0
  31. data/ext/java/org/msgpack/jruby/Types.java +37 -0
  32. data/ext/java/org/msgpack/jruby/Unpacker.java +170 -0
  33. data/ext/msgpack/buffer.c +695 -0
  34. data/ext/msgpack/buffer.h +447 -0
  35. data/ext/msgpack/buffer_class.c +507 -0
  36. data/ext/msgpack/buffer_class.h +32 -0
  37. data/ext/msgpack/compat.h +113 -0
  38. data/ext/msgpack/core_ext.c +129 -0
  39. data/ext/msgpack/core_ext.h +26 -0
  40. data/ext/msgpack/extconf.rb +28 -0
  41. data/ext/msgpack/packer.c +168 -0
  42. data/ext/msgpack/packer.h +441 -0
  43. data/ext/msgpack/packer_class.c +302 -0
  44. data/ext/msgpack/packer_class.h +30 -0
  45. data/ext/msgpack/rbinit.c +33 -0
  46. data/ext/msgpack/rmem.c +94 -0
  47. data/ext/msgpack/rmem.h +109 -0
  48. data/ext/msgpack/sysdep.h +115 -0
  49. data/ext/msgpack/sysdep_endian.h +50 -0
  50. data/ext/msgpack/sysdep_types.h +46 -0
  51. data/ext/msgpack/unpacker.c +771 -0
  52. data/ext/msgpack/unpacker.h +122 -0
  53. data/ext/msgpack/unpacker_class.c +405 -0
  54. data/ext/msgpack/unpacker_class.h +32 -0
  55. data/lib/msgpack/msgpack.so +0 -0
  56. data/lib/msgpack/version.rb +3 -0
  57. data/lib/msgpack.rb +13 -0
  58. data/msgpack.gemspec +31 -0
  59. data/msgpack.org.md +46 -0
  60. data/spec/cases.json +1 -0
  61. data/spec/cases.msg +0 -0
  62. data/spec/cases_compact.msg +0 -0
  63. data/spec/cases_spec.rb +39 -0
  64. data/spec/cruby/buffer_io_spec.rb +256 -0
  65. data/spec/cruby/buffer_packer.rb +29 -0
  66. data/spec/cruby/buffer_spec.rb +572 -0
  67. data/spec/cruby/buffer_unpacker.rb +19 -0
  68. data/spec/cruby/packer_spec.rb +120 -0
  69. data/spec/cruby/unpacker_spec.rb +305 -0
  70. data/spec/format_spec.rb +282 -0
  71. data/spec/jruby/benchmarks/shootout_bm.rb +73 -0
  72. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +25 -0
  73. data/spec/jruby/msgpack/unpacker_spec.rb +290 -0
  74. data/spec/jruby/msgpack_spec.rb +142 -0
  75. data/spec/pack_spec.rb +67 -0
  76. data/spec/random_compat.rb +24 -0
  77. data/spec/spec_helper.rb +27 -0
  78. data/spec/unpack_spec.rb +60 -0
  79. metadata +209 -0
@@ -0,0 +1,441 @@
1
+ /*
2
+ * MessagePack for Ruby
3
+ *
4
+ * Copyright (C) 2008-2013 Sadayuki Furuhashi
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ #ifndef MSGPACK_RUBY_PACKER_H__
19
+ #define MSGPACK_RUBY_PACKER_H__
20
+
21
+ #include "buffer.h"
22
+
23
+ #ifndef MSGPACK_PACKER_IO_FLUSH_THRESHOLD_TO_WRITE_STRING_BODY
24
+ #define MSGPACK_PACKER_IO_FLUSH_THRESHOLD_TO_WRITE_STRING_BODY (1024)
25
+ #endif
26
+
27
+ struct msgpack_packer_t;
28
+ typedef struct msgpack_packer_t msgpack_packer_t;
29
+
30
+ struct msgpack_packer_t {
31
+ msgpack_buffer_t buffer;
32
+
33
+ VALUE io;
34
+ ID io_write_all_method;
35
+
36
+ ID to_msgpack_method;
37
+ VALUE to_msgpack_arg;
38
+
39
+ VALUE buffer_ref;
40
+ };
41
+
42
+ #define PACKER_BUFFER_(pk) (&(pk)->buffer)
43
+
44
+ void msgpack_packer_static_init();
45
+
46
+ void msgpack_packer_static_destroy();
47
+
48
+ void msgpack_packer_init(msgpack_packer_t* pk);
49
+
50
+ void msgpack_packer_destroy(msgpack_packer_t* pk);
51
+
52
+ void msgpack_packer_mark(msgpack_packer_t* pk);
53
+
54
+ static inline void msgpack_packer_set_to_msgpack_method(msgpack_packer_t* pk,
55
+ ID to_msgpack_method, VALUE to_msgpack_arg)
56
+ {
57
+ pk->to_msgpack_method = to_msgpack_method;
58
+ pk->to_msgpack_arg = to_msgpack_arg;
59
+ }
60
+
61
+ static inline void msgpack_packer_set_io(msgpack_packer_t* pk, VALUE io, ID io_write_all_method)
62
+ {
63
+ pk->io = io;
64
+ pk->io_write_all_method = io_write_all_method;
65
+ }
66
+
67
+ void msgpack_packer_reset(msgpack_packer_t* pk);
68
+
69
+ static inline void msgpack_packer_write_nil(msgpack_packer_t* pk)
70
+ {
71
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
72
+ msgpack_buffer_write_1(PACKER_BUFFER_(pk), 0xc0);
73
+ }
74
+
75
+ static inline void msgpack_packer_write_true(msgpack_packer_t* pk)
76
+ {
77
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
78
+ msgpack_buffer_write_1(PACKER_BUFFER_(pk), 0xc3);
79
+ }
80
+
81
+ static inline void msgpack_packer_write_false(msgpack_packer_t* pk)
82
+ {
83
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
84
+ msgpack_buffer_write_1(PACKER_BUFFER_(pk), 0xc2);
85
+ }
86
+
87
+ static inline void _msgpack_packer_write_fixint(msgpack_packer_t* pk, int8_t v)
88
+ {
89
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
90
+ msgpack_buffer_write_1(PACKER_BUFFER_(pk), v);
91
+ }
92
+
93
+ static inline void _msgpack_packer_write_uint8(msgpack_packer_t* pk, uint8_t v)
94
+ {
95
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2);
96
+ msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xcc, v);
97
+ }
98
+
99
+ static inline void _msgpack_packer_write_uint16(msgpack_packer_t* pk, uint16_t v)
100
+ {
101
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
102
+ uint16_t be = _msgpack_be16(v);
103
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xcd, (const void*)&be, 2);
104
+ }
105
+
106
+ static inline void _msgpack_packer_write_uint32(msgpack_packer_t* pk, uint32_t v)
107
+ {
108
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
109
+ uint32_t be = _msgpack_be32(v);
110
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xce, (const void*)&be, 4);
111
+ }
112
+
113
+ static inline void _msgpack_packer_write_uint64(msgpack_packer_t* pk, uint64_t v)
114
+ {
115
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9);
116
+ uint64_t be = _msgpack_be64(v);
117
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xcf, (const void*)&be, 8);
118
+ }
119
+
120
+ static inline void _msgpack_packer_write_int8(msgpack_packer_t* pk, int8_t v)
121
+ {
122
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2);
123
+ msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd0, v);
124
+ }
125
+
126
+ static inline void _msgpack_packer_write_int16(msgpack_packer_t* pk, int16_t v)
127
+ {
128
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
129
+ uint16_t be = _msgpack_be16(v);
130
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd1, (const void*)&be, 2);
131
+ }
132
+
133
+ static inline void _msgpack_packer_write_int32(msgpack_packer_t* pk, int32_t v)
134
+ {
135
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
136
+ uint32_t be = _msgpack_be32(v);
137
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd2, (const void*)&be, 4);
138
+ }
139
+
140
+ static inline void _msgpack_packer_write_int64(msgpack_packer_t* pk, int64_t v)
141
+ {
142
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9);
143
+ uint64_t be = _msgpack_be64(v);
144
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd3, (const void*)&be, 8);
145
+ }
146
+
147
+ static inline void _msgpack_packer_write_long32(msgpack_packer_t* pk, long v)
148
+ {
149
+ if(v < -0x20L) {
150
+ if(v < -0x8000L) {
151
+ _msgpack_packer_write_int32(pk, (int32_t) v);
152
+ } else if(v < -0x80L) {
153
+ _msgpack_packer_write_int16(pk, (int16_t) v);
154
+ } else {
155
+ _msgpack_packer_write_int8(pk, (int8_t) v);
156
+ }
157
+ } else if(v <= 0x7fL) {
158
+ _msgpack_packer_write_fixint(pk, (int8_t) v);
159
+ } else {
160
+ if(v <= 0xffL) {
161
+ _msgpack_packer_write_uint8(pk, (uint8_t) v);
162
+ } else if(v <= 0xffffL) {
163
+ _msgpack_packer_write_uint16(pk, (uint16_t) v);
164
+ } else {
165
+ _msgpack_packer_write_uint32(pk, (uint32_t) v);
166
+ }
167
+ }
168
+ }
169
+
170
+ static inline void _msgpack_packer_write_long_long64(msgpack_packer_t* pk, long long v)
171
+ {
172
+ if(v < -0x20LL) {
173
+ if(v < -0x8000LL) {
174
+ if(v < -0x80000000LL) {
175
+ _msgpack_packer_write_int64(pk, (int64_t) v);
176
+ } else {
177
+ _msgpack_packer_write_int32(pk, (int32_t) v);
178
+ }
179
+ } else {
180
+ if(v < -0x80LL) {
181
+ _msgpack_packer_write_int16(pk, (int16_t) v);
182
+ } else {
183
+ _msgpack_packer_write_int8(pk, (int8_t) v);
184
+ }
185
+ }
186
+ } else if(v <= 0x7fLL) {
187
+ _msgpack_packer_write_fixint(pk, (int8_t) v);
188
+ } else {
189
+ if(v <= 0xffffLL) {
190
+ if(v <= 0xffLL) {
191
+ _msgpack_packer_write_uint8(pk, (uint8_t) v);
192
+ } else {
193
+ _msgpack_packer_write_uint16(pk, (uint16_t) v);
194
+ }
195
+ } else {
196
+ if(v <= 0xffffffffLL) {
197
+ _msgpack_packer_write_uint32(pk, (uint32_t) v);
198
+ } else {
199
+ _msgpack_packer_write_uint64(pk, (uint64_t) v);
200
+ }
201
+ }
202
+ }
203
+ }
204
+
205
+ static inline void msgpack_packer_write_long(msgpack_packer_t* pk, long v)
206
+ {
207
+ #if defined(SIZEOF_LONG)
208
+ # if SIZEOF_LONG <= 4
209
+ _msgpack_packer_write_long32(pk, v);
210
+ # else
211
+ _msgpack_packer_write_long_long64(pk, v);
212
+ # endif
213
+
214
+ #elif defined(LONG_MAX)
215
+ # if LONG_MAX <= 0x7fffffffL
216
+ _msgpack_packer_write_long32(pk, v);
217
+ # else
218
+ _msgpack_packer_write_long_long64(pk, v);
219
+ # endif
220
+
221
+ #else
222
+ if(sizeof(long) <= 4) {
223
+ _msgpack_packer_write_long32(pk, v);
224
+ } else {
225
+ _msgpack_packer_write_long_long64(pk, v);
226
+ }
227
+ #endif
228
+ }
229
+
230
+ static inline void msgpack_packer_write_long_long(msgpack_packer_t* pk, long long v)
231
+ {
232
+ /* assuming sizeof(long long) == 8 */
233
+ _msgpack_packer_write_long_long64(pk, v);
234
+ }
235
+
236
+ static inline void msgpack_packer_write_u64(msgpack_packer_t* pk, uint64_t v)
237
+ {
238
+ if(v <= 0xffULL) {
239
+ if(v <= 0x7fULL) {
240
+ _msgpack_packer_write_fixint(pk, (int8_t) v);
241
+ } else {
242
+ _msgpack_packer_write_uint8(pk, (uint8_t) v);
243
+ }
244
+ } else {
245
+ if(v <= 0xffffULL) {
246
+ _msgpack_packer_write_uint16(pk, (uint16_t) v);
247
+ } else if(v <= 0xffffffffULL) {
248
+ _msgpack_packer_write_uint32(pk, (uint32_t) v);
249
+ } else {
250
+ _msgpack_packer_write_uint64(pk, (uint64_t) v);
251
+ }
252
+ }
253
+ }
254
+
255
+ static inline void msgpack_packer_write_double(msgpack_packer_t* pk, double v)
256
+ {
257
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9);
258
+ union {
259
+ double d;
260
+ uint64_t u64;
261
+ char mem[8];
262
+ } castbuf = { v };
263
+ castbuf.u64 = _msgpack_be_double(castbuf.u64);
264
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xcb, castbuf.mem, 8);
265
+ }
266
+
267
+ static inline void msgpack_packer_write_raw_header(msgpack_packer_t* pk, unsigned int n)
268
+ {
269
+ if(n < 32) {
270
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
271
+ unsigned char h = 0xa0 | (uint8_t) n;
272
+ msgpack_buffer_write_1(PACKER_BUFFER_(pk), h);
273
+ } else if(n < 256) {
274
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2);
275
+ unsigned char be = (uint8_t) n;
276
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd9, (const void*)&be, 1);
277
+ } else if(n < 65536) {
278
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
279
+ uint16_t be = _msgpack_be16(n);
280
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xda, (const void*)&be, 2);
281
+ } else {
282
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
283
+ uint32_t be = _msgpack_be32(n);
284
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdb, (const void*)&be, 4);
285
+ }
286
+ }
287
+
288
+ static inline void msgpack_packer_write_bin_header(msgpack_packer_t* pk, unsigned int n)
289
+ {
290
+ if(n < 256) {
291
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
292
+ unsigned char be = (uint8_t) n;
293
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc4, (const void*)&be, 1);
294
+ } else if(n < 65536) {
295
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
296
+ uint16_t be = _msgpack_be16(n);
297
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc5, (const void*)&be, 2);
298
+ } else {
299
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
300
+ uint32_t be = _msgpack_be32(n);
301
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc6, (const void*)&be, 4);
302
+ }
303
+ }
304
+
305
+ static inline void msgpack_packer_write_array_header(msgpack_packer_t* pk, unsigned int n)
306
+ {
307
+ if(n < 16) {
308
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
309
+ unsigned char h = 0x90 | (uint8_t) n;
310
+ msgpack_buffer_write_1(PACKER_BUFFER_(pk), h);
311
+ } else if(n < 65536) {
312
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
313
+ uint16_t be = _msgpack_be16(n);
314
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdc, (const void*)&be, 2);
315
+ } else {
316
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
317
+ uint32_t be = _msgpack_be32(n);
318
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdd, (const void*)&be, 4);
319
+ }
320
+ }
321
+
322
+ static inline void msgpack_packer_write_map_header(msgpack_packer_t* pk, unsigned int n)
323
+ {
324
+ if(n < 16) {
325
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
326
+ unsigned char h = 0x80 | (uint8_t) n;
327
+ msgpack_buffer_write_1(PACKER_BUFFER_(pk), h);
328
+ } else if(n < 65536) {
329
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
330
+ uint16_t be = _msgpack_be16(n);
331
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xde, (const void*)&be, 2);
332
+ } else {
333
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
334
+ uint32_t be = _msgpack_be32(n);
335
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdf, (const void*)&be, 4);
336
+ }
337
+ }
338
+
339
+ #ifdef COMPAT_HAVE_ENCODING
340
+ static inline bool msgpack_packer_is_binary(VALUE v, int encindex)
341
+ {
342
+ return encindex == msgpack_rb_encindex_ascii8bit;
343
+ }
344
+
345
+ static inline bool msgpack_packer_is_utf8_compat_string(VALUE v, int encindex)
346
+ {
347
+ return encindex == msgpack_rb_encindex_utf8
348
+ || encindex == msgpack_rb_encindex_usascii
349
+ #ifdef ENC_CODERANGE_ASCIIONLY
350
+ /* Because ENC_CODERANGE_ASCIIONLY does not scan string, it may return ENC_CODERANGE_UNKNOWN unlike */
351
+ /* rb_enc_str_asciionly_p. It is always faster than rb_str_encode if it is available. */
352
+ /* Very old Rubinius (< v1.3.1) doesn't have ENC_CODERANGE_ASCIIONLY. */
353
+ || (rb_enc_asciicompat(rb_enc_from_index(encindex)) && ENC_CODERANGE_ASCIIONLY(v))
354
+ #endif
355
+ ;
356
+ }
357
+ #endif
358
+
359
+ static inline void msgpack_packer_write_string_value(msgpack_packer_t* pk, VALUE v)
360
+ {
361
+ /* TODO encoding conversion? */
362
+ /* actual return type of RSTRING_LEN is long */
363
+ unsigned long len = RSTRING_LEN(v);
364
+ if(len > 0xffffffffUL) {
365
+ // TODO rb_eArgError?
366
+ rb_raise(rb_eArgError, "size of string is too long to pack: %lu bytes should be <= %lu", len, 0xffffffffUL);
367
+ }
368
+
369
+ #ifdef COMPAT_HAVE_ENCODING
370
+ int encindex = ENCODING_GET(v);
371
+ if(msgpack_packer_is_binary(v, encindex)) {
372
+ /* write ASCII-8BIT string using Binary type */
373
+ msgpack_packer_write_bin_header(pk, (unsigned int)len);
374
+ msgpack_buffer_append_string(PACKER_BUFFER_(pk), v);
375
+ } else {
376
+ /* write UTF-8, US-ASCII, or 7bit-safe ascii-compatible string using String type directly */
377
+ if(!msgpack_packer_is_utf8_compat_string(v, encindex)) {
378
+ /* transcode other strings to UTF-8 and write using String type */
379
+ VALUE enc = rb_enc_from_encoding(rb_utf8_encoding()); /* rb_enc_from_encoding_index is not extern */
380
+ v = rb_str_encode(v, enc, 0, Qnil);
381
+ len = RSTRING_LEN(v);
382
+ }
383
+ msgpack_packer_write_raw_header(pk, (unsigned int)len);
384
+ msgpack_buffer_append_string(PACKER_BUFFER_(pk), v);
385
+ }
386
+ #else
387
+ msgpack_packer_write_raw_header(pk, (unsigned int)len);
388
+ msgpack_buffer_append_string(PACKER_BUFFER_(pk), v);
389
+ #endif
390
+ }
391
+
392
+ static inline void msgpack_packer_write_symbol_value(msgpack_packer_t* pk, VALUE v)
393
+ {
394
+ #ifdef HAVE_RB_SYM2STR
395
+ /* rb_sym2str is added since MRI 2.2.0 */
396
+ msgpack_packer_write_string_value(pk, rb_sym2str(v));
397
+ #else
398
+ const char* name = rb_id2name(SYM2ID(v));
399
+ unsigned long len = strlen(name);
400
+ /* actual return type of strlen is size_t */
401
+ if(len > 0xffffffffUL) {
402
+ // TODO rb_eArgError?
403
+ rb_raise(rb_eArgError, "size of symbol is too long to pack: %lu bytes should be <= %lu", len, 0xffffffffUL);
404
+ }
405
+ msgpack_packer_write_raw_header(pk, (unsigned int)len);
406
+ msgpack_buffer_append(PACKER_BUFFER_(pk), name, len);
407
+ #endif
408
+ }
409
+
410
+ static inline void msgpack_packer_write_fixnum_value(msgpack_packer_t* pk, VALUE v)
411
+ {
412
+ #ifdef JRUBY
413
+ msgpack_packer_write_long(pk, FIXNUM_P(v) ? FIX2LONG(v) : rb_num2ll(v));
414
+ #else
415
+ msgpack_packer_write_long(pk, FIX2LONG(v));
416
+ #endif
417
+ }
418
+
419
+ static inline void msgpack_packer_write_bignum_value(msgpack_packer_t* pk, VALUE v)
420
+ {
421
+ if(RBIGNUM_POSITIVE_P(v)) {
422
+ msgpack_packer_write_u64(pk, rb_big2ull(v));
423
+ } else {
424
+ msgpack_packer_write_long_long(pk, rb_big2ll(v));
425
+ }
426
+ }
427
+
428
+ static inline void msgpack_packer_write_float_value(msgpack_packer_t* pk, VALUE v)
429
+ {
430
+ msgpack_packer_write_double(pk, rb_num2dbl(v));
431
+ }
432
+
433
+ void msgpack_packer_write_array_value(msgpack_packer_t* pk, VALUE v);
434
+
435
+ void msgpack_packer_write_hash_value(msgpack_packer_t* pk, VALUE v);
436
+
437
+ void msgpack_packer_write_value(msgpack_packer_t* pk, VALUE v);
438
+
439
+
440
+ #endif
441
+