msgpack 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/msgpack/pack_template.h +132 -72
- data/test/msgpack_test.rb +76 -2
- metadata +2 -2
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ DESCRIPTION = "Binary-based efficient data interchange format."
|
|
17
17
|
RUBYFORGE_PROJECT = "msgpack"
|
18
18
|
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
19
19
|
BIN_FILES = %w( )
|
20
|
-
VERS = "0.3.
|
20
|
+
VERS = "0.3.1"
|
21
21
|
|
22
22
|
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
23
|
REV = nil
|
data/msgpack/pack_template.h
CHANGED
@@ -24,29 +24,79 @@
|
|
24
24
|
#endif
|
25
25
|
#endif
|
26
26
|
|
27
|
+
|
27
28
|
#ifdef __LITTLE_ENDIAN__
|
28
29
|
|
29
|
-
#define
|
30
|
-
((
|
30
|
+
#define STORE8_BE8(d) \
|
31
|
+
((uint8_t*)&d)[0]
|
32
|
+
|
33
|
+
|
34
|
+
#define STORE16_BE8(d) \
|
35
|
+
((uint8_t*)&d)[0]
|
36
|
+
|
37
|
+
#define STORE16_BE16(d) \
|
38
|
+
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
39
|
+
|
40
|
+
|
41
|
+
#define STORE32_BE8(d) \
|
42
|
+
((uint8_t*)&d)[0]
|
43
|
+
|
44
|
+
#define STORE32_BE16(d) \
|
45
|
+
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
31
46
|
|
32
|
-
#define
|
33
|
-
((
|
47
|
+
#define STORE32_BE32(d) \
|
48
|
+
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
49
|
+
|
50
|
+
|
51
|
+
#define STORE64_BE8(d) \
|
52
|
+
((uint8_t*)&d)[0]
|
53
|
+
|
54
|
+
#define STORE64_BE16(d) \
|
55
|
+
((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
56
|
+
|
57
|
+
#define STORE64_BE32(d) \
|
58
|
+
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
59
|
+
|
60
|
+
#define STORE64_BE64(d) \
|
61
|
+
((uint8_t*)&d)[7], ((uint8_t*)&d)[6], ((uint8_t*)&d)[5], ((uint8_t*)&d)[4], \
|
62
|
+
((uint8_t*)&d)[3], ((uint8_t*)&d)[2], ((uint8_t*)&d)[1], ((uint8_t*)&d)[0]
|
34
63
|
|
35
|
-
#define STORE_BE64(d) \
|
36
|
-
((char*)&d)[7], ((char*)&d)[6], ((char*)&d)[5], ((char*)&d)[4], \
|
37
|
-
((char*)&d)[3], ((char*)&d)[2], ((char*)&d)[1], ((char*)&d)[0]
|
38
64
|
|
39
65
|
#elif __BIG_ENDIAN__
|
40
66
|
|
41
|
-
#define
|
42
|
-
((
|
67
|
+
#define STORE8_BE8(d) \
|
68
|
+
((uint8_t*)&d)[0]
|
69
|
+
|
70
|
+
|
71
|
+
#define STORE16_BE8(d) \
|
72
|
+
((uint8_t*)&d)[1]
|
43
73
|
|
44
|
-
#define
|
45
|
-
((
|
74
|
+
#define STORE16_BE16(d) \
|
75
|
+
((uint8_t*)&d)[0], ((uint8_t*)&d)[1]
|
46
76
|
|
47
|
-
|
48
|
-
|
49
|
-
((
|
77
|
+
|
78
|
+
#define STORE32_BE8(d) \
|
79
|
+
((uint8_t*)&d)[3]
|
80
|
+
|
81
|
+
#define STORE32_BE16(d) \
|
82
|
+
((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
|
83
|
+
|
84
|
+
#define STORE32_BE32(d) \
|
85
|
+
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3]
|
86
|
+
|
87
|
+
|
88
|
+
#define STORE64_BE8(d) \
|
89
|
+
((uint8_t*)&d)[7]
|
90
|
+
|
91
|
+
#define STORE64_BE16(d) \
|
92
|
+
((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
93
|
+
|
94
|
+
#define STORE64_BE32(d) \
|
95
|
+
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
96
|
+
|
97
|
+
#define STORE64_BE64(d) \
|
98
|
+
((uint8_t*)&d)[0], ((uint8_t*)&d)[1], ((uint8_t*)&d)[2], ((uint8_t*)&d)[3], \
|
99
|
+
((uint8_t*)&d)[4], ((uint8_t*)&d)[5], ((uint8_t*)&d)[6], ((uint8_t*)&d)[7]
|
50
100
|
|
51
101
|
#endif
|
52
102
|
|
@@ -71,10 +121,10 @@
|
|
71
121
|
do { \
|
72
122
|
if(d < (1<<7)) { \
|
73
123
|
/* fixnum */ \
|
74
|
-
msgpack_pack_append_buffer(x, (
|
124
|
+
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
|
75
125
|
} else { \
|
76
126
|
/* unsigned 8 */ \
|
77
|
-
const unsigned char buf[2] = {0xcc, (
|
127
|
+
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)}; \
|
78
128
|
msgpack_pack_append_buffer(x, buf, 2); \
|
79
129
|
} \
|
80
130
|
} while(0)
|
@@ -83,14 +133,14 @@ do { \
|
|
83
133
|
do { \
|
84
134
|
if(d < (1<<7)) { \
|
85
135
|
/* fixnum */ \
|
86
|
-
msgpack_pack_append_buffer(x, (
|
136
|
+
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
|
87
137
|
} else if(d < (1<<8)) { \
|
88
138
|
/* unsigned 8 */ \
|
89
|
-
const unsigned char buf[2] = {0xcc, (
|
139
|
+
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
90
140
|
msgpack_pack_append_buffer(x, buf, 2); \
|
91
141
|
} else { \
|
92
142
|
/* unsigned 16 */ \
|
93
|
-
const unsigned char buf[3] = {0xcd,
|
143
|
+
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
|
94
144
|
msgpack_pack_append_buffer(x, buf, 3); \
|
95
145
|
} \
|
96
146
|
} while(0)
|
@@ -100,20 +150,20 @@ do { \
|
|
100
150
|
if(d < (1<<8)) { \
|
101
151
|
if(d < (1<<7)) { \
|
102
152
|
/* fixnum */ \
|
103
|
-
msgpack_pack_append_buffer(x, (
|
153
|
+
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
|
104
154
|
} else { \
|
105
155
|
/* unsigned 8 */ \
|
106
|
-
const unsigned char buf[2] = {0xcc, (
|
156
|
+
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
107
157
|
msgpack_pack_append_buffer(x, buf, 2); \
|
108
158
|
} \
|
109
159
|
} else { \
|
110
160
|
if(d < (1<<16)) { \
|
111
161
|
/* unsigned 16 */ \
|
112
|
-
const unsigned char buf[3] = {0xcd,
|
162
|
+
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
113
163
|
msgpack_pack_append_buffer(x, buf, 3); \
|
114
164
|
} else { \
|
115
165
|
/* unsigned 32 */ \
|
116
|
-
const unsigned char buf[5] = {0xce,
|
166
|
+
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
|
117
167
|
msgpack_pack_append_buffer(x, buf, 5); \
|
118
168
|
} \
|
119
169
|
} \
|
@@ -124,24 +174,24 @@ do { \
|
|
124
174
|
if(d < (1ULL<<8)) { \
|
125
175
|
if(d < (1<<7)) { \
|
126
176
|
/* fixnum */ \
|
127
|
-
msgpack_pack_append_buffer(x, (
|
177
|
+
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
|
128
178
|
} else { \
|
129
179
|
/* unsigned 8 */ \
|
130
|
-
const unsigned char buf[2] = {0xcc, (
|
180
|
+
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
131
181
|
msgpack_pack_append_buffer(x, buf, 2); \
|
132
182
|
} \
|
133
183
|
} else { \
|
134
184
|
if(d < (1ULL<<16)) { \
|
135
185
|
/* signed 16 */ \
|
136
|
-
const unsigned char buf[3] = {0xcd,
|
186
|
+
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
137
187
|
msgpack_pack_append_buffer(x, buf, 3); \
|
138
188
|
} else if(d < (1ULL<<32)) { \
|
139
189
|
/* signed 32 */ \
|
140
|
-
const unsigned char buf[5] = {0xce,
|
190
|
+
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
141
191
|
msgpack_pack_append_buffer(x, buf, 5); \
|
142
192
|
} else { \
|
143
193
|
/* signed 64 */ \
|
144
|
-
const unsigned char buf[9] = {0xcf,
|
194
|
+
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
|
145
195
|
msgpack_pack_append_buffer(x, buf, 9); \
|
146
196
|
} \
|
147
197
|
} \
|
@@ -151,11 +201,11 @@ do { \
|
|
151
201
|
do { \
|
152
202
|
if(d < -(1<<5)) { \
|
153
203
|
/* signed 8 */ \
|
154
|
-
const unsigned char buf[2] = {0xd0, d}; \
|
204
|
+
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)}; \
|
155
205
|
msgpack_pack_append_buffer(x, buf, 2); \
|
156
206
|
} else { \
|
157
207
|
/* fixnum */ \
|
158
|
-
msgpack_pack_append_buffer(x, (
|
208
|
+
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1); \
|
159
209
|
} \
|
160
210
|
} while(0)
|
161
211
|
|
@@ -164,24 +214,24 @@ do { \
|
|
164
214
|
if(d < -(1<<5)) { \
|
165
215
|
if(d < -(1<<7)) { \
|
166
216
|
/* signed 16 */ \
|
167
|
-
const unsigned char buf[3] = {0xd1,
|
217
|
+
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)}; \
|
168
218
|
msgpack_pack_append_buffer(x, buf, 3); \
|
169
219
|
} else { \
|
170
220
|
/* signed 8 */ \
|
171
|
-
const unsigned char buf[2] = {0xd0, (
|
221
|
+
const unsigned char buf[2] = {0xd0, STORE16_BE8(d)}; \
|
172
222
|
msgpack_pack_append_buffer(x, buf, 2); \
|
173
223
|
} \
|
174
224
|
} else if(d < (1<<7)) { \
|
175
225
|
/* fixnum */ \
|
176
|
-
msgpack_pack_append_buffer(x, (
|
226
|
+
msgpack_pack_append_buffer(x, &STORE16_BE8(d), 1); \
|
177
227
|
} else { \
|
178
228
|
if(d < (1<<8)) { \
|
179
229
|
/* unsigned 8 */ \
|
180
|
-
const unsigned char buf[2] = {0xcc, (
|
230
|
+
const unsigned char buf[2] = {0xcc, STORE16_BE8(d)}; \
|
181
231
|
msgpack_pack_append_buffer(x, buf, 2); \
|
182
232
|
} else { \
|
183
233
|
/* unsigned 16 */ \
|
184
|
-
const unsigned char buf[3] = {0xcd,
|
234
|
+
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)}; \
|
185
235
|
msgpack_pack_append_buffer(x, buf, 3); \
|
186
236
|
} \
|
187
237
|
} \
|
@@ -192,32 +242,32 @@ do { \
|
|
192
242
|
if(d < -(1<<5)) { \
|
193
243
|
if(d < -(1<<15)) { \
|
194
244
|
/* signed 32 */ \
|
195
|
-
const unsigned char buf[5] = {0xd2,
|
245
|
+
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)}; \
|
196
246
|
msgpack_pack_append_buffer(x, buf, 5); \
|
197
247
|
} else if(d < -(1<<7)) { \
|
198
248
|
/* signed 16 */ \
|
199
|
-
const unsigned char buf[3] = {0xd1,
|
249
|
+
const unsigned char buf[3] = {0xd1, STORE32_BE16(d)}; \
|
200
250
|
msgpack_pack_append_buffer(x, buf, 3); \
|
201
251
|
} else { \
|
202
252
|
/* signed 8 */ \
|
203
|
-
const unsigned char buf[2] = {0xd0, (
|
253
|
+
const unsigned char buf[2] = {0xd0, STORE32_BE8(d)}; \
|
204
254
|
msgpack_pack_append_buffer(x, buf, 2); \
|
205
255
|
} \
|
206
256
|
} else if(d < (1<<7)) { \
|
207
257
|
/* fixnum */ \
|
208
|
-
msgpack_pack_append_buffer(x, (
|
258
|
+
msgpack_pack_append_buffer(x, &STORE32_BE8(d), 1); \
|
209
259
|
} else { \
|
210
260
|
if(d < (1<<8)) { \
|
211
261
|
/* unsigned 8 */ \
|
212
|
-
const unsigned char buf[2] = {0xcc, (
|
262
|
+
const unsigned char buf[2] = {0xcc, STORE32_BE8(d)}; \
|
213
263
|
msgpack_pack_append_buffer(x, buf, 2); \
|
214
264
|
} else if(d < (1<<16)) { \
|
215
265
|
/* unsigned 16 */ \
|
216
|
-
const unsigned char buf[3] = {0xcd,
|
266
|
+
const unsigned char buf[3] = {0xcd, STORE32_BE16(d)}; \
|
217
267
|
msgpack_pack_append_buffer(x, buf, 3); \
|
218
268
|
} else { \
|
219
269
|
/* unsigned 32 */ \
|
220
|
-
const unsigned char buf[5] = {0xce,
|
270
|
+
const unsigned char buf[5] = {0xce, STORE32_BE32(d)}; \
|
221
271
|
msgpack_pack_append_buffer(x, buf, 5); \
|
222
272
|
} \
|
223
273
|
} \
|
@@ -229,46 +279,46 @@ do { \
|
|
229
279
|
if(d < -(1LL<<15)) { \
|
230
280
|
if(d < -(1LL<<31)) { \
|
231
281
|
/* signed 64 */ \
|
232
|
-
const unsigned char buf[9] = {0xd3,
|
282
|
+
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)}; \
|
233
283
|
msgpack_pack_append_buffer(x, buf, 9); \
|
234
284
|
} else { \
|
235
285
|
/* signed 32 */ \
|
236
|
-
const unsigned char buf[5] = {0xd2,
|
286
|
+
const unsigned char buf[5] = {0xd2, STORE64_BE32(d)}; \
|
237
287
|
msgpack_pack_append_buffer(x, buf, 5); \
|
238
288
|
} \
|
239
289
|
} else { \
|
240
290
|
if(d < -(1<<7)) { \
|
241
291
|
/* signed 16 */ \
|
242
|
-
const unsigned char buf[3] = {0xd1,
|
292
|
+
const unsigned char buf[3] = {0xd1, STORE64_BE16(d)}; \
|
243
293
|
msgpack_pack_append_buffer(x, buf, 3); \
|
244
294
|
} else { \
|
245
295
|
/* signed 8 */ \
|
246
|
-
const unsigned char buf[2] = {0xd0, (
|
296
|
+
const unsigned char buf[2] = {0xd0, STORE64_BE8(d)}; \
|
247
297
|
msgpack_pack_append_buffer(x, buf, 2); \
|
248
298
|
} \
|
249
299
|
} \
|
250
300
|
} else if(d < (1<<7)) { \
|
251
301
|
/* fixnum */ \
|
252
|
-
msgpack_pack_append_buffer(x, (
|
302
|
+
msgpack_pack_append_buffer(x, &STORE64_BE8(d), 1); \
|
253
303
|
} else { \
|
254
304
|
if(d < (1LL<<16)) { \
|
255
305
|
if(d < (1<<8)) { \
|
256
306
|
/* unsigned 8 */ \
|
257
|
-
const unsigned char buf[2] = {0xcc, (
|
307
|
+
const unsigned char buf[2] = {0xcc, STORE64_BE8(d)}; \
|
258
308
|
msgpack_pack_append_buffer(x, buf, 2); \
|
259
309
|
} else { \
|
260
310
|
/* unsigned 16 */ \
|
261
|
-
const unsigned char buf[3] = {0xcd,
|
311
|
+
const unsigned char buf[3] = {0xcd, STORE64_BE16(d)}; \
|
262
312
|
msgpack_pack_append_buffer(x, buf, 3); \
|
263
313
|
} \
|
264
314
|
} else { \
|
265
315
|
if(d < (1LL<<32)) { \
|
266
316
|
/* unsigned 32 */ \
|
267
|
-
const unsigned char buf[5] = {0xce,
|
317
|
+
const unsigned char buf[5] = {0xce, STORE64_BE32(d)}; \
|
268
318
|
msgpack_pack_append_buffer(x, buf, 5); \
|
269
319
|
} else { \
|
270
320
|
/* unsigned 64 */ \
|
271
|
-
const unsigned char buf[9] = {0xcf,
|
321
|
+
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)}; \
|
272
322
|
msgpack_pack_append_buffer(x, buf, 9); \
|
273
323
|
} \
|
274
324
|
} \
|
@@ -280,49 +330,49 @@ do { \
|
|
280
330
|
|
281
331
|
msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
|
282
332
|
{
|
283
|
-
const unsigned char buf[2] = {0xcc, d};
|
333
|
+
const unsigned char buf[2] = {0xcc, STORE8_BE8(d)};
|
284
334
|
msgpack_pack_append_buffer(x, buf, 2);
|
285
335
|
}
|
286
336
|
|
287
337
|
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
|
288
338
|
{
|
289
|
-
const unsigned char buf[3] = {0xcd,
|
339
|
+
const unsigned char buf[3] = {0xcd, STORE16_BE16(d)};
|
290
340
|
msgpack_pack_append_buffer(x, buf, 3);
|
291
341
|
}
|
292
342
|
|
293
343
|
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
294
344
|
{
|
295
|
-
const unsigned char buf[5] = {0xce,
|
345
|
+
const unsigned char buf[5] = {0xce, STORE32_BE32(d)};
|
296
346
|
msgpack_pack_append_buffer(x, buf, 5);
|
297
347
|
}
|
298
348
|
|
299
349
|
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
300
350
|
{
|
301
|
-
const unsigned char buf[9] = {0xcf,
|
351
|
+
const unsigned char buf[9] = {0xcf, STORE64_BE64(d)};
|
302
352
|
msgpack_pack_append_buffer(x, buf, 9);
|
303
353
|
}
|
304
354
|
|
305
355
|
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
|
306
356
|
{
|
307
|
-
const unsigned char buf[2] = {0xd0, d};
|
357
|
+
const unsigned char buf[2] = {0xd0, STORE8_BE8(d)};
|
308
358
|
msgpack_pack_append_buffer(x, buf, 2);
|
309
359
|
}
|
310
360
|
|
311
361
|
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
|
312
362
|
{
|
313
|
-
const unsigned char buf[3] = {0xd1,
|
363
|
+
const unsigned char buf[3] = {0xd1, STORE16_BE16(d)};
|
314
364
|
msgpack_pack_append_buffer(x, buf, 3);
|
315
365
|
}
|
316
366
|
|
317
367
|
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
318
368
|
{
|
319
|
-
const unsigned char buf[5] = {0xd2,
|
369
|
+
const unsigned char buf[5] = {0xd2, STORE32_BE32(d)};
|
320
370
|
msgpack_pack_append_buffer(x, buf, 5);
|
321
371
|
}
|
322
372
|
|
323
373
|
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
324
374
|
{
|
325
|
-
const unsigned char buf[9] = {0xd3,
|
375
|
+
const unsigned char buf[9] = {0xd3, STORE64_BE64(d)};
|
326
376
|
msgpack_pack_append_buffer(x, buf, 9);
|
327
377
|
}
|
328
378
|
|
@@ -554,7 +604,7 @@ msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
|
554
604
|
{
|
555
605
|
union { char buf[4]; uint32_t num; } f;
|
556
606
|
*((float*)&f.buf) = d; // FIXME
|
557
|
-
const unsigned char buf[5] = {0xca,
|
607
|
+
const unsigned char buf[5] = {0xca, STORE32_BE32(f.num)};
|
558
608
|
msgpack_pack_append_buffer(x, buf, 5);
|
559
609
|
}
|
560
610
|
|
@@ -562,7 +612,7 @@ msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
|
|
562
612
|
{
|
563
613
|
union { char buf[8]; uint64_t num; } f;
|
564
614
|
*((double*)&f.buf) = d; // FIXME
|
565
|
-
const unsigned char buf[9] = {0xcb,
|
615
|
+
const unsigned char buf[9] = {0xcb, STORE64_BE64(f.num)};
|
566
616
|
msgpack_pack_append_buffer(x, buf, 9);
|
567
617
|
}
|
568
618
|
|
@@ -606,11 +656,11 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
|
606
656
|
msgpack_pack_append_buffer(x, &d, 1);
|
607
657
|
} else if(n < 65536) {
|
608
658
|
uint16_t d = (uint16_t)n;
|
609
|
-
unsigned char buf[3] = {0xdc,
|
659
|
+
unsigned char buf[3] = {0xdc, STORE16_BE16(d)};
|
610
660
|
msgpack_pack_append_buffer(x, buf, 3);
|
611
661
|
} else {
|
612
662
|
uint32_t d = (uint32_t)n;
|
613
|
-
unsigned char buf[5] = {0xdd,
|
663
|
+
unsigned char buf[5] = {0xdd, STORE32_BE32(d)};
|
614
664
|
msgpack_pack_append_buffer(x, buf, 5);
|
615
665
|
}
|
616
666
|
}
|
@@ -624,14 +674,14 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
|
|
624
674
|
{
|
625
675
|
if(n < 16) {
|
626
676
|
unsigned char d = 0x80 | n;
|
627
|
-
msgpack_pack_append_buffer(x, &d, 1);
|
677
|
+
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1);
|
628
678
|
} else if(n < 65536) {
|
629
679
|
uint16_t d = (uint16_t)n;
|
630
|
-
unsigned char buf[3] = {0xde,
|
680
|
+
unsigned char buf[3] = {0xde, STORE16_BE16(d)};
|
631
681
|
msgpack_pack_append_buffer(x, buf, 3);
|
632
682
|
} else {
|
633
683
|
uint32_t d = (uint32_t)n;
|
634
|
-
unsigned char buf[5] = {0xdf,
|
684
|
+
unsigned char buf[5] = {0xdf, STORE32_BE32(d)};
|
635
685
|
msgpack_pack_append_buffer(x, buf, 5);
|
636
686
|
}
|
637
687
|
}
|
@@ -645,14 +695,14 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
|
|
645
695
|
{
|
646
696
|
if(l < 32) {
|
647
697
|
unsigned char d = 0xa0 | l;
|
648
|
-
msgpack_pack_append_buffer(x, &d, 1);
|
698
|
+
msgpack_pack_append_buffer(x, &STORE8_BE8(d), 1);
|
649
699
|
} else if(l < 65536) {
|
650
700
|
uint16_t d = (uint16_t)l;
|
651
|
-
unsigned char buf[3] = {0xda,
|
701
|
+
unsigned char buf[3] = {0xda, STORE16_BE16(d)};
|
652
702
|
msgpack_pack_append_buffer(x, buf, 3);
|
653
703
|
} else {
|
654
704
|
uint32_t d = (uint32_t)l;
|
655
|
-
unsigned char buf[5] = {0xdb,
|
705
|
+
unsigned char buf[5] = {0xdb, STORE32_BE32(d)};
|
656
706
|
msgpack_pack_append_buffer(x, buf, 5);
|
657
707
|
}
|
658
708
|
}
|
@@ -666,9 +716,19 @@ msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l
|
|
666
716
|
#undef msgpack_pack_user
|
667
717
|
#undef msgpack_pack_append_buffer
|
668
718
|
|
669
|
-
#undef
|
670
|
-
|
671
|
-
#undef
|
719
|
+
#undef STORE8_BE8
|
720
|
+
|
721
|
+
#undef STORE16_BE8
|
722
|
+
#undef STORE16_BE16
|
723
|
+
|
724
|
+
#undef STORE32_BE8
|
725
|
+
#undef STORE32_BE16
|
726
|
+
#undef STORE32_BE32
|
727
|
+
|
728
|
+
#undef STORE64_BE8
|
729
|
+
#undef STORE64_BE16
|
730
|
+
#undef STORE64_BE32
|
731
|
+
#undef STORE64_BE64
|
672
732
|
|
673
733
|
#undef msgpack_pack_real_uint8
|
674
734
|
#undef msgpack_pack_real_uint16
|
data/test/msgpack_test.rb
CHANGED
@@ -113,6 +113,80 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
|
113
113
|
#check_array 5, (1<<32)-1 # memory error
|
114
114
|
end
|
115
115
|
|
116
|
+
it "nil" do
|
117
|
+
match nil, "\xc0"
|
118
|
+
end
|
119
|
+
|
120
|
+
it "false" do
|
121
|
+
match false, "\xc2"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "true" do
|
125
|
+
match true, "\xc3"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "0" do
|
129
|
+
match 0, "\x00"
|
130
|
+
end
|
131
|
+
|
132
|
+
it "127" do
|
133
|
+
match 127, "\x7f"
|
134
|
+
end
|
135
|
+
|
136
|
+
it "128" do
|
137
|
+
match 128, "\xcc\x80"
|
138
|
+
end
|
139
|
+
|
140
|
+
it "256" do
|
141
|
+
match 256, "\xcd\x01\x00"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "-1" do
|
145
|
+
match -1, "\xff"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "-33" do
|
149
|
+
match -33, "\xd0\xdf"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "-129" do
|
153
|
+
match -129, "\xd1\xff\x7f"
|
154
|
+
end
|
155
|
+
|
156
|
+
it "{1=>1}" do
|
157
|
+
match ({1=>1}), "\x81\x01\x01"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "1.0" do
|
161
|
+
match 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "[]" do
|
165
|
+
match [], "\x90"
|
166
|
+
end
|
167
|
+
|
168
|
+
it "[0, 1, ..., 14]" do
|
169
|
+
match (0..14).to_a, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e"
|
170
|
+
end
|
171
|
+
|
172
|
+
it "[0, 1, ..., 15]" do
|
173
|
+
match (0..15).to_a, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "{}" do
|
177
|
+
match ({}), "\x80"
|
178
|
+
end
|
179
|
+
|
180
|
+
it "{0=>0, 1=>1, ..., 14=>14}" do
|
181
|
+
a = (0..14).to_a;
|
182
|
+
match Hash[*a.zip(a).flatten], "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"
|
183
|
+
end
|
184
|
+
|
185
|
+
it "{0=>0, 1=>1, ..., 15=>15}" do
|
186
|
+
a = (0..15).to_a;
|
187
|
+
match Hash[*a.zip(a).flatten], "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"
|
188
|
+
end
|
189
|
+
|
116
190
|
# it "fixmap" do
|
117
191
|
# check_map 1, 0
|
118
192
|
# check_map 1, (1<<4)-1
|
@@ -143,8 +217,8 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
|
143
217
|
check num+overhead, Array.new(num)
|
144
218
|
end
|
145
219
|
|
146
|
-
def
|
147
|
-
|
220
|
+
def match(obj, buf)
|
221
|
+
assert_equal(obj.to_msgpack, buf)
|
148
222
|
end
|
149
223
|
end
|
150
224
|
|
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.3.
|
4
|
+
version: 0.3.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: 2009-03-
|
12
|
+
date: 2009-03-04 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|