msgpack 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/ext/pack.c +6 -26
- data/lib/msgpack/version.rb +1 -1
- data/msgpack/pack_define.h +26 -0
- data/msgpack/pack_template.h +450 -84
- data/test/test_format.rb +142 -0
- metadata +7 -6
data/Manifest.txt
CHANGED
data/ext/pack.c
CHANGED
@@ -16,39 +16,19 @@
|
|
16
16
|
* limitations under the License.
|
17
17
|
*/
|
18
18
|
#include "ruby.h"
|
19
|
-
#include
|
20
|
-
#include <stdint.h>
|
19
|
+
#include "msgpack/pack_define.h"
|
21
20
|
|
22
21
|
#define msgpack_pack_inline_func(name) \
|
23
|
-
static void msgpack_pack_##name
|
22
|
+
static inline void msgpack_pack_##name
|
23
|
+
|
24
|
+
#define msgpack_pack_inline_func_cint(name) \
|
25
|
+
static inline void msgpack_pack_##name
|
24
26
|
|
25
27
|
#define msgpack_pack_user VALUE
|
26
28
|
|
27
29
|
#define msgpack_pack_append_buffer(user, buf, len) \
|
28
30
|
rb_str_buf_cat(user, (const void*)buf, len)
|
29
31
|
|
30
|
-
/*
|
31
|
-
static void msgpack_pack_int(VALUE x, int d);
|
32
|
-
static void msgpack_pack_unsigned_int(VALUE x, unsigned int d);
|
33
|
-
static void msgpack_pack_uint8(VALUE x, uint8_t d);
|
34
|
-
static void msgpack_pack_uint16(VALUE x, uint16_t d);
|
35
|
-
static void msgpack_pack_uint32(VALUE x, uint32_t d);
|
36
|
-
static void msgpack_pack_uint64(VALUE x, uint64_t d);
|
37
|
-
static void msgpack_pack_int8(VALUE x, int8_t d);
|
38
|
-
static void msgpack_pack_int16(VALUE x, int16_t d);
|
39
|
-
static void msgpack_pack_int32(VALUE x, int32_t d);
|
40
|
-
static void msgpack_pack_int64(VALUE x, int64_t d);
|
41
|
-
static void msgpack_pack_float(VALUE x, float d);
|
42
|
-
static void msgpack_pack_double(VALUE x, double d);
|
43
|
-
static void msgpack_pack_nil(VALUE x);
|
44
|
-
static void msgpack_pack_true(VALUE x);
|
45
|
-
static void msgpack_pack_false(VALUE x);
|
46
|
-
static void msgpack_pack_array(VALUE x, unsigned int n);
|
47
|
-
static void msgpack_pack_map(VALUE x, unsigned int n);
|
48
|
-
static void msgpack_pack_raw(VALUE x, size_t l);
|
49
|
-
static void msgpack_pack_raw_body(VALUE x, const void* b, size_t l);
|
50
|
-
*/
|
51
|
-
|
52
32
|
#include "msgpack/pack_template.h"
|
53
33
|
|
54
34
|
|
@@ -93,7 +73,7 @@ static VALUE MessagePack_FalseClass_to_msgpack(int argc, VALUE *argv, VALUE self
|
|
93
73
|
static VALUE MessagePack_Fixnum_to_msgpack(int argc, VALUE *argv, VALUE self)
|
94
74
|
{
|
95
75
|
ARG_BUFFER(out, argc, argv);
|
96
|
-
|
76
|
+
msgpack_pack_long(out, FIX2LONG(self));
|
97
77
|
return out;
|
98
78
|
}
|
99
79
|
|
data/lib/msgpack/version.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack unpacking routine template
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008 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 <stddef.h>
|
22
|
+
#include <stdint.h>
|
23
|
+
#include <limits.h>
|
24
|
+
|
25
|
+
#endif /* msgpack/pack_define.h */
|
26
|
+
|
data/msgpack/pack_template.h
CHANGED
@@ -50,7 +50,6 @@
|
|
50
50
|
|
51
51
|
#endif
|
52
52
|
|
53
|
-
|
54
53
|
#ifndef msgpack_pack_inline_func
|
55
54
|
#error msgpack_pack_inline_func template is not defined
|
56
55
|
#endif
|
@@ -68,126 +67,484 @@
|
|
68
67
|
* Integer
|
69
68
|
*/
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
{
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
} else if(d <
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
70
|
+
#define msgpack_pack_real_uint8(x, d) \
|
71
|
+
do { \
|
72
|
+
if(d < (1<<7)) { \
|
73
|
+
/* fixnum */ \
|
74
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
75
|
+
} else { \
|
76
|
+
/* unsigned 8 */ \
|
77
|
+
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
78
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
79
|
+
} \
|
80
|
+
} while(0)
|
81
|
+
|
82
|
+
#define msgpack_pack_real_uint16(x, d) \
|
83
|
+
do { \
|
84
|
+
if(d < (1<<7)) { \
|
85
|
+
/* fixnum */ \
|
86
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
87
|
+
} else if(d < (1<<8)) { \
|
88
|
+
/* unsigned 8 */ \
|
89
|
+
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
90
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
91
|
+
} else { \
|
92
|
+
/* unsigned 16 */ \
|
93
|
+
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
94
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
95
|
+
} \
|
96
|
+
} while(0)
|
97
|
+
|
98
|
+
#define msgpack_pack_real_uint32(x, d) \
|
99
|
+
do { \
|
100
|
+
if(d < (1<<8)) { \
|
101
|
+
if(d < (1<<7)) { \
|
102
|
+
/* fixnum */ \
|
103
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
104
|
+
} else { \
|
105
|
+
/* unsigned 8 */ \
|
106
|
+
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
107
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
108
|
+
} \
|
109
|
+
} else { \
|
110
|
+
if(d < (1<<16)) { \
|
111
|
+
/* unsigned 16 */ \
|
112
|
+
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
113
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
114
|
+
} else { \
|
115
|
+
/* unsigned 32 */ \
|
116
|
+
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
117
|
+
msgpack_pack_append_buffer(x, buf, 5); \
|
118
|
+
} \
|
119
|
+
} \
|
120
|
+
} while(0)
|
121
|
+
|
122
|
+
#define msgpack_pack_real_uint64(x, d) \
|
123
|
+
do { \
|
124
|
+
if(d < (1ULL<<8)) { \
|
125
|
+
if(d < (1<<7)) { \
|
126
|
+
/* fixnum */ \
|
127
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
128
|
+
} else { \
|
129
|
+
/* unsigned 8 */ \
|
130
|
+
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
131
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
132
|
+
} \
|
133
|
+
} else { \
|
134
|
+
if(d < (1ULL<<16)) { \
|
135
|
+
/* signed 16 */ \
|
136
|
+
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
137
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
138
|
+
} else if(d < (1ULL<<32)) { \
|
139
|
+
/* signed 32 */ \
|
140
|
+
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
141
|
+
msgpack_pack_append_buffer(x, buf, 5); \
|
142
|
+
} else { \
|
143
|
+
/* signed 64 */ \
|
144
|
+
const unsigned char buf[9] = {0xcf, STORE_BE64(d)}; \
|
145
|
+
msgpack_pack_append_buffer(x, buf, 9); \
|
146
|
+
} \
|
147
|
+
} \
|
148
|
+
} while(0)
|
149
|
+
|
150
|
+
#define msgpack_pack_real_int8(x, d) \
|
151
|
+
do { \
|
152
|
+
if(d < -(1<<5)) { \
|
153
|
+
/* signed 8 */ \
|
154
|
+
const unsigned char buf[2] = {0xd0, d}; \
|
155
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
156
|
+
} else { \
|
157
|
+
/* fixnum */ \
|
158
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
159
|
+
} \
|
160
|
+
} while(0)
|
161
|
+
|
162
|
+
#define msgpack_pack_real_int16(x, d) \
|
163
|
+
do { \
|
164
|
+
if(d < -(1<<5)) { \
|
165
|
+
if(d < -(1<<7)) { \
|
166
|
+
/* signed 16 */ \
|
167
|
+
const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; \
|
168
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
169
|
+
} else { \
|
170
|
+
/* signed 8 */ \
|
171
|
+
const unsigned char buf[2] = {0xd0, (uint8_t)d}; \
|
172
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
173
|
+
} \
|
174
|
+
} else if(d < (1<<7)) { \
|
175
|
+
/* fixnum */ \
|
176
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
177
|
+
} else { \
|
178
|
+
if(d < (1<<8)) { \
|
179
|
+
/* unsigned 8 */ \
|
180
|
+
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
181
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
182
|
+
} else { \
|
183
|
+
/* unsigned 16 */ \
|
184
|
+
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
185
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
186
|
+
} \
|
187
|
+
} \
|
188
|
+
} while(0)
|
189
|
+
|
190
|
+
#define msgpack_pack_real_int32(x, d) \
|
191
|
+
do { \
|
192
|
+
if(d < -(1<<5)) { \
|
193
|
+
if(d < -(1<<15)) { \
|
194
|
+
/* signed 32 */ \
|
195
|
+
const unsigned char buf[5] = {0xd2, STORE_BE32(d)}; \
|
196
|
+
msgpack_pack_append_buffer(x, buf, 5); \
|
197
|
+
} else if(d < -(1<<7)) { \
|
198
|
+
/* signed 16 */ \
|
199
|
+
const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; \
|
200
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
201
|
+
} else { \
|
202
|
+
/* signed 8 */ \
|
203
|
+
const unsigned char buf[2] = {0xd0, (uint8_t)d}; \
|
204
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
205
|
+
} \
|
206
|
+
} else if(d < (1<<7)) { \
|
207
|
+
/* fixnum */ \
|
208
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
209
|
+
} else { \
|
210
|
+
if(d < (1<<8)) { \
|
211
|
+
/* unsigned 8 */ \
|
212
|
+
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
213
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
214
|
+
} else if(d < (1<<16)) { \
|
215
|
+
/* unsigned 16 */ \
|
216
|
+
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
217
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
218
|
+
} else { \
|
219
|
+
/* unsigned 32 */ \
|
220
|
+
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
221
|
+
msgpack_pack_append_buffer(x, buf, 5); \
|
222
|
+
} \
|
223
|
+
} \
|
224
|
+
} while(0)
|
225
|
+
|
226
|
+
#define msgpack_pack_real_int64(x, d) \
|
227
|
+
do { \
|
228
|
+
if(d < -(1LL<<5)) { \
|
229
|
+
if(d < -(1LL<<15)) { \
|
230
|
+
if(d < -(1LL<<31)) { \
|
231
|
+
/* signed 64 */ \
|
232
|
+
const unsigned char buf[9] = {0xd3, STORE_BE64(d)}; \
|
233
|
+
msgpack_pack_append_buffer(x, buf, 9); \
|
234
|
+
} else { \
|
235
|
+
/* signed 32 */ \
|
236
|
+
const unsigned char buf[5] = {0xd2, STORE_BE32(d)}; \
|
237
|
+
msgpack_pack_append_buffer(x, buf, 5); \
|
238
|
+
} \
|
239
|
+
} else { \
|
240
|
+
if(d < -(1<<7)) { \
|
241
|
+
/* signed 16 */ \
|
242
|
+
const unsigned char buf[3] = {0xd1, STORE_BE16(d)}; \
|
243
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
244
|
+
} else { \
|
245
|
+
/* signed 8 */ \
|
246
|
+
const unsigned char buf[2] = {0xd0, (uint8_t)d}; \
|
247
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
248
|
+
} \
|
249
|
+
} \
|
250
|
+
} else if(d < (1<<7)) { \
|
251
|
+
/* fixnum */ \
|
252
|
+
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1); \
|
253
|
+
} else { \
|
254
|
+
if(d < (1LL<<16)) { \
|
255
|
+
if(d < (1<<8)) { \
|
256
|
+
/* unsigned 8 */ \
|
257
|
+
const unsigned char buf[2] = {0xcc, (uint8_t)d}; \
|
258
|
+
msgpack_pack_append_buffer(x, buf, 2); \
|
259
|
+
} else { \
|
260
|
+
/* unsigned 16 */ \
|
261
|
+
const unsigned char buf[3] = {0xcd, STORE_BE16(d)}; \
|
262
|
+
msgpack_pack_append_buffer(x, buf, 3); \
|
263
|
+
} \
|
264
|
+
} else { \
|
265
|
+
if(d < (1LL<<32)) { \
|
266
|
+
/* unsigned 32 */ \
|
267
|
+
const unsigned char buf[5] = {0xce, STORE_BE32(d)}; \
|
268
|
+
msgpack_pack_append_buffer(x, buf, 5); \
|
269
|
+
} else { \
|
270
|
+
/* unsigned 64 */ \
|
271
|
+
const unsigned char buf[9] = {0xcf, STORE_BE64(d)}; \
|
272
|
+
msgpack_pack_append_buffer(x, buf, 9); \
|
273
|
+
} \
|
274
|
+
} \
|
275
|
+
} \
|
276
|
+
} while(0)
|
277
|
+
|
278
|
+
|
279
|
+
#ifdef msgpack_pack_inline_func_fastint
|
280
|
+
|
281
|
+
msgpack_pack_inline_func_fastint(uint8)(msgpack_pack_user x, uint8_t d)
|
282
|
+
{
|
283
|
+
const unsigned char buf[2] = {0xcc, d};
|
284
|
+
msgpack_pack_append_buffer(x, buf, 2);
|
106
285
|
}
|
107
286
|
|
108
|
-
|
109
|
-
msgpack_pack_inline_func(unsigned_int)(msgpack_pack_user x, unsigned int d)
|
287
|
+
msgpack_pack_inline_func_fastint(uint16)(msgpack_pack_user x, uint16_t d)
|
110
288
|
{
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
289
|
+
const unsigned char buf[3] = {0xcd, STORE_BE16(d)};
|
290
|
+
msgpack_pack_append_buffer(x, buf, 3);
|
291
|
+
}
|
292
|
+
|
293
|
+
msgpack_pack_inline_func_fastint(uint32)(msgpack_pack_user x, uint32_t d)
|
294
|
+
{
|
295
|
+
const unsigned char buf[5] = {0xce, STORE_BE32(d)};
|
296
|
+
msgpack_pack_append_buffer(x, buf, 5);
|
297
|
+
}
|
298
|
+
|
299
|
+
msgpack_pack_inline_func_fastint(uint64)(msgpack_pack_user x, uint64_t d)
|
300
|
+
{
|
301
|
+
const unsigned char buf[9] = {0xcf, STORE_BE64(d)};
|
302
|
+
msgpack_pack_append_buffer(x, buf, 9);
|
303
|
+
}
|
304
|
+
|
305
|
+
msgpack_pack_inline_func_fastint(int8)(msgpack_pack_user x, int8_t d)
|
306
|
+
{
|
307
|
+
const unsigned char buf[2] = {0xd0, d};
|
308
|
+
msgpack_pack_append_buffer(x, buf, 2);
|
131
309
|
}
|
132
310
|
|
311
|
+
msgpack_pack_inline_func_fastint(int16)(msgpack_pack_user x, int16_t d)
|
312
|
+
{
|
313
|
+
const unsigned char buf[3] = {0xd1, STORE_BE16(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
|
+
const unsigned char buf[5] = {0xd2, STORE_BE32(d)};
|
320
|
+
msgpack_pack_append_buffer(x, buf, 5);
|
321
|
+
}
|
322
|
+
|
323
|
+
msgpack_pack_inline_func_fastint(int64)(msgpack_pack_user x, int64_t d)
|
324
|
+
{
|
325
|
+
const unsigned char buf[9] = {0xd3, STORE_BE64(d)};
|
326
|
+
msgpack_pack_append_buffer(x, buf, 9);
|
327
|
+
}
|
328
|
+
|
329
|
+
#undef msgpack_pack_inline_func_fastint
|
330
|
+
#endif
|
331
|
+
|
332
|
+
|
133
333
|
msgpack_pack_inline_func(uint8)(msgpack_pack_user x, uint8_t d)
|
134
334
|
{
|
135
|
-
|
136
|
-
msgpack_pack_append_buffer(x, &d, 1);
|
137
|
-
} else {
|
138
|
-
const unsigned char buf[2] = {0xcc, d};
|
139
|
-
msgpack_pack_append_buffer(x, buf, 2);
|
140
|
-
}
|
335
|
+
msgpack_pack_real_uint8(x, d);
|
141
336
|
}
|
142
337
|
|
143
338
|
msgpack_pack_inline_func(uint16)(msgpack_pack_user x, uint16_t d)
|
144
339
|
{
|
145
|
-
|
146
|
-
msgpack_pack_append_buffer(x, buf, 3);
|
340
|
+
msgpack_pack_real_uint16(x, d);
|
147
341
|
}
|
148
342
|
|
149
343
|
msgpack_pack_inline_func(uint32)(msgpack_pack_user x, uint32_t d)
|
150
344
|
{
|
151
|
-
|
152
|
-
msgpack_pack_append_buffer(x, buf, 5);
|
345
|
+
msgpack_pack_real_uint32(x, d);
|
153
346
|
}
|
154
347
|
|
155
348
|
msgpack_pack_inline_func(uint64)(msgpack_pack_user x, uint64_t d)
|
156
349
|
{
|
157
|
-
|
158
|
-
msgpack_pack_append_buffer(x, buf, 9);
|
350
|
+
msgpack_pack_real_uint64(x, d);
|
159
351
|
}
|
160
352
|
|
161
353
|
msgpack_pack_inline_func(int8)(msgpack_pack_user x, int8_t d)
|
162
354
|
{
|
163
|
-
|
164
|
-
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
|
165
|
-
} else if(d >= -32) {
|
166
|
-
msgpack_pack_append_buffer(x, (uint8_t*)&d, 1);
|
167
|
-
} else {
|
168
|
-
const unsigned char buf[2] = {0xd0, d};
|
169
|
-
msgpack_pack_append_buffer(x, buf, 2);
|
170
|
-
}
|
355
|
+
msgpack_pack_real_int8(x, d);
|
171
356
|
}
|
172
357
|
|
173
358
|
msgpack_pack_inline_func(int16)(msgpack_pack_user x, int16_t d)
|
174
359
|
{
|
175
|
-
|
176
|
-
msgpack_pack_append_buffer(x, buf, 3);
|
360
|
+
msgpack_pack_real_int16(x, d);
|
177
361
|
}
|
178
362
|
|
179
363
|
msgpack_pack_inline_func(int32)(msgpack_pack_user x, int32_t d)
|
180
364
|
{
|
181
|
-
|
182
|
-
msgpack_pack_append_buffer(x, buf, 5);
|
365
|
+
msgpack_pack_real_int32(x, d);
|
183
366
|
}
|
184
367
|
|
185
368
|
msgpack_pack_inline_func(int64)(msgpack_pack_user x, int64_t d)
|
186
369
|
{
|
187
|
-
|
188
|
-
|
370
|
+
msgpack_pack_real_int64(x, d);
|
371
|
+
}
|
372
|
+
|
373
|
+
|
374
|
+
#ifdef msgpack_pack_inline_func_cint
|
375
|
+
|
376
|
+
msgpack_pack_inline_func_cint(short)(msgpack_pack_user x, short d)
|
377
|
+
{
|
378
|
+
#if defined(SIZEOF_SHORT) || defined(SHRT_MAX)
|
379
|
+
#if SIZEOF_SHORT == 2 || SHRT_MAX == 0x7fff
|
380
|
+
msgpack_pack_real_int16(x, d);
|
381
|
+
#elif SIZEOF_SHORT == 4 || SHRT_MAX == 0x7fffffff
|
382
|
+
msgpack_pack_real_int32(x, d);
|
383
|
+
#else
|
384
|
+
msgpack_pack_real_int64(x, d);
|
385
|
+
#endif
|
386
|
+
#else
|
387
|
+
if(sizeof(short) == 2) {
|
388
|
+
msgpack_pack_real_int16(x, d);
|
389
|
+
} else if(sizeof(short) == 4) {
|
390
|
+
msgpack_pack_real_int32(x, d);
|
391
|
+
} else {
|
392
|
+
msgpack_pack_real_int64(x, d);
|
393
|
+
}
|
394
|
+
#endif
|
395
|
+
}
|
396
|
+
|
397
|
+
msgpack_pack_inline_func_cint(int)(msgpack_pack_user x, int d)
|
398
|
+
{
|
399
|
+
#if defined(SIZEOF_INT) || defined(INT_MAX)
|
400
|
+
#if SIZEOF_INT == 2 || INT_MAX == 0x7fff
|
401
|
+
msgpack_pack_real_int16(x, d);
|
402
|
+
#elif SIZEOF_INT == 4 || INT_MAX == 0x7fffffff
|
403
|
+
msgpack_pack_real_int32(x, d);
|
404
|
+
#else
|
405
|
+
msgpack_pack_real_int64(x, d);
|
406
|
+
#endif
|
407
|
+
#else
|
408
|
+
if(sizeof(int) == 2) {
|
409
|
+
msgpack_pack_real_int16(x, d);
|
410
|
+
} else if(sizeof(int) == 4) {
|
411
|
+
msgpack_pack_real_int32(x, d);
|
412
|
+
} else {
|
413
|
+
msgpack_pack_real_int64(x, d);
|
414
|
+
}
|
415
|
+
#endif
|
416
|
+
}
|
417
|
+
|
418
|
+
msgpack_pack_inline_func_cint(long)(msgpack_pack_user x, long d)
|
419
|
+
{
|
420
|
+
#if defined(SIZEOF_LONG) || defined(LONG_MAX)
|
421
|
+
#if SIZEOF_LONG == 2 || LONG_MAX == 0x7fffL
|
422
|
+
msgpack_pack_real_int16(x, d);
|
423
|
+
#elif SIZEOF_LONG == 4 || LONG_MAX == 0x7fffffffL
|
424
|
+
msgpack_pack_real_int32(x, d);
|
425
|
+
#else
|
426
|
+
msgpack_pack_real_int64(x, d);
|
427
|
+
#endif
|
428
|
+
#else
|
429
|
+
if(sizeof(long) == 2) {
|
430
|
+
msgpack_pack_real_int16(x, d);
|
431
|
+
} else if(sizeof(long) == 4) {
|
432
|
+
msgpack_pack_real_int32(x, d);
|
433
|
+
} else {
|
434
|
+
msgpack_pack_real_int64(x, d);
|
435
|
+
}
|
436
|
+
#endif
|
189
437
|
}
|
190
438
|
|
439
|
+
msgpack_pack_inline_func_cint(long_long)(msgpack_pack_user x, long long d)
|
440
|
+
{
|
441
|
+
#if defined(SIZEOF_LONG_LONG) || defined(LLONG_MAX)
|
442
|
+
#if SIZEOF_LONG_LONG == 2 || LLONG_MAX == 0x7fffL
|
443
|
+
msgpack_pack_real_int16(x, d);
|
444
|
+
#elif SIZEOF_LONG_LONG == 4 || LLONG_MAX == 0x7fffffffL
|
445
|
+
msgpack_pack_real_int32(x, d);
|
446
|
+
#else
|
447
|
+
msgpack_pack_real_int64(x, d);
|
448
|
+
#endif
|
449
|
+
#else
|
450
|
+
if(sizeof(long long) == 2) {
|
451
|
+
msgpack_pack_real_int16(x, d);
|
452
|
+
} else if(sizeof(long long) == 4) {
|
453
|
+
msgpack_pack_real_int32(x, d);
|
454
|
+
} else {
|
455
|
+
msgpack_pack_real_int64(x, d);
|
456
|
+
}
|
457
|
+
#endif
|
458
|
+
}
|
459
|
+
|
460
|
+
msgpack_pack_inline_func_cint(unsigned_short)(msgpack_pack_user x, unsigned short d)
|
461
|
+
{
|
462
|
+
#if defined(SIZEOF_SHORT) || defined(USHRT_MAX)
|
463
|
+
#if SIZEOF_SHORT == 2 || USHRT_MAX == 0xffffU
|
464
|
+
msgpack_pack_real_uint16(x, d);
|
465
|
+
#elif SIZEOF_SHORT == 4 || USHRT_MAX == 0xffffffffU
|
466
|
+
msgpack_pack_real_uint32(x, d);
|
467
|
+
#else
|
468
|
+
msgpack_pack_real_uint64(x, d);
|
469
|
+
#endif
|
470
|
+
#else
|
471
|
+
if(sizeof(unsigned short) == 2) {
|
472
|
+
msgpack_pack_real_uint16(x, d);
|
473
|
+
} else if(sizeof(unsigned short) == 4) {
|
474
|
+
msgpack_pack_real_uint32(x, d);
|
475
|
+
} else {
|
476
|
+
msgpack_pack_real_uint64(x, d);
|
477
|
+
}
|
478
|
+
#endif
|
479
|
+
}
|
480
|
+
|
481
|
+
msgpack_pack_inline_func_cint(unsigned_int)(msgpack_pack_user x, unsigned int d)
|
482
|
+
{
|
483
|
+
#if defined(SIZEOF_INT) || defined(UINT_MAX)
|
484
|
+
#if SIZEOF_INT == 2 || UINT_MAX == 0xffffU
|
485
|
+
msgpack_pack_real_uint16(x, d);
|
486
|
+
#elif SIZEOF_INT == 4 || UINT_MAX == 0xffffffffU
|
487
|
+
msgpack_pack_real_uint32(x, d);
|
488
|
+
#else
|
489
|
+
msgpack_pack_real_uint64(x, d);
|
490
|
+
#endif
|
491
|
+
#else
|
492
|
+
if(sizeof(unsigned int) == 2) {
|
493
|
+
msgpack_pack_real_uint16(x, d);
|
494
|
+
} else if(sizeof(unsigned int) == 4) {
|
495
|
+
msgpack_pack_real_uint32(x, d);
|
496
|
+
} else {
|
497
|
+
msgpack_pack_real_uint64(x, d);
|
498
|
+
}
|
499
|
+
#endif
|
500
|
+
}
|
501
|
+
|
502
|
+
msgpack_pack_inline_func_cint(unsigned_long)(msgpack_pack_user x, unsigned long d)
|
503
|
+
{
|
504
|
+
#if defined(SIZEOF_LONG) || defined(ULONG_MAX)
|
505
|
+
#if SIZEOF_LONG == 2 || ULONG_MAX == 0xffffUL
|
506
|
+
msgpack_pack_real_uint16(x, d);
|
507
|
+
#elif SIZEOF_LONG == 4 || ULONG_MAX == 0xffffffffUL
|
508
|
+
msgpack_pack_real_uint32(x, d);
|
509
|
+
#else
|
510
|
+
msgpack_pack_real_uint64(x, d);
|
511
|
+
#endif
|
512
|
+
#else
|
513
|
+
if(sizeof(unsigned int) == 2) {
|
514
|
+
msgpack_pack_real_uint16(x, d);
|
515
|
+
} else if(sizeof(unsigned int) == 4) {
|
516
|
+
msgpack_pack_real_uint32(x, d);
|
517
|
+
} else {
|
518
|
+
msgpack_pack_real_uint64(x, d);
|
519
|
+
}
|
520
|
+
#endif
|
521
|
+
}
|
522
|
+
|
523
|
+
msgpack_pack_inline_func_cint(unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
|
524
|
+
{
|
525
|
+
#if defined(SIZEOF_LONG_LONG) || defined(ULLONG_MAX)
|
526
|
+
#if SIZEOF_LONG_LONG == 2 || ULLONG_MAX == 0xffffUL
|
527
|
+
msgpack_pack_real_uint16(x, d);
|
528
|
+
#elif SIZEOF_LONG_LONG == 4 || ULLONG_MAX == 0xffffffffUL
|
529
|
+
msgpack_pack_real_uint32(x, d);
|
530
|
+
#else
|
531
|
+
msgpack_pack_real_uint64(x, d);
|
532
|
+
#endif
|
533
|
+
#else
|
534
|
+
if(sizeof(unsigned long long) == 2) {
|
535
|
+
msgpack_pack_real_uint16(x, d);
|
536
|
+
} else if(sizeof(unsigned long long) == 4) {
|
537
|
+
msgpack_pack_real_uint32(x, d);
|
538
|
+
} else {
|
539
|
+
msgpack_pack_real_uint64(x, d);
|
540
|
+
}
|
541
|
+
#endif
|
542
|
+
}
|
543
|
+
|
544
|
+
#undef msgpack_pack_inline_func_cint
|
545
|
+
#endif
|
546
|
+
|
547
|
+
|
191
548
|
|
192
549
|
/*
|
193
550
|
* Float
|
@@ -311,3 +668,12 @@ msgpack_pack_inline_func(raw_body)(msgpack_pack_user x, const void* b, size_t l)
|
|
311
668
|
#undef STORE_BE32
|
312
669
|
#undef STORE_BE64
|
313
670
|
|
671
|
+
#undef msgpack_pack_real_uint8
|
672
|
+
#undef msgpack_pack_real_uint16
|
673
|
+
#undef msgpack_pack_real_uint32
|
674
|
+
#undef msgpack_pack_real_uint64
|
675
|
+
#undef msgpack_pack_real_int8
|
676
|
+
#undef msgpack_pack_real_int16
|
677
|
+
#undef msgpack_pack_real_int32
|
678
|
+
#undef msgpack_pack_real_int64
|
679
|
+
|
data/test/test_format.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'msgpack'
|
3
|
+
|
4
|
+
class MessagePackTestFormat < Test::Unit::TestCase
|
5
|
+
def self.it(name, &block)
|
6
|
+
define_method("test_#{name}", &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "nil" do
|
10
|
+
check 1, nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "true" do
|
14
|
+
check 1, true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "false" do
|
18
|
+
check 1, false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "zero" do
|
22
|
+
check 1, 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it "positive fixnum" do
|
26
|
+
check 1, 1
|
27
|
+
check 1, (1<<6)
|
28
|
+
check 1, (1<<7)-1
|
29
|
+
end
|
30
|
+
|
31
|
+
it "positive int 8" do
|
32
|
+
check 1, -1
|
33
|
+
check 2, (1<<7)
|
34
|
+
check 2, (1<<8)-1
|
35
|
+
end
|
36
|
+
|
37
|
+
it "positive int 16" do
|
38
|
+
check 3, (1<<8)
|
39
|
+
check 3, (1<<16)-1
|
40
|
+
end
|
41
|
+
|
42
|
+
it "positive int 32" do
|
43
|
+
check 5, (1<<16)
|
44
|
+
check 5, (1<<32)-1
|
45
|
+
end
|
46
|
+
|
47
|
+
it "positive int 64" do
|
48
|
+
check 9, (1<<32)
|
49
|
+
check 9, (1<<64)-1
|
50
|
+
end
|
51
|
+
|
52
|
+
it "negative fixnum" do
|
53
|
+
check 1, -1
|
54
|
+
check 1, -((1<<5)-1)
|
55
|
+
check 1, -(1<<5)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "negative int 8" do
|
59
|
+
check 2, -((1<<5)+1)
|
60
|
+
check 2, -(1<<7)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "negative int 16" do
|
64
|
+
check 3, -((1<<7)+1)
|
65
|
+
check 3, -(1<<15)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "negative int 32" do
|
69
|
+
check 5, -((1<<15)+1)
|
70
|
+
check 5, -(1<<31)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "negative int 64" do
|
74
|
+
check 9, -((1<<31)+1)
|
75
|
+
check 9, -(1<<63)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "fixraw" do
|
79
|
+
check_raw 1, 0
|
80
|
+
check_raw 1, (1<<5)-1
|
81
|
+
end
|
82
|
+
|
83
|
+
it "raw 16" do
|
84
|
+
check_raw 3, (1<<5)
|
85
|
+
check_raw 3, (1<<16)-1
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raw 32" do
|
89
|
+
check_raw 5, (1<<16)
|
90
|
+
#check_raw 5, (1<<32)-1 # memory error
|
91
|
+
end
|
92
|
+
|
93
|
+
it "fixarray" do
|
94
|
+
check_array 1, 0
|
95
|
+
check_array 1, (1<<4)-1
|
96
|
+
end
|
97
|
+
|
98
|
+
it "array 16" do
|
99
|
+
check_array 3, (1<<4)
|
100
|
+
check_array 3, (1<<16)-1
|
101
|
+
end
|
102
|
+
|
103
|
+
it "array 32" do
|
104
|
+
check_array 5, (1<<16)
|
105
|
+
#check_array 5, (1<<32)-1 # memory error
|
106
|
+
end
|
107
|
+
|
108
|
+
# it "fixmap" do
|
109
|
+
# check_map 1, 0
|
110
|
+
# check_map 1, (1<<4)-1
|
111
|
+
# end
|
112
|
+
#
|
113
|
+
# it "map 16" do
|
114
|
+
# check_map 3, (1<<4)
|
115
|
+
# check_map 3, (1<<16)-1
|
116
|
+
# end
|
117
|
+
#
|
118
|
+
# it "map 32" do
|
119
|
+
# check_map 5, (1<<16)
|
120
|
+
# #check_map 5, (1<<32)-1 # memory error
|
121
|
+
# end
|
122
|
+
|
123
|
+
private
|
124
|
+
def check(len, obj)
|
125
|
+
v = obj.to_msgpack
|
126
|
+
assert_equal(v.length, len)
|
127
|
+
assert_equal(MessagePack.unpack(v), obj)
|
128
|
+
end
|
129
|
+
|
130
|
+
def check_raw(overhead, num)
|
131
|
+
check num+overhead, " "*num
|
132
|
+
end
|
133
|
+
|
134
|
+
def check_array(overhead, num)
|
135
|
+
check num+overhead, Array.new(num)
|
136
|
+
end
|
137
|
+
|
138
|
+
def check_map(overhead, num)
|
139
|
+
# FIXME
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FURUHASHI Sadayuki
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-07 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
23
|
+
version: 1.8.0
|
24
24
|
version:
|
25
25
|
description: An object-oriented parser generator based on Parser Expression Grammar
|
26
26
|
email:
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- ext/rbinit.c
|
47
47
|
- ext/unpack.c
|
48
48
|
- ext/unpack.h
|
49
|
+
- msgpack/pack_define.h
|
49
50
|
- msgpack/pack_template.h
|
50
51
|
- msgpack/unpack_define.h
|
51
52
|
- msgpack/unpack_template.h
|
@@ -82,9 +83,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
requirements: []
|
83
84
|
|
84
85
|
rubyforge_project: msgpack
|
85
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.3.1
|
86
87
|
signing_key:
|
87
88
|
specification_version: 2
|
88
89
|
summary: An object-oriented parser generator based on Parser Expression Grammar
|
89
|
-
test_files:
|
90
|
-
|
90
|
+
test_files:
|
91
|
+
- test/test_format.rb
|