msgpack 0.3.2-mswin32 → 0.3.3-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ FURUHASHI Sadayuki <frsyuki _at_ users.sourceforge.jp>
File without changes
data/README ADDED
@@ -0,0 +1,29 @@
1
+
2
+ = MessagePack
3
+
4
+
5
+ == Description
6
+
7
+
8
+ == Installation
9
+
10
+ === Archive Installation
11
+
12
+ rake install
13
+
14
+ === Gem Installation
15
+
16
+ gem install msgpack
17
+
18
+
19
+ == Features/Problems
20
+
21
+
22
+ == Synopsis
23
+
24
+
25
+ == Copyright
26
+
27
+ Author:: frsyuki <frsyuki@users.sourceforge.jp>
28
+ Copyright:: Copyright (c) 2008-2009 frsyuki
29
+ License:: Apache License, Version 2.0
@@ -18,10 +18,16 @@
18
18
  #include "ruby.h"
19
19
  #include "msgpack/unpack_define.h"
20
20
 
21
+ static ID s_sysread;
21
22
 
22
23
  typedef struct {
23
24
  int finished;
24
25
  VALUE source;
26
+ size_t offset;
27
+ size_t parsed;
28
+ VALUE buffer;
29
+ VALUE stream;
30
+ VALUE streambuf;
25
31
  } unpack_user;
26
32
 
27
33
 
@@ -144,6 +150,9 @@ static void MessagePack_Unpacker_free(void* data)
144
150
  static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
145
151
  {
146
152
  unsigned int i;
153
+ rb_gc_mark(mp->user.buffer);
154
+ rb_gc_mark(mp->user.stream);
155
+ rb_gc_mark(mp->user.streambuf);
147
156
  for(i=0; i < mp->top; ++i) {
148
157
  rb_gc_mark(mp->stack[i].obj);
149
158
  rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */
@@ -164,14 +173,32 @@ static VALUE MessagePack_Unpacker_reset(VALUE self)
164
173
  UNPACKER(self, mp);
165
174
  template_init(mp);
166
175
  init_stack(mp);
167
- unpack_user u = {0, Qnil};
168
- mp->user = u;
176
+ mp->user.finished = 0;
169
177
  return self;
170
178
  }
171
179
 
172
- static VALUE MessagePack_Unpacker_initialize(VALUE self)
180
+ static VALUE MessagePack_Unpacker_initialize(int argc, VALUE *argv, VALUE self)
173
181
  {
174
- return MessagePack_Unpacker_reset(self);
182
+ VALUE stream;
183
+ switch(argc) {
184
+ case 0:
185
+ stream = Qnil;
186
+ break;
187
+ case 1:
188
+ stream = argv[0];
189
+ break;
190
+ default:
191
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
192
+ }
193
+
194
+ MessagePack_Unpacker_reset(self);
195
+ UNPACKER(self, mp);
196
+ mp->user.offset = 0;
197
+ mp->user.parsed = 0;
198
+ mp->user.buffer = rb_str_new("",0);
199
+ mp->user.stream = stream;
200
+ mp->user.streambuf = rb_str_new("",0);
201
+ return self;
175
202
  }
176
203
 
177
204
 
@@ -249,6 +276,87 @@ static VALUE MessagePack_Unpacker_data(VALUE self)
249
276
  }
250
277
 
251
278
 
