msgpack 0.3.2 → 0.3.3
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/ext/unpack.c +120 -7
- data/msgpack/pack_define.h +2 -1
- data/msgpack/pack_template.h +37 -37
- data/msgpack/sysdep.h +25 -1
- data/msgpack/unpack_define.h +1 -1
- data/msgpack/unpack_template.h +25 -34
- metadata +16 -27
- data/Rakefile +0 -133
data/ext/unpack.c
CHANGED
@@ -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
|
-
|
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
|
-
|
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,
|
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
|
-
|
data/msgpack/pack_define.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* MessagePack unpacking routine template
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008-
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
@@ -20,6 +20,7 @@
|
|
20
20
|
|
21
21
|
#include "msgpack/sysdep.h"
|
22
22
|
#include <limits.h>
|
23
|
+
#include <string.h>
|
23
24
|
|
24
25
|
#endif /* msgpack/pack_define.h */
|
25
26
|
|
data/msgpack/pack_template.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* MessagePack packing routine template
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008-
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
@@ -69,7 +69,7 @@ do { \
|
|
69
69
|
} else { \
|
70
70
|
/* unsigned 16 */ \
|
71
71
|
unsigned char buf[3]; \
|
72
|
-
buf[0] = 0xcd;
|
72
|
+
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
|
73
73
|
msgpack_pack_append_buffer(x, buf, 3); \
|
74
74
|
} \
|
75
75
|
} while(0)
|
@@ -89,12 +89,12 @@ do { \
|
|
89
89
|
if(d < (1<<16)) { \
|
90
90
|
/* unsigned 16 */ \
|
91
91
|
unsigned char buf[3]; \
|
92
|
-
buf[0] = 0xcd;
|
92
|
+
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
|
93
93
|
msgpack_pack_append_buffer(x, buf, 3); \
|
94
94
|
} else { \
|
95
95
|
/* unsigned 32 */ \
|
96
96
|
unsigned char buf[5]; \
|
97
|
-
buf[0] = 0xce;
|
97
|
+
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
|
98
98
|
msgpack_pack_append_buffer(x, buf, 5); \
|
99
99
|
} \
|
100
100
|
} \
|
@@ -115,17 +115,17 @@ do { \
|
|
115
115
|
if(d < (1ULL<<16)) { \
|
116
116
|
/* signed 16 */ \
|
117
117
|
unsigned char buf[3]; \
|
118
|
-
buf[0] = 0xcd;
|
118
|
+
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
|
119
119
|
msgpack_pack_append_buffer(x, buf, 3); \
|
120
120
|
} else if(d < (1ULL<<32)) { \
|
121
121
|
/* signed 32 */ \
|
122
122
|
unsigned char buf[5]; \
|
123
|
-
buf[0] = 0xce;
|
123
|
+
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
|
124
124
|
msgpack_pack_append_buffer(x, buf, 5); \
|
125
125
|
} else { \
|
126
126
|
/* signed 64 */ \
|
127
127
|
unsigned char buf[9]; \
|
128
|
-
buf[0] = 0xcf;
|
128
|
+
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
129
129
|
msgpack_pack_append_buffer(x, buf, 9); \
|
130
130
|
} \
|
131
131
|
} \
|
@@ -149,7 +149,7 @@ do { \
|
|
149
149
|
if(d < -(1<<7)) { \
|
150
150
|
/* signed 16 */ \
|
151
151
|
unsigned char buf[3]; \
|
152
|
-
buf[0] = 0xd1;
|
152
|
+
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
|
153
153
|
msgpack_pack_append_buffer(x, buf, 3); \
|
154
154
|
} else { \
|
155
155
|
/* signed 8 */ \
|
@@ -167,7 +167,7 @@ do { \
|
|
167
167
|
} else { \
|
168
168
|
/* unsigned 16 */ \
|
169
169
|
unsigned char buf[3]; \
|
170
|
-
buf[0] = 0xcd;
|
170
|
+
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
|
171
171
|
msgpack_pack_append_buffer(x, buf, 3); \
|
172
172
|
} \
|
173
173
|
} \
|
@@ -179,12 +179,12 @@ do { \
|
|
179
179
|
if(d < -(1<<15)) { \
|
180
180
|
/* signed 32 */ \
|
181
181
|
unsigned char buf[5]; \
|
182
|
-
buf[0] = 0xd2;
|
182
|
+
buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
|
183
183
|
msgpack_pack_append_buffer(x, buf, 5); \
|
184
184
|
} else if(d < -(1<<7)) { \
|
185
185
|
/* signed 16 */ \
|
186
186
|
unsigned char buf[3]; \
|
187
|
-
buf[0] = 0xd1;
|
187
|
+
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
|
188
188
|
msgpack_pack_append_buffer(x, buf, 3); \
|
189
189
|
} else { \
|
190
190
|
/* signed 8 */ \
|
@@ -202,12 +202,12 @@ do { \
|
|
202
202
|
} else if(d < (1<<16)) { \
|
203
203
|
/* unsigned 16 */ \
|
204
204
|
unsigned char buf[3]; \
|
205
|
-
buf[0] = 0xcd;
|
205
|
+
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
|
206
206
|
msgpack_pack_append_buffer(x, buf, 3); \
|
207
207
|
} else { \
|
208
208
|
/* unsigned 32 */ \
|
209
209
|
unsigned char buf[5]; \
|
210
|
-
buf[0] = 0xce;
|
210
|
+
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
|
211
211
|
msgpack_pack_append_buffer(x, buf, 5); \
|
212
212
|
} \
|
213
213
|
} \
|
@@ -220,19 +220,19 @@ do { \
|
|
220
220
|
if(d < -(1LL<<31)) { \
|
221
221
|
/* signed 64 */ \
|
222
222
|
unsigned char buf[9]; \
|
223
|
-
buf[0] = 0xd3;
|
223
|
+
buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
|
224
224
|
msgpack_pack_append_buffer(x, buf, 9); \
|
225
225
|
} else { \
|
226
226
|
/* signed 32 */ \
|
227
227
|
unsigned char buf[5]; \
|
228
|
-
buf[0] = 0xd2;
|
228
|
+
buf[0] = 0xd2; _msgpack_store32(&buf[1], d); \
|
229
229
|
msgpack_pack_append_buffer(x, buf, 5); \
|
230
230
|
} \
|
231
231
|
} else { \
|
232
232
|
if(d < -(1<<7)) { \
|
233
233
|
/* signed 16 */ \
|
234
234
|
unsigned char buf[3]; \
|
235
|
-
buf[0] = 0xd1;
|
235
|
+
buf[0] = 0xd1; _msgpack_store16(&buf[1], d); \
|
236
236
|
msgpack_pack_append_buffer(x, buf, 3); \
|
237
237
|
} else { \
|
238
238
|
/* signed 8 */ \
|
@@ -252,19 +252,19 @@ do { \
|
|
252
252
|
} else { \
|
253
253
|
/* unsigned 16 */ \
|
254
254
|
unsigned char buf[3]; \
|
255
|
-
buf[0] = 0xcd;
|
255
|
+
buf[0] = 0xcd; _msgpack_store16(&buf[1], d); \
|
256
256
|
msgpack_pack_append_buffer(x, buf, 3); \
|
257
257
|
} \
|
258
258
|
} else { \
|
259
259
|
if(d < (1LL<<32)) { \
|
260
260
|
/* unsigned 32 */ \
|
261
261
|
unsigned char buf[5]; \
|
262
|
-
buf[0] = 0xce;
|
262
|
+
buf[0] = 0xce; _msgpack_store32(&buf[1], d); \
|
263
263
|
msgpack_pack_append_buffer(x, buf, 5); \
|
264
264
|
} else { \
|
265
265
|
/* unsigned 64 */ \
|
266
266
|
unsigned char buf[9]; \
|
267
|
-
buf[0] = 0xcf;
|
267
|
+
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
|
268
268
|
msgpack_pack_append_buffer(x, buf, 9); \
|
269
269
|
} \
|
270
270
|
} \
|
@@ -283,21 +283,21 @@ msgpack_pack_inline_func_fastint(_uint8)(msgpack_pack_user x, uint8_t d)
|
|
283
283
|
msgpack_pack_inline_func_fastint(_uint16)(msgpack_pack_user x, uint16_t d)
|
284
284
|
{
|
285
285
|
unsigned char buf[3];
|
286
|
-
buf[0] = 0xcd;
|
286
|
+
buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
|
287
287
|
msgpack_pack_append_buffer(x, buf, 3);
|
288
288
|
}
|
289
289
|
|
290
290
|
msgpack_pack_inline_func_fastint(_uint32)(msgpack_pack_user x, uint32_t d)
|
291
291
|
{
|
292
292
|
unsigned char buf[5];
|
293
|
-
buf[0] = 0xce;
|
293
|
+
buf[0] = 0xce; _msgpack_store32(&buf[1], d);
|
294
294
|
msgpack_pack_append_buffer(x, buf, 5);
|
295
295
|
}
|
296
296
|
|
297
297
|
msgpack_pack_inline_func_fastint(_uint64)(msgpack_pack_user x, uint64_t d)
|
298
298
|
{
|
299
299
|
unsigned char buf[9];
|
300
|
-
buf[0] = 0xcf;
|
300
|
+
buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
|
301
301
|
msgpack_pack_append_buffer(x, buf, 9);
|
302
302
|
}
|
303
303
|
|
@@ -310,21 +310,21 @@ msgpack_pack_inline_func_fastint(_int8)(msgpack_pack_user x, int8_t d)
|
|
310
310
|
msgpack_pack_inline_func_fastint(_int16)(msgpack_pack_user x, int16_t d)
|
311
311
|
{
|
312
312
|
unsigned char buf[3];
|
313
|
-
buf[0] = 0xd1;
|
313
|
+
buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
|
314
314
|
msgpack_pack_append_buffer(x, buf, 3);
|
315
315
|
}
|
316
316
|
|
317
317
|
msgpack_pack_inline_func_fastint(_int32)(msgpack_pack_user x, int32_t d)
|
318
318
|
{
|
319
319
|
unsigned char buf[5];
|
320
|
-
buf[0] = 0xd2;
|
320
|
+
buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
|
321
321
|
msgpack_pack_append_buffer(x, buf, 5);
|
322
322
|
}
|
323
323
|
|
324
324
|
msgpack_pack_inline_func_fastint(_int64)(msgpack_pack_user x, int64_t d)
|
325
325
|
{
|
326
326
|
unsigned char buf[9];
|
327
|
-
buf[0] = 0xd3;
|
327
|
+
buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
|
328
328
|
msgpack_pack_append_buffer(x, buf, 9);
|
329
329
|
}
|
330
330
|
|
@@ -554,19 +554,19 @@ if(sizeof(unsigned long long) == 2) {
|
|
554
554
|
|
555
555
|
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
556
556
|
{
|
557
|
-
union {
|
558
|
-
|
557
|
+
union { float f; uint32_t i; } mem;
|
558
|
+
mem.f = d;
|
559
559
|
unsigned char buf[5];
|
560
|
-
buf[0] = 0xca;
|
560
|
+
buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
|
561
561
|
msgpack_pack_append_buffer(x, buf, 5);
|
562
562
|
}
|
563
563
|
|
564
564
|
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
|
565
565
|
{
|
566
|
-
union {
|
567
|
-
|
566
|
+
union { double f; uint64_t i; } mem;
|
567
|
+
mem.f = d;
|
568
568
|
unsigned char buf[9];
|
569
|
-
buf[0] = 0xcb;
|
569
|
+
buf[0] = 0xcb; _msgpack_store64(&buf[1], mem.i);
|
570
570
|
msgpack_pack_append_buffer(x, buf, 9);
|
571
571
|
}
|
572
572
|
|
@@ -610,11 +610,11 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, unsigned int n)
|
|
610
610
|
msgpack_pack_append_buffer(x, &d, 1);
|
611
611
|
} else if(n < 65536) {
|
612
612
|
unsigned char buf[3];
|
613
|
-
buf[0] = 0xdc;
|
613
|
+
buf[0] = 0xdc; _msgpack_store16(&buf[1], n);
|
614
614
|
msgpack_pack_append_buffer(x, buf, 3);
|
615
615
|
} else {
|
616
616
|
unsigned char buf[5];
|
617
|
-
buf[0] = 0xdd;
|
617
|
+
buf[0] = 0xdd; _msgpack_store32(&buf[1], n);
|
618
618
|
msgpack_pack_append_buffer(x, buf, 5);
|
619
619
|
}
|
620
620
|
}
|
@@ -631,11 +631,11 @@ msgpack_pack_inline_func(_map)(msgpack_pack_user x, unsigned int n)
|
|
631
631
|
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
632
632
|
} else if(n < 65536) {
|
633
633
|
unsigned char buf[3];
|
634
|
-
buf[0] = 0xde;
|
634
|
+
buf[0] = 0xde; _msgpack_store16(&buf[1], n);
|
635
635
|
msgpack_pack_append_buffer(x, buf, 3);
|
636
636
|
} else {
|
637
637
|
unsigned char buf[5];
|
638
|
-
buf[0] = 0xdf;
|
638
|
+
buf[0] = 0xdf; _msgpack_store32(&buf[1], n);
|
639
639
|
msgpack_pack_append_buffer(x, buf, 5);
|
640
640
|
}
|
641
641
|
}
|
@@ -652,11 +652,11 @@ msgpack_pack_inline_func(_raw)(msgpack_pack_user x, size_t l)
|
|
652
652
|
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
|
653
653
|
} else if(l < 65536) {
|
654
654
|
unsigned char buf[3];
|
655
|
-
buf[0] = 0xda;
|
655
|
+
buf[0] = 0xda; _msgpack_store16(&buf[1], l);
|
656
656
|
msgpack_pack_append_buffer(x, buf, 3);
|
657
657
|
} else {
|
658
658
|
unsigned char buf[5];
|
659
|
-
buf[0] = 0xdb;
|
659
|
+
buf[0] = 0xdb; _msgpack_store32(&buf[1], l);
|
660
660
|
msgpack_pack_append_buffer(x, buf, 5);
|
661
661
|
}
|
662
662
|
}
|
data/msgpack/sysdep.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* MessagePack system dependencies
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008-
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
@@ -48,6 +48,17 @@ typedef unsigned int _msgpack_atomic_counter_t;
|
|
48
48
|
|
49
49
|
#ifdef _WIN32
|
50
50
|
#include <winsock2.h>
|
51
|
+
|
52
|
+
#ifdef __cplusplus
|
53
|
+
/* numeric_limits<T>::min,max */
|
54
|
+
#ifdef max
|
55
|
+
#undef max
|
56
|
+
#endif
|
57
|
+
#ifdef min
|
58
|
+
#undef min
|
59
|
+
#endif
|
60
|
+
#endif
|
61
|
+
|
51
62
|
#else
|
52
63
|
#include <arpa/inet.h> /* __BYTE_ORDER */
|
53
64
|
#endif
|
@@ -90,5 +101,18 @@ typedef unsigned int _msgpack_atomic_counter_t;
|
|
90
101
|
#endif
|
91
102
|
|
92
103
|
|
104
|
+
#define _msgpack_store16(to, num) \
|
105
|
+
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0);
|
106
|
+
#define _msgpack_store32(to, num) \
|
107
|
+
do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0);
|
108
|
+
#define _msgpack_store64(to, num) \
|
109
|
+
do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0);
|
110
|
+
|
111
|
+
|
112
|
+
#define _msgpack_load16(cast, from) ((cast)_msgpack_be16(*(uint16_t*)from))
|
113
|
+
#define _msgpack_load32(cast, from) ((cast)_msgpack_be32(*(uint32_t*)from))
|
114
|
+
#define _msgpack_load64(cast, from) ((cast)_msgpack_be64(*(uint64_t*)from))
|
115
|
+
|
116
|
+
|
93
117
|
#endif /* msgpack/sysdep.h */
|
94
118
|
|
data/msgpack/unpack_define.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* MessagePack unpacking routine template
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008-
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
data/msgpack/unpack_template.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* MessagePack unpacking routine template
|
3
3
|
*
|
4
|
-
* Copyright (C) 2008-
|
4
|
+
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
5
5
|
*
|
6
6
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
* you may not use this file except in compliance with the License.
|
@@ -130,11 +130,6 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
|
130
130
|
#define NEXT_CS(p) \
|
131
131
|
((unsigned int)*p & 0x1f)
|
132
132
|
|
133
|
-
#define PTR_CAST_8(ptr) (*(uint8_t*)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
133
|
#ifdef USE_CASE_RANGE
|
139
134
|
#define SWITCH_RANGE_BEGIN switch(*p) {
|
140
135
|
#define SWITCH_RANGE(FROM, TO) case FROM ... TO:
|
@@ -222,70 +217,70 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
|
222
217
|
//case CS_
|
223
218
|
//case CS_
|
224
219
|
case CS_FLOAT: {
|
225
|
-
union { uint32_t
|
226
|
-
|
227
|
-
push_fixed_value(_float,
|
220
|
+
union { uint32_t i; float f; } mem;
|
221
|
+
mem.i = _msgpack_load32(uint32_t,n);
|
222
|
+
push_fixed_value(_float, mem.f); }
|
228
223
|
case CS_DOUBLE: {
|
229
|
-
union { uint64_t
|
230
|
-
|
231
|
-
push_fixed_value(_double,
|
224
|
+
union { uint64_t i; double f; } mem;
|
225
|
+
mem.i = _msgpack_load64(uint64_t,n);
|
226
|
+
push_fixed_value(_double, mem.f); }
|
232
227
|
case CS_UINT_8:
|
233
|
-
push_fixed_value(_uint8, (uint8_t)
|
228
|
+
push_fixed_value(_uint8, *(uint8_t*)n);
|
234
229
|
case CS_UINT_16:
|
235
|
-
push_fixed_value(_uint16, (uint16_t
|
230
|
+
push_fixed_value(_uint16, _msgpack_load16(uint16_t,n));
|
236
231
|
case CS_UINT_32:
|
237
|
-
push_fixed_value(_uint32, (uint32_t
|
232
|
+
push_fixed_value(_uint32, _msgpack_load32(uint32_t,n));
|
238
233
|
case CS_UINT_64:
|
239
|
-
push_fixed_value(_uint64, (uint64_t
|
234
|
+
push_fixed_value(_uint64, _msgpack_load64(uint64_t,n));
|
240
235
|
|
241
236
|
case CS_INT_8:
|
242
|
-
push_fixed_value(_int8, (int8_t)
|
237
|
+
push_fixed_value(_int8, *(int8_t*)n);
|
243
238
|
case CS_INT_16:
|
244
|
-
push_fixed_value(_int16, (int16_t
|
239
|
+
push_fixed_value(_int16, _msgpack_load16(int16_t,n));
|
245
240
|
case CS_INT_32:
|
246
|
-
push_fixed_value(_int32, (int32_t
|
241
|
+
push_fixed_value(_int32, _msgpack_load32(int32_t,n));
|
247
242
|
case CS_INT_64:
|
248
|
-
push_fixed_value(_int64, (int64_t
|
243
|
+
push_fixed_value(_int64, _msgpack_load64(int64_t,n));
|
249
244
|
|
250
245
|
//case CS_
|
251
246
|
//case CS_
|
252
247
|
//case CS_BIG_INT_16:
|
253
|
-
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint16_t
|
248
|
+
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load16(uint16_t,n), _big_int_zero);
|
254
249
|
//case CS_BIG_INT_32:
|
255
|
-
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, (uint32_t
|
250
|
+
// again_fixed_trail_if_zero(ACS_BIG_INT_VALUE, _msgpack_load32(uint32_t,n), _big_int_zero);
|
256
251
|
//case ACS_BIG_INT_VALUE:
|
257
252
|
//_big_int_zero:
|
258
253
|
// // FIXME
|
259
254
|
// push_variable_value(_big_int, data, n, trail);
|
260
255
|
|
261
256
|
//case CS_BIG_FLOAT_16:
|
262
|
-
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint16_t
|
257
|
+
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load16(uint16_t,n), _big_float_zero);
|
263
258
|
//case CS_BIG_FLOAT_32:
|
264
|
-
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, (uint32_t
|
259
|
+
// again_fixed_trail_if_zero(ACS_BIG_FLOAT_VALUE, _msgpack_load32(uint32_t,n), _big_float_zero);
|
265
260
|
//case ACS_BIG_FLOAT_VALUE:
|
266
261
|
//_big_float_zero:
|
267
262
|
// // FIXME
|
268
263
|
// push_variable_value(_big_float, data, n, trail);
|
269
264
|
|
270
265
|
case CS_RAW_16:
|
271
|
-
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint16_t
|
266
|
+
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load16(uint16_t,n), _raw_zero);
|
272
267
|
case CS_RAW_32:
|
273
|
-
again_fixed_trail_if_zero(ACS_RAW_VALUE, (uint32_t
|
268
|
+
again_fixed_trail_if_zero(ACS_RAW_VALUE, _msgpack_load32(uint32_t,n), _raw_zero);
|
274
269
|
case ACS_RAW_VALUE:
|
275
270
|
_raw_zero:
|
276
271
|
push_variable_value(_raw, data, n, trail);
|
277
272
|
|
278
273
|
case CS_ARRAY_16:
|
279
|
-
start_container(_array, (uint16_t
|
274
|
+
start_container(_array, _msgpack_load16(uint16_t,n), CT_ARRAY_ITEM);
|
280
275
|
case CS_ARRAY_32:
|
281
276
|
/* FIXME security guard */
|
282
|
-
start_container(_array, (uint32_t
|
277
|
+
start_container(_array, _msgpack_load32(uint32_t,n), CT_ARRAY_ITEM);
|
283
278
|
|
284
279
|
case CS_MAP_16:
|
285
|
-
start_container(_map, (uint16_t
|
280
|
+
start_container(_map, _msgpack_load16(uint16_t,n), CT_MAP_KEY);
|
286
281
|
case CS_MAP_32:
|
287
282
|
/* FIXME security guard */
|
288
|
-
start_container(_map, (uint32_t
|
283
|
+
start_container(_map, _msgpack_load32(uint32_t,n), CT_MAP_KEY);
|
289
284
|
|
290
285
|
default:
|
291
286
|
goto _failed;
|
@@ -371,8 +366,4 @@ _end:
|
|
371
366
|
#undef start_container
|
372
367
|
|
373
368
|
#undef NEXT_CS
|
374
|
-
#undef PTR_CAST_8
|
375
|
-
#undef PTR_CAST_16
|
376
|
-
#undef PTR_CAST_32
|
377
|
-
#undef PTR_CAST_64
|
378
369
|
|
metadata
CHANGED
@@ -1,20 +1,20 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- FURUHASHI Sadayuki
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-03-02 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
17
|
-
email: frsyuki
|
16
|
+
description:
|
17
|
+
email: frsyuki@users.sourceforge.jp
|
18
18
|
executables: []
|
19
19
|
|
20
20
|
extensions:
|
@@ -24,42 +24,31 @@ extra_rdoc_files:
|
|
24
24
|
- ChangeLog
|
25
25
|
- AUTHORS
|
26
26
|
files:
|
27
|
-
-
|
28
|
-
- ChangeLog
|
29
|
-
- Rakefile
|
30
|
-
- test/msgpack_test.rb
|
31
|
-
- test/test_helper.rb
|
32
|
-
- ext/pack.h
|
33
|
-
- ext/unpack.h
|
27
|
+
- ext/extconf.rb
|
34
28
|
- ext/pack.c
|
29
|
+
- ext/pack.h
|
35
30
|
- ext/rbinit.c
|
36
31
|
- ext/unpack.c
|
37
|
-
- ext/
|
32
|
+
- ext/unpack.h
|
38
33
|
- msgpack/pack_define.h
|
39
34
|
- msgpack/pack_template.h
|
40
35
|
- msgpack/sysdep.h
|
41
36
|
- msgpack/unpack_define.h
|
42
37
|
- msgpack/unpack_template.h
|
38
|
+
- test/msgpack_test.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
- README
|
41
|
+
- ChangeLog
|
43
42
|
- AUTHORS
|
44
43
|
has_rdoc: true
|
45
44
|
homepage: http://msgpack.sourceforge.jp/
|
46
45
|
licenses: []
|
47
46
|
|
48
47
|
post_install_message:
|
49
|
-
rdoc_options:
|
50
|
-
|
51
|
-
- msgpack documentation
|
52
|
-
- --charset
|
53
|
-
- utf-8
|
54
|
-
- --opname
|
55
|
-
- index.html
|
56
|
-
- --line-numbers
|
57
|
-
- --main
|
58
|
-
- README
|
59
|
-
- --inline-source
|
60
|
-
- --exclude
|
61
|
-
- ^(examples|extras)/
|
48
|
+
rdoc_options: []
|
49
|
+
|
62
50
|
require_paths:
|
51
|
+
- lib
|
63
52
|
- ext
|
64
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
54
|
requirements:
|
@@ -79,6 +68,6 @@ rubyforge_project: msgpack
|
|
79
68
|
rubygems_version: 1.3.5
|
80
69
|
signing_key:
|
81
70
|
specification_version: 3
|
82
|
-
summary:
|
71
|
+
summary: MessagePack, a binary-based efficient data interchange format.
|
83
72
|
test_files:
|
84
73
|
- test/test_helper.rb
|
data/Rakefile
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/clean'
|
4
|
-
require 'rake/testtask'
|
5
|
-
require 'rake/packagetask'
|
6
|
-
require 'rake/gempackagetask'
|
7
|
-
require 'rake/rdoctask'
|
8
|
-
require 'rake/contrib/rubyforgepublisher'
|
9
|
-
require 'rake/contrib/sshpublisher'
|
10
|
-
require 'fileutils'
|
11
|
-
include FileUtils
|
12
|
-
|
13
|
-
NAME = "msgpack"
|
14
|
-
AUTHOR = "FURUHASHI Sadayuki"
|
15
|
-
EMAIL = "frsyuki _at_ users.sourceforge.jp"
|
16
|
-
DESCRIPTION = "Binary-based efficient data interchange format."
|
17
|
-
RUBYFORGE_PROJECT = "msgpack"
|
18
|
-
HOMEPATH = "http://msgpack.sourceforge.jp/"
|
19
|
-
BIN_FILES = %w( )
|
20
|
-
VERS = "0.3.2"
|
21
|
-
|
22
|
-
#REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
23
|
-
REV = nil
|
24
|
-
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
25
|
-
RDOC_OPTS = [
|
26
|
-
'--title', "#{NAME} documentation",
|
27
|
-
"--charset", "utf-8",
|
28
|
-
"--opname", "index.html",
|
29
|
-
"--line-numbers",
|
30
|
-
"--main", "README",
|
31
|
-
"--inline-source",
|
32
|
-
]
|
33
|
-
|
34
|
-
task :default => [:test]
|
35
|
-
task :package => [:clean]
|
36
|
-
|
37
|
-
Rake::TestTask.new("test") do |t|
|
38
|
-
t.libs << "test"
|
39
|
-
t.pattern = "test/**/*_test.rb"
|
40
|
-
t.verbose = true
|
41
|
-
end
|
42
|
-
|
43
|
-
spec = Gem::Specification.new do |s|
|
44
|
-
s.name = NAME
|
45
|
-
s.version = VERS
|
46
|
-
s.platform = Gem::Platform::RUBY
|
47
|
-
s.has_rdoc = false
|
48
|
-
s.extra_rdoc_files = ["README", "ChangeLog", "AUTHORS"]
|
49
|
-
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
|
50
|
-
s.summary = DESCRIPTION
|
51
|
-
s.description = DESCRIPTION
|
52
|
-
s.author = AUTHOR
|
53
|
-
s.email = EMAIL
|
54
|
-
s.homepage = HOMEPATH
|
55
|
-
s.executables = BIN_FILES
|
56
|
-
s.rubyforge_project = RUBYFORGE_PROJECT
|
57
|
-
s.bindir = "bin"
|
58
|
-
s.require_path = "ext"
|
59
|
-
s.autorequire = ""
|
60
|
-
s.test_files = Dir["test/test_*.rb"]
|
61
|
-
|
62
|
-
#s.add_dependency('activesupport', '>=1.3.1')
|
63
|
-
#s.required_ruby_version = '>= 1.8.2'
|
64
|
-
|
65
|
-
s.files = %w(README ChangeLog Rakefile) +
|
66
|
-
Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
|
67
|
-
Dir.glob("ext/**/*.{h,c,rb}") +
|
68
|
-
Dir.glob("examples/**/*.rb") +
|
69
|
-
Dir.glob("tools/*.rb") +
|
70
|
-
Dir.glob("msgpack/*.h")
|
71
|
-
|
72
|
-
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
73
|
-
end
|
74
|
-
|
75
|
-
Rake::GemPackageTask.new(spec) do |p|
|
76
|
-
p.need_tar = true
|
77
|
-
p.gem_spec = spec
|
78
|
-
end
|
79
|
-
|
80
|
-
task :install do
|
81
|
-
name = "#{NAME}-#{VERS}.gem"
|
82
|
-
sh %{rake package}
|
83
|
-
sh %{sudo gem install pkg/#{name}}
|
84
|
-
end
|
85
|
-
|
86
|
-
task :uninstall => [:clean] do
|
87
|
-
sh %{sudo gem uninstall #{NAME}}
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
#Rake::RDocTask.new do |rdoc|
|
92
|
-
# rdoc.rdoc_dir = 'html'
|
93
|
-
# rdoc.options += RDOC_OPTS
|
94
|
-
# rdoc.template = "resh"
|
95
|
-
# #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
96
|
-
# if ENV['DOC_FILES']
|
97
|
-
# rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
|
98
|
-
# else
|
99
|
-
# rdoc.rdoc_files.include('README', 'ChangeLog')
|
100
|
-
# rdoc.rdoc_files.include('lib/**/*.rb')
|
101
|
-
# rdoc.rdoc_files.include('ext/**/*.c')
|
102
|
-
# end
|
103
|
-
#end
|
104
|
-
|
105
|
-
desc "Publish to RubyForge"
|
106
|
-
task :rubyforge => [:rdoc, :package] do
|
107
|
-
require 'rubyforge'
|
108
|
-
Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'frsyuki').upload
|
109
|
-
end
|
110
|
-
|
111
|
-
desc 'Package and upload the release to rubyforge.'
|
112
|
-
task :release => [:clean, :package] do |t|
|
113
|
-
v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
|
114
|
-
abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
|
115
|
-
pkg = "pkg/#{NAME}-#{VERS}"
|
116
|
-
|
117
|
-
rf = RubyForge.new
|
118
|
-
puts "Logging in"
|
119
|
-
rf.login
|
120
|
-
|
121
|
-
c = rf.userconfig
|
122
|
-
# c["release_notes"] = description if description
|
123
|
-
# c["release_changes"] = changes if changes
|
124
|
-
c["preformatted"] = true
|
125
|
-
|
126
|
-
files = [
|
127
|
-
"#{pkg}.tgz",
|
128
|
-
"#{pkg}.gem"
|
129
|
-
].compact
|
130
|
-
|
131
|
-
puts "Releasing #{NAME} v. #{VERS}"
|
132
|
-
rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
|
133
|
-
end
|