msgpack 0.3.1 → 0.3.2
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.
- data/Rakefile +3 -3
- data/ext/unpack.c +12 -1
- data/msgpack/pack_define.h +1 -2
- data/msgpack/pack_template.h +99 -154
- data/msgpack/sysdep.h +94 -0
- data/msgpack/unpack_define.h +1 -38
- data/msgpack/unpack_template.h +29 -12
- data/test/msgpack_test.rb +1 -0
- metadata +8 -5
data/Rakefile
CHANGED
@@ -15,9 +15,9 @@ AUTHOR = "FURUHASHI Sadayuki"
|
|
15
15
|
EMAIL = "frsyuki _at_ users.sourceforge.jp"
|
16
16
|
DESCRIPTION = "Binary-based efficient data interchange format."
|
17
17
|
RUBYFORGE_PROJECT = "msgpack"
|
18
|
-
HOMEPATH = "http
|
18
|
+
HOMEPATH = "http://msgpack.sourceforge.jp/"
|
19
19
|
BIN_FILES = %w( )
|
20
|
-
VERS = "0.3.
|
20
|
+
VERS = "0.3.2"
|
21
21
|
|
22
22
|
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
23
|
REV = nil
|
@@ -44,7 +44,7 @@ spec = Gem::Specification.new do |s|
|
|
44
44
|
s.name = NAME
|
45
45
|
s.version = VERS
|
46
46
|
s.platform = Gem::Platform::RUBY
|
47
|
-
s.has_rdoc =
|
47
|
+
s.has_rdoc = false
|
48
48
|
s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
|
49
49
|
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
50
50
|
s.summary = DESCRIPTION
|
data/ext/unpack.c
CHANGED
@@ -127,6 +127,15 @@ static inline int template_callback_raw(unpack_user* u, const char* b, const cha
|
|
127
127
|
static VALUE cUnpacker;
|
128
128
|
static VALUE eUnpackError;
|
129
129
|
|
130
|
+
// FIXME slow operation
|
131
|
+
static void init_stack(msgpack_unpack_t* mp)
|
132
|
+
{
|
133
|
+
size_t i;
|
134
|
+
for(i=0; i < MSGPACK_MAX_STACK_SIZE; ++i) {
|
135
|
+
mp->stack[i].map_key = Qnil; /* GC */
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
130
139
|
static void MessagePack_Unpacker_free(void* data)
|
131
140
|
{
|
132
141
|
if(data) { free(data); }
|
@@ -137,7 +146,7 @@ static void MessagePack_Unpacker_mark(msgpack_unpack_t *mp)
|
|
137
146
|
unsigned int i;
|
138
147
|
for(i=0; i < mp->top; ++i) {
|
139
148
|
rb_gc_mark(mp->stack[i].obj);
|
140
|
-
rb_gc_mark(mp->stack[i].map_key);
|
149
|
+
rb_gc_mark(mp->stack[i].map_key); /* maybe map_key is not initialized */
|
141
150
|
}
|
142
151
|
}
|
143
152
|
|
@@ -154,6 +163,7 @@ static VALUE MessagePack_Unpacker_reset(VALUE self)
|
|
154
163
|
{
|
155
164
|
UNPACKER(self, mp);
|
156
165
|
template_init(mp);
|
166
|
+
init_stack(mp);
|
157
167
|
unpack_user u = {0, Qnil};
|
158
168
|
mp->user = u;
|
159
169
|
return self;
|
@@ -281,6 +291,7 @@ static VALUE MessagePack_unpack_limit(VALUE self, VALUE data, VALUE limit)
|
|
281
291
|
|
282
292
|
msgpack_unpack_t mp;
|
283
293
|
template_init(&mp);
|
294
|
+
init_stack(&mp);
|
284
295
|
unpack_user u = {0, Qnil};
|
285
296
|
mp.user = u;
|
286
297
|
|
data/msgpack/pack_define.h
CHANGED
data/msgpack/pack_template.h
CHANGED
@@ -16,88 +16,16 @@
|
|
16
16
|
* limitations under the License.
|
17
17
|
*/
|
18
18
|
|
19
|
-
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
20
|
-
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
21
|
-
#define __LITTLE_ENDIAN__
|
22
|
-
#elif __BYTE_ORDER == __BIG_ENDIAN
|
23
|
-
#define __BIG_ENDIAN__
|
24
|
-
#endif
|
25
|
-
#endif
|
26
|
-
|
27
|
-
|
28
19
|
#ifdef __LITTLE_ENDIAN__
|
29
|
-
|
30
|
-
#define
|
31
|
-
|
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]
|
46
|
-
|
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]
|
63
|
-
|
64
|
-
|
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]
|
65
24
|
#elif __BIG_ENDIAN__
|
66
|
-
|
67
|
-
#define
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
#define STORE16_BE8(d) \
|
72
|
-
((uint8_t*)&d)[1]
|
73
|
-
|
74
|
-
#define STORE16_BE16(d) \
|
75
|
-
((uint8_t*)&d)[0], ((uint8_t*)&d)[1]
|
76
|
-
|
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]
|
100
|
-
|
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]
|
101
29
|
#endif
|
102
30
|
|
103
31
|
#ifndef msgpack_pack_inline_func
|
@@ -121,10 +49,10 @@
|
|
121
49
|
do { \
|
122
50
|
if(d < (1<<7)) { \
|
123
51
|
/* fixnum */ \
|
124
|
-
msgpack_pack_append_buffer(x, &
|
52
|
+
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
125
53
|
} else { \
|
126
54
|
/* unsigned 8 */ \
|
127
|
-
|
55
|
+
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
|
128
56
|
msgpack_pack_append_buffer(x, buf, 2); \
|
129
57
|
} \
|
130
58
|
} while(0)
|
@@ -133,14 +61,15 @@ do { \
|
|
133
61
|
do { \
|
134
62
|
if(d < (1<<7)) { \
|
135
63
|
/* fixnum */ \
|
136
|
-
msgpack_pack_append_buffer(x, &
|
64
|
+
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
137
65
|
} else if(d < (1<<8)) { \
|
138
66
|
/* unsigned 8 */ \
|
139
|
-
|
67
|
+
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
140
68
|
msgpack_pack_append_buffer(x, buf, 2); \
|
141
69
|
} else { \
|
142
70
|
/* unsigned 16 */ \
|
143
|
-
|
71
|
+
unsigned char buf[3]; \
|
72
|
+
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
144
73
|
msgpack_pack_append_buffer(x, buf, 3); \
|
145
74
|
} \
|
146
75
|
} while(0)
|
@@ -150,20 +79,22 @@ do { \
|
|
150
79
|
if(d < (1<<8)) { \
|
151
80
|
if(d < (1<<7)) { \
|
152
81
|
/* fixnum */ \
|
153
|
-
msgpack_pack_append_buffer(x, &
|
82
|
+
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
154
83
|
} else { \
|
155
84
|
/* unsigned 8 */ \
|
156
|
-
|
85
|
+
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
157
86
|
msgpack_pack_append_buffer(x, buf, 2); \
|
158
87
|
} \
|
159
88
|
} else { \
|
160
89
|
if(d < (1<<16)) { \
|
161
90
|
/* unsigned 16 */ \
|
162
|
-
|
91
|
+
unsigned char buf[3]; \
|
92
|
+
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
163
93
|
msgpack_pack_append_buffer(x, buf, 3); \
|
164
94
|
} else { \
|
165
95
|
/* unsigned 32 */ \
|
166
|
-
|
96
|
+
unsigned char buf[5]; \
|
97
|
+
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
167
98
|
msgpack_pack_append_buffer(x, buf, 5); \
|
168
99
|
} \
|
169
100
|
} \
|
@@ -174,24 +105,27 @@ do { \
|
|
174
105
|
if(d < (1ULL<<8)) { \
|
175
106
|
if(d < (1<<7)) { \
|
176
107
|
/* fixnum */ \
|
177
|
-
msgpack_pack_append_buffer(x, &
|
108
|
+
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
178
109
|
} else { \
|
179
110
|
/* unsigned 8 */ \
|
180
|
-
|
111
|
+
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
181
112
|
msgpack_pack_append_buffer(x, buf, 2); \
|
182
113
|
} \
|
183
114
|
} else { \
|
184
115
|
if(d < (1ULL<<16)) { \
|
185
116
|
/* signed 16 */ \
|
186
|
-
|
117
|
+
unsigned char buf[3]; \
|
118
|
+
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
187
119
|
msgpack_pack_append_buffer(x, buf, 3); \
|
188
120
|
} else if(d < (1ULL<<32)) { \
|
189
121
|
/* signed 32 */ \
|
190
|
-
|
122
|
+
unsigned char buf[5]; \
|
123
|
+
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
191
124
|
msgpack_pack_append_buffer(x, buf, 5); \
|
192
125
|
} else { \
|
193
126
|
/* signed 64 */ \
|
194
|
-
|
127
|
+
unsigned char buf[9]; \
|
128
|
+
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); \
|
195
129
|
msgpack_pack_append_buffer(x, buf, 9); \
|
196
130
|
} \
|
197
131
|
} \
|
@@ -201,11 +135,11 @@ do { \
|
|
201
135
|
do { \
|
202
136
|
if(d < -(1<<5)) { \
|
203
137
|
/* signed 8 */ \
|
204
|
-
|
138
|
+
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
|
205
139
|
msgpack_pack_append_buffer(x, buf, 2); \
|
206
140
|
} else { \
|
207
141
|
/* fixnum */ \
|
208
|
-
msgpack_pack_append_buffer(x, &
|
142
|
+
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
|
209
143
|
} \
|
210
144
|
} while(0)
|
211
145
|
|
@@ -214,24 +148,26 @@ do { \
|
|
214
148
|
if(d < -(1<<5)) { \
|
215
149
|
if(d < -(1<<7)) { \
|
216
150
|
/* signed 16 */ \
|
217
|
-
|
151
|
+
unsigned char buf[3]; \
|
152
|
+
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
218
153
|
msgpack_pack_append_buffer(x, buf, 3); \
|
219
154
|
} else { \
|
220
155
|
/* signed 8 */ \
|
221
|
-
|
156
|
+
unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
|
222
157
|
msgpack_pack_append_buffer(x, buf, 2); \
|
223
158
|
} \
|
224
159
|
} else if(d < (1<<7)) { \
|
225
160
|
/* fixnum */ \
|
226
|
-
msgpack_pack_append_buffer(x, &
|
161
|
+
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
|
227
162
|
} else { \
|
228
163
|
if(d < (1<<8)) { \
|
229
164
|
/* unsigned 8 */ \
|
230
|
-
|
165
|
+
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
|
231
166
|
msgpack_pack_append_buffer(x, buf, 2); \
|
232
167
|
} else { \
|
233
168
|
/* unsigned 16 */ \
|
234
|
-
|
169
|
+
unsigned char buf[3]; \
|
170
|
+
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
235
171
|
msgpack_pack_append_buffer(x, buf, 3); \
|
236
172
|
} \
|
237
173
|
} \
|
@@ -242,32 +178,36 @@ do { \
|
|
242
178
|
if(d < -(1<<5)) { \
|
243
179
|
if(d < -(1<<15)) { \
|
244
180
|
/* signed 32 */ \
|
245
|
-
|
181
|
+
unsigned char buf[5]; \
|
182
|
+
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
246
183
|
msgpack_pack_append_buffer(x, buf, 5); \
|
247
184
|
} else if(d < -(1<<7)) { \
|
248
185
|
/* signed 16 */ \
|
249
|
-
|
186
|
+
unsigned char buf[3]; \
|
187
|
+
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
250
188
|
msgpack_pack_append_buffer(x, buf, 3); \
|
251
189
|
} else { \
|
252
190
|
/* signed 8 */ \
|
253
|
-
|
191
|
+
unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
|
254
192
|
msgpack_pack_append_buffer(x, buf, 2); \
|
255
193
|
} \
|
256
194
|
} else if(d < (1<<7)) { \
|
257
195
|
/* fixnum */ \
|
258
|
-
msgpack_pack_append_buffer(x, &
|
196
|
+
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
|
259
197
|
} else { \
|
260
198
|
if(d < (1<<8)) { \
|
261
199
|
/* unsigned 8 */ \
|
262
|
-
|
200
|
+
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
|
263
201
|
msgpack_pack_append_buffer(x, buf, 2); \
|
264
202
|
} else if(d < (1<<16)) { \
|
265
203
|
/* unsigned 16 */ \
|
266
|
-
|
204
|
+
unsigned char buf[3]; \
|
205
|
+
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
267
206
|
msgpack_pack_append_buffer(x, buf, 3); \
|
268
207
|
} else { \
|
269
208
|
/* unsigned 32 */ \
|
270
|
-
|
209
|
+
unsigned char buf[5]; \
|
210
|
+
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
271
211
|
msgpack_pack_append_buffer(x, buf, 5); \
|
272
212
|
} \
|
273
213
|
} \
|
@@ -279,46 +219,52 @@ do { \
|
|
279
219
|
if(d < -(1LL<<15)) { \
|
280
220
|
if(d < -(1LL<<31)) { \
|
281
221
|
/* signed 64 */ \
|
282
|
-
|
222
|
+
unsigned char buf[9]; \
|
223
|
+
buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_be64(d); \
|
283
224
|
msgpack_pack_append_buffer(x, buf, 9); \
|
284
225
|
} else { \
|
285
226
|
/* signed 32 */ \
|
286
|
-
|
227
|
+
unsigned char buf[5]; \
|
228
|
+
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
287
229
|
msgpack_pack_append_buffer(x, buf, 5); \
|
288
230
|
} \
|
289
231
|
} else { \
|
290
232
|
if(d < -(1<<7)) { \
|
291
233
|
/* signed 16 */ \
|
292
|
-
|
234
|
+
unsigned char buf[3]; \
|
235
|
+
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
293
236
|
msgpack_pack_append_buffer(x, buf, 3); \
|
294
237
|
} else { \
|
295
238
|
/* signed 8 */ \
|
296
|
-
|
239
|
+
unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
|
297
240
|
msgpack_pack_append_buffer(x, buf, 2); \
|
298
241
|
} \
|
299
242
|
} \
|
300
243
|
} else if(d < (1<<7)) { \
|
301
244
|
/* fixnum */ \
|
302
|
-
msgpack_pack_append_buffer(x, &
|
245
|
+
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
|
303
246
|
} else { \
|
304
247
|
if(d < (1LL<<16)) { \
|
305
248
|
if(d < (1<<8)) { \
|
306
249
|
/* unsigned 8 */ \
|
307
|
-
|
250
|
+
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
|
308
251
|
msgpack_pack_append_buffer(x, buf, 2); \
|
309
252
|
} else { \
|
310
253
|
/* unsigned 16 */ \
|
311
|
-
|
254
|
+
unsigned char buf[3]; \
|
255
|
+
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d); \
|
312
256
|
msgpack_pack_append_buffer(x, buf, 3); \
|
313
257
|
} \
|
314
258
|
} else { \
|
315
259
|
if(d < (1LL<<32)) { \
|
316
260
|
/* unsigned 32 */ \
|
317
|
-
|
261
|
+
unsigned char buf[5]; \
|
262
|
+
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d); \
|
318
263
|
msgpack_pack_append_buffer(x, buf, 5); \
|
319
264
|
} else { \
|
320
265
|
/* unsigned 64 */ \
|
321
|
-
|
266
|
+
unsigned char buf[9]; \
|
267
|
+
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d); \
|
322
268
|
msgpack_pack_append_buffer(x, buf, 9); \
|
323
269
|
} \
|
324
270
|
} \
|
@@ -330,49 +276,55 @@ do { \
|
|
330
276
|
|
331
277
|
msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
|
332
278
|
{
|
333
|
-
|
279
|
+
unsigned char buf[2] = {0xcc, TAKE8_8(d)};
|
334
280
|
msgpack_pack_append_buffer(x, buf, 2);
|
335
281
|
}
|
336
282
|
|
337
283
|
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
|
338
284
|
{
|
339
|
-
|
285
|
+
unsigned char buf[3];
|
286
|
+
buf[0] = 0xcd; *(uint16_t*)&buf[1] = _msgpack_be16(d);
|
340
287
|
msgpack_pack_append_buffer(x, buf, 3);
|
341
288
|
}
|
342
289
|
|
343
290
|
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
344
291
|
{
|
345
|
-
|
292
|
+
unsigned char buf[5];
|
293
|
+
buf[0] = 0xce; *(uint32_t*)&buf[1] = _msgpack_be32(d);
|
346
294
|
msgpack_pack_append_buffer(x, buf, 5);
|
347
295
|
}
|
348
296
|
|
349
297
|
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
350
298
|
{
|
351
|
-
|
299
|
+
unsigned char buf[9];
|
300
|
+
buf[0] = 0xcf; *(uint64_t*)&buf[1] = _msgpack_be64(d);
|
352
301
|
msgpack_pack_append_buffer(x, buf, 9);
|
353
302
|
}
|
354
303
|
|
355
304
|
msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
|
356
305
|
{
|
357
|
-
|
306
|
+
unsigned char buf[2] = {0xd0, TAKE8_8(d)};
|
358
307
|
msgpack_pack_append_buffer(x, buf, 2);
|
359
308
|
}
|
360
309
|
|
361
310
|
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
|
362
311
|
{
|
363
|
-
|
312
|
+
unsigned char buf[3];
|
313
|
+
buf[0] = 0xd1; *(uint16_t*)&buf[1] = _msgpack_be16(d);
|
364
314
|
msgpack_pack_append_buffer(x, buf, 3);
|
365
315
|
}
|
366
316
|
|
367
317
|
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
368
318
|
{
|
369
|
-
|
319
|
+
unsigned char buf[5];
|
320
|
+
buf[0] = 0xd2; *(uint32_t*)&buf[1] = _msgpack_be32(d);
|
370
321
|
msgpack_pack_append_buffer(x, buf, 5);
|
371
322
|
}
|
372
323
|
|
373
324
|
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
374
325
|
{
|
375
|
-
|
326
|
+
unsigned char buf[9];
|
327
|
+
buf[0] = 0xd3; *(uint64_t*)&buf[1] = _msgpack_be64(d);
|
376
328
|
msgpack_pack_append_buffer(x, buf, 9);
|
377
329
|
}
|
378
330
|
|
@@ -604,7 +556,8 @@ msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
|
604
556
|
{
|
605
557
|
union { char buf[4]; uint32_t num; } f;
|
606
558
|
*((float*)&f.buf) = d; // FIXME
|
607
|
-
|
559
|
+
unsigned char buf[5];
|
560
|
+
buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_be32(f.num);
|
608
561
|
msgpack_pack_append_buffer(x, buf, 5);
|
609
562
|
}
|
610
563
|
|
@@ -612,7 +565,8 @@ msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
|
|
612
565
|
{
|
613
566
|
union { char buf[8]; uint64_t num; } f;
|
614
567
|
*((double*)&f.buf) = d; // FIXME
|
615
|
-
|
568
|
+
unsigned char buf[9];
|
569
|
+
buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_be64(f.num);
|
616
570
|
msgpack_pack_append_buffer(x, buf, 9);
|
617
571
|
}
|
618
572
|
|
@@ -655,12 +609,12 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
|
655
609
|
unsigned char d = 0x90 | n;
|
656
610
|
msgpack_pack_append_buffer(x, &d, 1);
|
657
611
|
} else if(n < 65536) {
|
658
|
-
|
659
|
-
|
612
|
+
unsigned char buf[3];
|
613
|
+
buf[0] = 0xdc; *(uint16_t*)&buf[1] = _msgpack_be16(n);
|
660
614
|
msgpack_pack_append_buffer(x, buf, 3);
|
661
615
|
} else {
|
662
|
-
|
663
|
-
|
616
|
+
unsigned char buf[5];
|
617
|
+
buf[0] = 0xdd; *(uint32_t*)&buf[1] = _msgpack_be32(n);
|
664
618
|
msgpack_pack_append_buffer(x, buf, 5);
|
665
619
|
}
|
666
620
|
}
|
@@ -674,14 +628,14 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
|
|
674
628
|
{
|
675
629
|
if(n < 16) {
|
676
630
|
unsigned char d = 0x80 | n;
|
677
|
-
msgpack_pack_append_buffer(x, &
|
631
|
+
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
678
632
|
} else if(n < 65536) {
|
679
|
-
|
680
|
-
|
633
|
+
unsigned char buf[3];
|
634
|
+
buf[0] = 0xde; *(uint16_t*)&buf[1] = _msgpack_be16(n);
|
681
635
|
msgpack_pack_append_buffer(x, buf, 3);
|
682
636
|
} else {
|
683
|
-
|
684
|
-
|
637
|
+
unsigned char buf[5];
|
638
|
+
buf[0] = 0xdf; *(uint32_t*)&buf[1] = _msgpack_be32(n);
|
685
639
|
msgpack_pack_append_buffer(x, buf, 5);
|
686
640
|
}
|
687
641
|
}
|
@@ -695,14 +649,14 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
|
|
695
649
|
{
|
696
650
|
if(l < 32) {
|
697
651
|
unsigned char d = 0xa0 | l;
|
698
|
-
msgpack_pack_append_buffer(x, &
|
652
|
+
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
699
653
|
} else if(l < 65536) {
|
700
|
-
|
701
|
-
|
654
|
+
unsigned char buf[3];
|
655
|
+
buf[0] = 0xda; *(uint16_t*)&buf[1] = _msgpack_be16(l);
|
702
656
|
msgpack_pack_append_buffer(x, buf, 3);
|
703
657
|
} else {
|
704
|
-
|
705
|
-
|
658
|
+
unsigned char buf[5];
|
659
|
+
buf[0] = 0xdb; *(uint32_t*)&buf[1] = _msgpack_be32(l);
|
706
660
|
msgpack_pack_append_buffer(x, buf, 5);
|
707
661
|
}
|
708
662
|
}
|
@@ -716,19 +670,10 @@ msgpack_pack_inline_func(_raw_body)(msgpack_pack_user x, const void* b, size_t l
|
|
716
670
|
#undef msgpack_pack_user
|
717
671
|
#undef msgpack_pack_append_buffer
|
718
672
|
|
719
|
-
#undef
|
720
|
-
|
721
|
-
#undef
|
722
|
-
#undef
|
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
|
673
|
+
#undef TAKE8_8
|
674
|
+
#undef TAKE8_16
|
675
|
+
#undef TAKE8_32
|
676
|
+
#undef TAKE8_64
|
732
677
|
|
733
678
|
#undef msgpack_pack_real_uint8
|
734
679
|
#undef msgpack_pack_real_uint16
|
data/msgpack/sysdep.h
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
/*
|
2
|
+
* MessagePack system dependencies
|
3
|
+
*
|
4
|
+
* Copyright (C) 2008-2009 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_SYSDEP_H__
|
19
|
+
#define MSGPACK_SYSDEP_H__
|
20
|
+
|
21
|
+
|
22
|
+
#ifdef _MSC_VER
|
23
|
+
typedef __int8 int8_t;
|
24
|
+
typedef unsigned __int8 uint8_t;
|
25
|
+
typedef __int16 int16_t;
|
26
|
+
typedef unsigned __int16 uint16_t;
|
27
|
+
typedef __int32 int32_t;
|
28
|
+
typedef unsigned __int32 uint32_t;
|
29
|
+
typedef __int64 int64_t;
|
30
|
+
typedef unsigned __int64 uint64_t;
|
31
|
+
#else
|
32
|
+
#include <stddef.h>
|
33
|
+
#include <stdint.h>
|
34
|
+
#include <stdbool.h>
|
35
|
+
#endif
|
36
|
+
|
37
|
+
|
38
|
+
#ifdef _WIN32
|
39
|
+
typedef long _msgpack_atomic_counter_t;
|
40
|
+
#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
|
41
|
+
#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
|
42
|
+
#else
|
43
|
+
typedef unsigned int _msgpack_atomic_counter_t;
|
44
|
+
#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
|
45
|
+
#define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1)
|
46
|
+
#endif
|
47
|
+
|
48
|
+
|
49
|
+
#ifdef _WIN32
|
50
|
+
#include <winsock2.h>
|
51
|
+
#else
|
52
|
+
#include <arpa/inet.h> /* __BYTE_ORDER */
|
53
|
+
#endif
|
54
|
+
|
55
|
+
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
56
|
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
57
|
+
#define __LITTLE_ENDIAN__
|
58
|
+
#elif __BYTE_ORDER == __BIG_ENDIAN
|
59
|
+
#define __BIG_ENDIAN__
|
60
|
+
#endif
|
61
|
+
#endif
|
62
|
+
|
63
|
+
#ifdef __LITTLE_ENDIAN__
|
64
|
+
|
65
|
+
#define _msgpack_be16(x) ntohs(x)
|
66
|
+
#define _msgpack_be32(x) ntohl(x)
|
67
|
+
|
68
|
+
#if defined(_byteswap_uint64)
|
69
|
+
# define _msgpack_be64(x) (_byteswap_uint64(x))
|
70
|
+
#elif defined(bswap_64)
|
71
|
+
# define _msgpack_be64(x) bswap_64(x)
|
72
|
+
#elif defined(__DARWIN_OSSwapInt64)
|
73
|
+
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
|
74
|
+
#else
|
75
|
+
#define _msgpack_be64(x) \
|
76
|
+
( ((((uint64_t)x) << 56) & 0xff00000000000000ULL ) | \
|
77
|
+
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
|
78
|
+
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
|
79
|
+
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
|
80
|
+
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
|
81
|
+
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
82
|
+
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
|
83
|
+
((((uint64_t)x) >> 56) & 0x00000000000000ffULL ) )
|
84
|
+
#endif
|
85
|
+
|
86
|
+
#else
|
87
|
+
#define _msgpack_be16(x) (x)
|
88
|
+
#define _msgpack_be32(x) (x)
|
89
|
+
#define _msgpack_be64(x) (x)
|
90
|
+
#endif
|
91
|
+
|
92
|
+
|
93
|
+
#endif /* msgpack/sysdep.h */
|
94
|
+
|
data/msgpack/unpack_define.h
CHANGED
@@ -18,14 +18,10 @@
|
|
18
18
|
#ifndef MSGPACK_UNPACK_DEFINE_H__
|
19
19
|
#define MSGPACK_UNPACK_DEFINE_H__
|
20
20
|
|
21
|
-
#include
|
22
|
-
#include <stdint.h>
|
21
|
+
#include "msgpack/sysdep.h"
|
23
22
|
#include <string.h>
|
24
23
|
#include <assert.h>
|
25
24
|
#include <stdio.h>
|
26
|
-
#ifndef __WIN32__
|
27
|
-
#include <arpa/inet.h>
|
28
|
-
#endif
|
29
25
|
|
30
26
|
#ifdef __cplusplus
|
31
27
|
extern "C" {
|
@@ -37,39 +33,6 @@ extern "C" {
|
|
37
33
|
#endif
|
38
34
|
|
39
35
|
|
40
|
-
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
41
|
-
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
42
|
-
#define __LITTLE_ENDIAN__
|
43
|
-
#elif __BYTE_ORDER == __BIG_ENDIAN
|
44
|
-
#define __BIG_ENDIAN__
|
45
|
-
#endif
|
46
|
-
#endif
|
47
|
-
|
48
|
-
#define msgpack_betoh16(x) ntohs(x)
|
49
|
-
#define msgpack_betoh32(x) ntohl(x)
|
50
|
-
|
51
|
-
#ifdef __LITTLE_ENDIAN__
|
52
|
-
#if defined(__bswap_64)
|
53
|
-
# define msgpack_betoh64(x) __bswap_64(x)
|
54
|
-
#elif defined(__DARWIN_OSSwapInt64)
|
55
|
-
# define msgpack_betoh64(x) __DARWIN_OSSwapInt64(x)
|
56
|
-
#else
|
57
|
-
static inline uint64_t msgpack_betoh64(uint64_t x) {
|
58
|
-
return ((x << 56) & 0xff00000000000000ULL ) |
|
59
|
-
((x << 40) & 0x00ff000000000000ULL ) |
|
60
|
-
((x << 24) & 0x0000ff0000000000ULL ) |
|
61
|
-
((x << 8) & 0x000000ff00000000ULL ) |
|
62
|
-
((x >> 8) & 0x00000000ff000000ULL ) |
|
63
|
-
((x >> 24) & 0x0000000000ff0000ULL ) |
|
64
|
-
((x >> 40) & 0x000000000000ff00ULL ) |
|
65
|
-
((x >> 56) & 0x00000000000000ffULL ) ;
|
66
|
-
}
|
67
|
-
#endif
|
68
|
-
#else
|
69
|
-
#define msgpack_betoh64(x) (x)
|
70
|
-
#endif
|
71
|
-
|
72
|
-
|
73
36
|
typedef enum {
|
74
37
|
CS_HEADER = 0x00, // nil
|
75
38
|
|
data/msgpack/unpack_template.h
CHANGED
@@ -40,6 +40,11 @@
|
|
40
40
|
#error msgpack_unpack_user type is not defined
|
41
41
|
#endif
|
42
42
|
|
43
|
+
#ifndef USE_CASE_RANGE
|
44
|
+
#if !defined(_MSC_VER)
|
45
|
+
#define USE_CASE_RANGE
|
46
|
+
#endif
|
47
|
+
#endif
|
43
48
|
|
44
49
|
msgpack_unpack_struct_decl(_stack) {
|
45
50
|
msgpack_unpack_object obj;
|
@@ -126,20 +131,32 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
|
126
131
|
((unsigned int)*p & 0x1f)
|
127
132
|
|
128
133
|
#define PTR_CAST_8(ptr) (*(uint8_t*)ptr)
|
129
|
-
#define PTR_CAST_16(ptr)
|
130
|
-
#define PTR_CAST_32(ptr)
|
131
|
-
#define PTR_CAST_64(ptr)
|
134
|
+
#define PTR_CAST_16(ptr) _msgpack_be16(*(uint16_t*)ptr)
|
135
|
+
#define PTR_CAST_32(ptr) _msgpack_be32(*(uint32_t*)ptr)
|
136
|
+
#define PTR_CAST_64(ptr) _msgpack_be64(*(uint64_t*)ptr)
|
137
|
+
|
138
|
+
#ifdef USE_CASE_RANGE
|
139
|
+
#define SWITCH_RANGE_BEGIN switch(*p) {
|
140
|
+
#define SWITCH_RANGE(FROM, TO) case FROM ... TO:
|
141
|
+
#define SWITCH_RANGE_DEFAULT default:
|
142
|
+
#define SWITCH_RANGE_END }
|
143
|
+
#else
|
144
|
+
#define SWITCH_RANGE_BEGIN { if(0) {
|
145
|
+
#define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) {
|
146
|
+
#define SWITCH_RANGE_DEFAULT } else {
|
147
|
+
#define SWITCH_RANGE_END } }
|
148
|
+
#endif
|
132
149
|
|
133
150
|
if(p == pe) { goto _out; }
|
134
151
|
do {
|
135
152
|
switch(cs) {
|
136
153
|
case CS_HEADER:
|
137
|
-
|
138
|
-
|
154
|
+
SWITCH_RANGE_BEGIN
|
155
|
+
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
|
139
156
|
push_fixed_value(_uint8, *(uint8_t*)p);
|
140
|
-
|
157
|
+
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
|
141
158
|
push_fixed_value(_int8, *(int8_t*)p);
|
142
|
-
|
159
|
+
SWITCH_RANGE(0xc0, 0xdf) // Variable
|
143
160
|
switch(*p) {
|
144
161
|
case 0xc0: // nil
|
145
162
|
push_simple_value(_nil);
|
@@ -182,16 +199,16 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
|
182
199
|
default:
|
183
200
|
goto _failed;
|
184
201
|
}
|
185
|
-
|
202
|
+
SWITCH_RANGE(0xa0, 0xbf) // FixRaw
|
186
203
|
again_fixed_trail_if_zero(ACS_RAW_VALUE, ((unsigned int)*p & 0x1f), _raw_zero);
|
187
|
-
|
204
|
+
SWITCH_RANGE(0x90, 0x9f) // FixArray
|
188
205
|
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
|
189
|
-
|
206
|
+
SWITCH_RANGE(0x80, 0x8f) // FixMap
|
190
207
|
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
|
191
208
|
|
192
|
-
|
209
|
+
SWITCH_RANGE_DEFAULT
|
193
210
|
goto _failed;
|
194
|
-
|
211
|
+
SWITCH_RANGE_END
|
195
212
|
// end CS_HEADER
|
196
213
|
|
197
214
|
|
data/test/msgpack_test.rb
CHANGED
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.2
|
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-
|
12
|
+
date: 2009-12-11 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -37,11 +37,14 @@ files:
|
|
37
37
|
- ext/extconf.rb
|
38
38
|
- msgpack/pack_define.h
|
39
39
|
- msgpack/pack_template.h
|
40
|
+
- msgpack/sysdep.h
|
40
41
|
- msgpack/unpack_define.h
|
41
42
|
- msgpack/unpack_template.h
|
42
43
|
- AUTHORS
|
43
44
|
has_rdoc: true
|
44
|
-
homepage: http://msgpack.
|
45
|
+
homepage: http://msgpack.sourceforge.jp/
|
46
|
+
licenses: []
|
47
|
+
|
45
48
|
post_install_message:
|
46
49
|
rdoc_options:
|
47
50
|
- --title
|
@@ -73,9 +76,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
76
|
requirements: []
|
74
77
|
|
75
78
|
rubyforge_project: msgpack
|
76
|
-
rubygems_version: 1.3.
|
79
|
+
rubygems_version: 1.3.5
|
77
80
|
signing_key:
|
78
|
-
specification_version:
|
81
|
+
specification_version: 3
|
79
82
|
summary: Binary-based efficient data interchange format.
|
80
83
|
test_files:
|
81
84
|
- test/test_helper.rb
|