279
+ static VALUE MessagePack_Unpacker_feed(VALUE self, VALUE data)
280
+ {
281
+ UNPACKER(self, mp);
282
+ StringValue(data);
283
+ rb_str_cat(mp->user.buffer, RSTRING_PTR(data), RSTRING_LEN(data));
284
+ return Qnil;
285
+ }
286
+
287
+ static VALUE MessagePack_Unpacker_stream_get(VALUE self)
288
+ {
289
+ UNPACKER(self, mp);
290
+ return mp->user.stream;
291
+ }
292
+
293
+ static VALUE MessagePack_Unpacker_stream_set(VALUE self, VALUE val)
294
+ {
295
+ UNPACKER(self, mp);
296
+ return mp->user.stream = val;
297
+ }
298
+
299
+ static VALUE MessagePack_Unpacker_fill(VALUE self)
300
+ {
301
+ UNPACKER(self, mp);
302
+
303
+ if(mp->user.stream == Qnil) {
304
+ return Qnil;
305
+ }
306
+
307
+ size_t len;
308
+ if(RSTRING_LEN(mp->user.buffer) == 0) {
309
+ rb_funcall(mp->user.stream, s_sysread, 2, LONG2FIX(64*1024), mp->user.buffer);
310
+ len = RSTRING_LEN(mp->user.buffer);
311
+ } else {
312
+ rb_funcall(mp->user.stream, s_sysread, 2, LONG2FIX(64*1024), mp->user.streambuf);
313
+ len = RSTRING_LEN(mp->user.streambuf);
314
+ rb_str_cat(mp->user.buffer, RSTRING_PTR(mp->user.streambuf), RSTRING_LEN(mp->user.streambuf));
315
+ }
316
+
317
+ return LONG2FIX(len);
318
+ }
319
+
320
+ static VALUE MessagePack_Unpacker_each(VALUE self)
321
+ {
322
+ UNPACKER(self, mp);
323
+ int ret;
324
+
325
+ #ifdef RETURN_ENUMERATOR
326
+ RETURN_ENUMERATOR(self, 0, 0);
327
+ #endif
328
+
329
+ while(1) {
330
+ if(RSTRING_LEN(mp->user.buffer) <= mp->user.offset) {
331
+ do_fill:
332
+ {
333
+ VALUE len = MessagePack_Unpacker_fill(self);
334
+ if(len == Qnil || FIX2LONG(len) == 0) {
335
+ break;
336
+ }
337
+ }
338
+ }
339
+
340
+ mp->user.source = mp->user.buffer;
341
+ ret = template_execute(mp, RSTRING_PTR(mp->user.buffer), RSTRING_LEN(mp->user.buffer), &mp->user.offset);
342
+ mp->user.source = Qnil;
343
+
344
+ if(ret < 0) {
345
+ rb_raise(eUnpackError, "parse error.");
346
+ } else if(ret > 0) {
347
+ VALUE data = template_data(mp);
348
+ template_init(mp);
349
+ init_stack(mp);
350
+ rb_yield(data);
351
+ } else {
352
+ goto do_fill;
353
+ }
354
+ }
355
+
356
+ return Qnil;
357
+ }
358
+
359
+
252
360
  static VALUE MessagePack_unpack_impl(VALUE args)
253
361
  {
254
362
  msgpack_unpack_t* mp = (msgpack_unpack_t*)((VALUE*)args)[0];
@@ -292,7 +400,7 @@ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
292
400
  msgpack_unpack_t mp;
293
401
  template_init(&mp);
294
402
  init_stack(&mp);
295
- unpack_user u = {0, Qnil};
403
+ unpack_user u = {0, Qnil, 0, 0, Qnil, Qnil, Qnil};
296
404
  mp.user = u;
297
405
 
298
406
  rb_gc_disable();
@@ -313,17 +421,22 @@ static VALUE MessagePack_unpack(VALUE self, VALUE data)
313
421
 
314
422
  void Init_msgpack_unpack(VALUE mMessagePack)
315
423
  {
424
+ s_sysread = rb_intern("sysread");
316
425
  eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError);
317
426
  cUnpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject);
318
427
  rb_define_alloc_func(cUnpacker, MessagePack_Unpacker_alloc);
319
- rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, 0);
428
+ rb_define_method(cUnpacker, "initialize", MessagePack_Unpacker_initialize, -1);
320
429
  rb_define_method(cUnpacker, "execute", MessagePack_Unpacker_execute, 2);
321
430
  rb_define_method(cUnpacker, "execute_limit", MessagePack_Unpacker_execute_limit, 3);
322
431
  rb_define_method(cUnpacker, "finished?", MessagePack_Unpacker_finished_p, 0);
323
432
  rb_define_method(cUnpacker, "data", MessagePack_Unpacker_data, 0);
324
433
  rb_define_method(cUnpacker, "reset", MessagePack_Unpacker_reset, 0);
434
+ rb_define_method(cUnpacker, "feed", MessagePack_Unpacker_feed, 1);
435
+ rb_define_method(cUnpacker, "fill", MessagePack_Unpacker_fill, 0);
436
+ rb_define_method(cUnpacker, "each", MessagePack_Unpacker_each, 0);
437
+ rb_define_method(cUnpacker, "stream", MessagePack_Unpacker_stream_get, 0);
438
+ rb_define_method(cUnpacker, "stream=", MessagePack_Unpacker_stream_set, 1);
325
439
  rb_define_module_function(mMessagePack, "unpack", MessagePack_unpack, 1);
326
440
  rb_define_module_function(mMessagePack, "unpack_limit", MessagePack_unpack_limit, 2);
327
441
  }
328
442
 
329
-
@@ -0,0 +1,26 @@
1
+ /*
2
+ * MessagePack unpacking routine template
3
+ *
4
+ * Copyright (C) 2008-2010 FURUHASHI Sadayuki
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_PACK_DEFINE_H__
19
+ #define MSGPACK_PACK_DEFINE_H__
20
+
21
+ #include "msgpack/sysdep.h"
22
+ #include <limits.h>
23
+ #include <string.h>
24
+
25
+ #endif /* msgpack/pack_define.h */
26
+
@@ -0,0 +1,686 @@
1
+ /*
2
+ * MessagePack packing routine template
3
+ *
4
+ * Copyright (C) 2008-2010 FURUHASHI Sadayuki
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
+
19
+ #ifdef __LITTLE_ENDIAN__
20
+ #define TAKE8_8(d) ((uint8_t*)&d)[0]
21
+ #define TAKE8_16(d) ((uint8_t*)&d)[0]
22
+ #define TAKE8_32(d) ((uint8_t*)&d)[0]
23
+ #define TAKE8_64(d) ((uint8_t*)&d)[0]
24
+ #elif __BIG_ENDIAN__
25
+ #define TAKE8_8(d) ((uint8_t*)&d)[0]
26
+ #define TAKE8_16(d) ((uint8_t*)&d)[1]
27
+ #define TAKE8_32(d) ((uint8_t*)&d)[3]
28
+ #define TAKE8_64(d) ((uint8_t*)&d)[7]
29
+ #endif
30
+
31
+ #ifndef msgpack_pack_inline_func
32
+ #error msgpack_pack_inline_func template is not defined
33
+ #endif
34
+
35
+ #ifndef msgpack_pack_user
36
+ #error msgpack_pack_user type is not defined
37
+ #endif
38
+
39
+ #ifndef msgpack_pack_append_buffer
40
+ #error msgpack_pack_append_buffer callback is not defined
41
+ #endif
42
+
43
+
44
+ /*
45
+ * Integer
46
+ */
47
+
48
+ #define msgpack_pack_real_uint8(x, d) \
49
+ do { \
50
+ if(d < (1<<7)) { \
51
+ /* fixnum */ \
52
+ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
53
+ } else { \
54
+ /* unsigned 8 */ \
55
+ unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
56
+ msgpack_pack_append_buffer(x, buf, 2); \
57
+ } \
58
+ } while(0)
59
+
60
+ #define msgpack_pack_real_uint16(x, d) \
61
+ do { \
62
+ if(d < (1<<7)) { \
63
+ /* fixnum */ \
64
+ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
65
+ } else if(d < (1<<8)) { \
66
+ /* unsigned 8 */ \
67
+ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
68
+ msgpack_pack_append_buffer(x, buf, 2); \
69
+ } else { \
70
+ /* unsigned 16 */ \
71
+ unsigned char buf[3]; \
72
+ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
73
+ msgpack_pack_append_buffer(x, buf, 3); \
74
+ } \
75
+ } while(0)
76
+
77
+ #define msgpack_pack_real_uint32(x, d) \
78
+ do { \
79
+ if(d < (1<<8)) { \
80
+ if(d < (1<<7)) { \
81
+ /* fixnum */ \
82
+ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
83
+ } else { \
84
+ /* unsigned 8 */ \
85
+ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
86
+ msgpack_pack_append_buffer(x, buf, 2); \
87
+ } \
88
+ } else { \
89
+ if(d < (1<<16)) { \
90
+ /* unsigned 16 */ \
91
+ unsigned char buf[3]; \
92
+ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
93
+ msgpack_pack_append_buffer(x, buf, 3); \
94
+ } else { \
95
+ /* unsigned 32 */ \
96
+ unsigned char buf[5]; \
97
+ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
98
+ msgpack_pack_append_buffer(x, buf, 5); \
99
+ } \
100
+ } \
101
+ } while(0)
102
+
103
+ #define msgpack_pack_real_uint64(x, d) \
104
+ do { \
105
+ if(d < (1ULL<<8)) { \
106
+ if(d < (1<<7)) { \
107
+ /* fixnum */ \
108
+ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
109
+ } else { \
110
+ /* unsigned 8 */ \
111
+ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
112
+ msgpack_pack_append_buffer(x, buf, 2); \
113
+ } \
114
+ } else { \
115
+ if(d < (1ULL<<16)) { \
116
+ /* signed 16 */ \
117
+ unsigned char buf[3]; \
118
+ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
119
+ msgpack_pack_append_buffer(x, buf, 3); \
120
+ } else if(d < (1ULL<<32)) { \
121
+ /* signed 32 */ \
122
+ unsigned char buf[5]; \
123
+ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
124
+ msgpack_pack_append_buffer(x, buf, 5); \
125
+ } else { \
126
+ /* signed 64 */ \
127
+ unsigned char buf[9]; \
128
+ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
129
+ msgpack_pack_append_buffer(x, buf, 9); \
130
+ } \
131
+ } \
132
+ } while(0)
133
+
134
+ #define msgpack_pack_real_int8(x, d) \
135
+ do { \
136
+ if(d < -(1<<5)) { \
137
+ /* signed 8 */ \
138
+ unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
139
+ msgpack_pack_append_buffer(x, buf, 2); \
140
+ } else { \
141
+ /* fixnum */ \
142
+ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
143
+ } \
144
+ } while(0)
145
+
146
+ #define msgpack_pack_real_int16(x, d) \
147
+ do { \
148
+ if(d < -(1<<5)) { \
149
+ if(d < -(1<<7)) { \
150
+ /* signed 16 */ \
151
+ unsigned char buf[3]; \
152
+ buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
153
+ msgpack_pack_append_buffer(x, buf, 3); \
154
+ } else { \
155
+ /* signed 8 */ \
156
+ unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
157
+ msgpack_pack_append_buffer(x, buf, 2); \
158
+ } \
159
+ } else if(d < (1<<7)) { \
160
+ /* fixnum */ \
161
+ msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
162
+ } else { \
163
+ if(d < (1<<8)) { \
164
+ /* unsigned 8 */ \
165
+ unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
166
+ msgpack_pack_append_buffer(x, buf, 2); \
167
+ } else { \
168
+ /* unsigned 16 */ \
169
+ unsigned char buf[3]; \
170
+ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
171
+ msgpack_pack_append_buffer(x, buf, 3); \
172
+ } \
173
+ } \
174
+ } while(0)
175
+
176
+ #define msgpack_pack_real_int32(x, d) \
177
+ do { \
178
+ if(d < -(1<<5)) { \
179
+ if(d < -(1<<15)) { \
180
+ /* signed 32 */ \
181
+ unsigned char buf[5]; \
182
+ buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
183
+ msgpack_pack_append_buffer(x, buf, 5); \
184
+ } else if(d < -(1<<7)) { \
185
+ /* signed 16 */ \
186
+ unsigned char buf[3]; \
187
+ buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
188
+ msgpack_pack_append_buffer(x, buf, 3); \
189
+ } else { \
190
+ /* signed 8 */ \
191
+ unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
192
+ msgpack_pack_append_buffer(x, buf, 2); \
193
+ } \
194
+ } else if(d < (1<<7)) { \
195
+ /* fixnum */ \
196
+ msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
197
+ } else { \
198
+ if(d < (1<<8)) { \
199
+ /* unsigned 8 */ \
200
+ unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
201
+ msgpack_pack_append_buffer(x, buf, 2); \
202
+ } else if(d < (1<<16)) { \
203
+ /* unsigned 16 */ \
204
+ unsigned char buf[3]; \
205
+ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
206
+ msgpack_pack_append_buffer(x, buf, 3); \
207
+ } else { \
208
+ /* unsigned 32 */ \
209
+ unsigned char buf[5]; \
210
+ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
211
+ msgpack_pack_append_buffer(x, buf, 5); \
212
+ } \
213
+ } \
214
+ } while(0)
215
+
216
+ #define msgpack_pack_real_int64(x, d) \
217
+ do { \
218
+ if(d < -(1LL<<5)) { \
219
+ if(d < -(1LL<<15)) { \
220
+ if(d < -(1LL<<31)) { \
221
+ /* signed 64 */ \
222
+ unsigned char buf[9]; \
223
+ buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
224
+ msgpack_pack_append_buffer(x, buf, 9); \
225
+ } else { \
226
+ /* signed 32 */ \
227
+ unsigned char buf[5]; \
228
+ buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
229
+ msgpack_pack_append_buffer(x, buf, 5); \
230
+ } \
231
+ } else { \
232
+ if(d < -(1<<7)) { \
233
+ /* signed 16 */ \
234
+ unsigned char buf[3]; \
235
+ buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
236
+ msgpack_pack_append_buffer(x, buf, 3); \
237
+ } else { \
238
+ /* signed 8 */ \
239
+ unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
240
+ msgpack_pack_append_buffer(x, buf, 2); \
241
+ } \
242
+ } \
243
+ } else if(d < (1<<7)) { \
244
+ /* fixnum */ \
245
+ msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
246
+ } else { \
247
+ if(d < (1LL<<16)) { \
248
+ if(d < (1<<8)) { \
249
+ /* unsigned 8 */ \
250
+ unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
251
+ msgpack_pack_append_buffer(x, buf, 2); \
252
+ } else { \
253
+ /* unsigned 16 */ \
254
+ unsigned char buf[3]; \
255
+ buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
256
+ msgpack_pack_append_buffer(x, buf, 3); \
257
+ } \
258
+ } else { \
259
+ if(d < (1LL<<32)) { \
260
+ /* unsigned 32 */ \
261
+ unsigned char buf[5]; \
262
+ buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
263
+ msgpack_pack_append_buffer(x, buf, 5); \
264
+ } else { \
265
+ /* unsigned 64 */ \
266
+ unsigned char buf[9]; \
267
+ buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
268
+ msgpack_pack_append_buffer(x, buf, 9); \
269
+ } \
270
+ } \
271
+ } \
272
+ } while(0)
273
+
274
+
275
+ #ifdef msgpack_pack_inline_func_fastint
276
+
277
+ msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
278
+ {
279
+ unsigned char buf[2] = {0xcc, TAKE8_8(d)};
280
+ msgpack_pack_append_buffer(x, buf, 2);
281
+ }
282
+
283
+ msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
284
+ {
285
+ unsigned char buf[3];
286
+ buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
287
+ msgpack_pack_append_buffer(x, buf, 3);
288
+ }
289
+
290
+ msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
291
+ {
292
+ unsigned char buf[5];
293
+ buf[0] = 0xce; _msgpack_store32(&buf[1], d);
294
+ msgpack_pack_append_buffer(x, buf, 5);
295
+ }
296
+
297
+ msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
298
+ {
299
+ unsigned char buf[9];
300
+ buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
301
+ msgpack_pack_append_buffer(x, buf, 9);
302
+ }
303
+
304
+ msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
305
+ {
306
+ unsigned char buf[2] = {0xd0, TAKE8_8(d)};
307
+ msgpack_pack_append_buffer(x, buf, 2);
308
+ }
309
+
310
+ msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
311
+ {
312
+ unsigned char buf[3];
313
+ buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
314
+ msgpack_pack_append_buffer(x, buf, 3);
315
+ }
316
+
317
+ msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
318
+ {
319
+ unsigned char buf[5];
320
+ buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
321
+ msgpack_pack_append_buffer(x, buf, 5);
322
+ }
323
+
324
+ msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
325
+ {
326
+ unsigned char buf[9];
327
+ buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
328
+ msgpack_pack_append_buffer(x, buf, 9);
329
+ }
330
+
331
+ #undef msgpack_pack_inline_func_fastint
332
+ #endif
333
+
334
+
335
+ msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d)
336
+ {
337
+ msgpack_pack_real_uint8(x, d);
338
+ }
339
+
340
+ msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d)
341
+ {
342
+ msgpack_pack_real_uint16(x, d);
343
+ }
344
+
345
+ msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d)
346
+ {
347
+ msgpack_pack_real_uint32(x, d);
348
+ }
349
+
350
+ msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d)
351
+ {
352
+ msgpack_pack_real_uint64(x, d);
353
+ }
354
+
355
+ msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d)
356
+ {
357
+ msgpack_pack_real_int8(x, d);
358
+ }
359
+
360
+ msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d)
361
+ {
362
+ msgpack_pack_real_int16(x, d);
363
+ }
364
+
365
+ msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d)
366
+ {
367
+ msgpack_pack_real_int32(x, d);
368
+ }
369
+
370
+ msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
371
+ {
372
+ msgpack_pack_real_int64(x, d);
373
+ }
374
+
375
+
376
+ #ifdef msgpack_pack_inline_func_cint
377
+
378
+ msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d)
379
+ {
380
+ #if defined(SIZEOF_SHORT) || defined(SHRT_MAX)
381
+ #if SIZEOF_SHORT == 2 || SHRT_MAX == 0x7fff
382
+ msgpack_pack_real_int16(x, d);
383
+ #elif SIZEOF_SHORT == 4 || SHRT_MAX == 0x7fffffff
384
+ msgpack_pack_real_int32(x, d);
385
+ #else
386
+ msgpack_pack_real_int64(x, d);
387
+ #endif
388
+ #else
389
+ if(sizeof(short) == 2) {
390
+ msgpack_pack_real_int16(x, d);
391
+ } else if(sizeof(short) == 4) {
392
+ msgpack_pack_real_int32(x, d);
393
+ } else {
394
+ msgpack_pack_real_int64(x, d);
395
+ }
396
+ #endif
397
+ }
398
+
399
+ msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d)
400
+ {
401
+ #if defined(SIZEOF_INT) || defined(INT_MAX)
402
+ #if SIZEOF_INT == 2 || INT_MAX == 0x7fff
403
+ msgpack_pack_real_int16(x, d);
404
+ #elif SIZEOF_INT == 4 || INT_MAX == 0x7fffffff
405
+ msgpack_pack_real_int32(x, d);
406
+ #else
407
+ msgpack_pack_real_int64(x, d);
408
+ #endif
409
+ #else
410
+ if(sizeof(int) == 2) {
411
+ msgpack_pack_real_int16(x, d);
412
+ } else if(sizeof(int) == 4) {
413
+ msgpack_pack_real_int32(x, d);
414
+ } else {
415
+ msgpack_pack_real_int64(x, d);
416
+ }
417
+ #endif
418
+ }
419
+
420
+ msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d)
421
+ {
422
+ #if defined(SIZEOF_LONG) || defined(LONG_MAX)
423
+ #if SIZEOF_LONG == 2 || LONG_MAX == 0x7fffL
424
+ msgpack_pack_real_int16(x, d);
425
+ #elif SIZEOF_LONG == 4 || LONG_MAX == 0x7fffffffL
426
+ msgpack_pack_real_int32(x, d);
427
+ #else
428
+ msgpack_pack_real_int64(x, d);
429
+ #endif
430
+ #else
431
+ if(sizeof(long) == 2) {
432
+ msgpack_pack_real_int16(x, d);
433
+ } else if(sizeof(long) == 4) {
434
+ msgpack_pack_real_int32(x, d);
435
+ } else {
436
+ msgpack_pack_real_int64(x, d);
437
+ }
438
+ #endif
439
+ }
440
+
441
+ msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d)
442
+ {
443
+ #if defined(SIZEOF_LONG_LONG) || defined(LLONG_MAX)
444
+ #if SIZEOF_LONG_LONG == 2 || LLONG_MAX == 0x7fffL
445
+ msgpack_pack_real_int16(x, d);
446
+ #elif SIZEOF_LONG_LONG == 4 || LLONG_MAX == 0x7fffffffL
447
+ msgpack_pack_real_int32(x, d);
448
+ #else
449
+ msgpack_pack_real_int64(x, d);
450
+ #endif
451
+ #else
452
+ if(sizeof(long long) == 2) {
453
+ msgpack_pack_real_int16(x, d);
454
+ } else if(sizeof(long long) == 4) {
455
+ msgpack_pack_real_int32(x, d);
456
+ } else {
457
+ msgpack_pack_real_int64(x, d);
458
+ }
459
+ #endif
460
+ }
461
+
462
+ msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d)
463
+ {
464
+ #if defined(SIZEOF_SHORT) || defined(USHRT_MAX)
465
+ #if SIZEOF_SHORT == 2 || USHRT_MAX == 0xffffU
466
+ msgpack_pack_real_uint16(x, d);
467
+ #elif SIZEOF_SHORT == 4 || USHRT_MAX == 0xffffffffU
468
+ msgpack_pack_real_uint32(x, d);
469
+ #else
470
+ msgpack_pack_real_uint64(x, d);
471
+ #endif
472
+ #else
473
+ if(sizeof(unsigned short) == 2) {
474
+ msgpack_pack_real_uint16(x, d);
475
+ } else if(sizeof(unsigned short) == 4) {
476
+ msgpack_pack_real_uint32(x, d);
477
+ } else {
478
+ msgpack_pack_real_uint64(x, d);
479
+ }
480
+ #endif
481
+ }
482
+
483
+ msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d)
484
+ {
485
+ #if defined(SIZEOF_INT) || defined(UINT_MAX)
486
+ #if SIZEOF_INT == 2 || UINT_MAX == 0xffffU
487
+ msgpack_pack_real_uint16(x, d);
488
+ #elif SIZEOF_INT == 4 || UINT_MAX == 0xffffffffU
489
+ msgpack_pack_real_uint32(x, d);
490
+ #else
491
+ msgpack_pack_real_uint64(x, d);
492
+ #endif
493
+ #else
494
+ if(sizeof(unsigned int) == 2) {
495
+ msgpack_pack_real_uint16(x, d);
496
+ } else if(sizeof(unsigned int) == 4) {
497
+ msgpack_pack_real_uint32(x, d);
498
+ } else {
499
+ msgpack_pack_real_uint64(x, d);
500
+ }
501
+ #endif
502
+ }
503
+
504
+ msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d)
505
+ {
506
+ #if defined(SIZEOF_LONG) || defined(ULONG_MAX)
507
+ #if SIZEOF_LONG == 2 || ULONG_MAX == 0xffffUL
508
+ msgpack_pack_real_uint16(x, d);
509
+ #elif SIZEOF_LONG == 4 || ULONG_MAX == 0xffffffffUL
510
+ msgpack_pack_real_uint32(x, d);
511
+ #else
512
+ msgpack_pack_real_uint64(x, d);
513
+ #endif
514
+ #else
515
+ if(sizeof(unsigned int) == 2) {
516
+ msgpack_pack_real_uint16(x, d);
517
+ } else if(sizeof(unsigned int) == 4) {
518
+ msgpack_pack_real_uint32(x, d);
519
+ } else {
520
+ msgpack_pack_real_uint64(x, d);
521
+ }
522
+ #endif
523
+ }
524
+
525
+ msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
526
+ {
527
+ #if defined(SIZEOF_LONG_LONG) || defined(ULLONG_MAX)
528
+ #if SIZEOF_LONG_LONG == 2 || ULLONG_MAX == 0xffffUL
529
+ msgpack_pack_real_uint16(x, d);
530
+ #elif SIZEOF_LONG_LONG == 4 || ULLONG_MAX == 0xffffffffUL
531
+ msgpack_pack_real_uint32(x, d);
532
+ #else
533
+ msgpack_pack_real_uint64(x, d);
534
+ #endif
535
+ #else
536
+ if(sizeof(unsigned long long) == 2) {
537
+ msgpack_pack_real_uint16(x, d);
538
+ } else if(sizeof(unsigned long long) == 4) {
539
+ msgpack_pack_real_uint32(x, d);
540
+ } else {
541
+ msgpack_pack_real_uint64(x, d);
542
+ }
543
+ #endif
544
+ }
545
+
546
+ #undef msgpack_pack_inline_func_cint
547
+ #endif
548
+
549
+
550
+
551
+ /*
552
+ * Float
553
+ */
554
+
555
+ msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
556
+ {
557
+ union { float f; uint32_t i; } mem;
558
+ mem.f = d;
559
+ unsigned char buf[5];
560
+ buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
561
+ msgpack_pack_append_buffer(x, buf, 5);
562
+ }
563
+
564
+ msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
565
+ {
566
+ union { double f; uint64_t i; } mem;
567
+ mem.f = d;
568
+ unsigned char buf[9];
569
+ buf[0] = 0xcb; _msgpack_store64(&buf[1], mem.i);
570
+ msgpack_pack_append_buffer(x, buf, 9);
571
+ }
572
+
573
+
574
+ /*
575
+ * Nil
576
+ */
577
+
578
+ msgpack_pack_inline_func(_nil)(msgpack_pack_user x)
579
+ {
580
+ static const unsigned char d = 0xc0;
581
+ msgpack_pack_append_buffer(x, &d, 1);
582
+ }
583
+
584
+
585
+ /*
586
+ * Boolean
587
+ */
588
+
589
+ msgpack_pack_inline_func(_true)(msgpack_pack_user x)
590
+ {
591
+ static const unsigned char d = 0xc3;
592
+ msgpack_pack_append_buffer(x, &d, 1);
593
+ }
594
+
595
+ msgpack_pack_inline_func(_false)(msgpack_pack_user x)
596
+ {
597
+ static const unsigned char d = 0xc2;
598
+ msgpack_pack_append_buffer(x, &d, 1);
599
+ }
600
+
601
+
602
+ /*
603
+ * Array
604
+ */
605
+
606
+ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
607
+ {
608
+ if(n < 16) {
609
+ unsigned char d = 0x90 | n;
610
+ msgpack_pack_append_buffer(x, &d, 1);
611
+ } else if(n < 65536) {
612
+ unsigned char buf[3];
613
+ buf[0] = 0xdc; _msgpack_store16(&buf[1], n);
614
+ msgpack_pack_append_buffer(x, buf, 3);
615
+ } else {
616
+ unsigned char buf[5];
617
+ buf[0] = 0xdd; _msgpack_store32(&buf[1], n);
618
+ msgpack_pack_append_buffer(x, buf, 5);
619
+ }
620
+ }
621
+
622
+
623
+ /*
624
+ * Map
625
+ */
626
+
627
+ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
628
+ {
629
+ if(n < 16) {
630
+ unsigned char d = 0x80 | n;
631
+ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
632
+ } else if(n < 65536) {
633
+ unsigned char buf[3];
634
+ buf[0] = 0xde; _msgpack_store16(&buf[1], n);
635
+ msgpack_pack_append_buffer(x, buf, 3);
636
+ } else {
637
+ unsigned char buf[5];
638
+ buf[0] = 0xdf; _msgpack_store32(&buf[1], n);
639
+ msgpack_pack_append_buffer(x, buf, 5);
640
+ }
641
+ }
642
+
643
+
644
+ /*
645
+ * Raw
646
+ */
647
+
648
+ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
649
+ {
650
+ if(l < 32) {
651
+ unsigned char d = 0xa0 | l;
652
+ msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
653
+ } else if(l < 65536) {
654
+ unsigned char buf[3];
655
+ buf[0] = 0xda; _msgpack_store16(&buf[1], l);
656
+ msgpack_pack_append_buffer(x, buf, 3);
657
+ } else {
658
+ unsigned char buf[5];
659
+ buf[0] = 0xdb; _msgpack_store32(&buf[1], l);
660
+ msgpack_pack_append_buffer(x, buf, 5);
661
+ }
662
+ }
663
+
664
+ msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l)
665
+ {
666
+ msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
667
+ }
668
+
669
+ #undef msgpack_pack_inline_func
670
+ #undef msgpack_pack_user
671
+ #undef msgpack_pack_append_buffer
672
+
673
+ #undef TAKE8_8
674
+ #undef TAKE8_16
675
+ #undef TAKE8_32
676
+ #undef TAKE8_64
677
+
678
+ #undef msgpack_pack_real_uint8
679
+ #undef msgpack_pack_real_uint16
680
+ #undef msgpack_pack_real_uint32
681
+ #undef msgpack_pack_real_uint64
682
+ #undef msgpack_pack_real_int8
683
+ #undef msgpack_pack_real_int16
684
+ #undef msgpack_pack_real_int32
685
+ #undef msgpack_pack_real_int64
686
+