mochilo 1.3.0 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -4
- data/Gemfile.lock +1 -1
- data/LICENSE +21 -0
- data/README.md +12 -26
- data/docs/format-spec.md +63 -44
- data/docs/why-banana-pack.md +5 -3
- data/ext/mochilo/buffer.c +11 -14
- data/ext/mochilo/buffer.h +4 -5
- data/ext/mochilo/mochilo.h +33 -27
- data/ext/mochilo/mochilo.rb.c +15 -42
- data/ext/mochilo/mochilo_api.h +2 -15
- data/ext/mochilo/mochilo_pack.c +103 -95
- data/ext/mochilo/mochilo_unpack.c +125 -32
- data/lib/mochilo/version.rb +1 -1
- data/mochilo.gemspec +2 -1
- data/script/bootstrap +1 -0
- data/test/pack_test.rb +169 -64
- data/test/setup.rb +4 -9
- data/test/unpack_test.rb +243 -48
- metadata +5 -8
- data/MIT-LICENSE +0 -20
data/ext/mochilo/mochilo_pack.c
CHANGED
@@ -7,7 +7,27 @@
|
|
7
7
|
|
8
8
|
extern VALUE rb_eMochiloPackError;
|
9
9
|
|
10
|
-
void mochilo_pack_one(mochilo_buf *buf, VALUE rb_object
|
10
|
+
void mochilo_pack_one(mochilo_buf *buf, VALUE rb_object);
|
11
|
+
|
12
|
+
static void mochilo_buf_put_ext_size(mochilo_buf *buf, long size)
|
13
|
+
{
|
14
|
+
if (size < 0x100) {
|
15
|
+
uint8_t lead = size;
|
16
|
+
mochilo_buf_putc(buf, MSGPACK_T_ENC8);
|
17
|
+
mochilo_buf_putc(buf, lead);
|
18
|
+
} else if (size < 0x10000) {
|
19
|
+
uint16_t lead = size;
|
20
|
+
mochilo_buf_putc(buf, MSGPACK_T_ENC16);
|
21
|
+
mochilo_buf_put16be(buf, &lead);
|
22
|
+
} else if (size < 0x100000000) {
|
23
|
+
mochilo_buf_putc(buf, MSGPACK_T_ENC32);
|
24
|
+
mochilo_buf_put32be(buf, &size);
|
25
|
+
} else {
|
26
|
+
// there is no ext 64
|
27
|
+
rb_raise(rb_eMochiloPackError,
|
28
|
+
"String cannot be larger than %ld bytes", 0x100000000);
|
29
|
+
}
|
30
|
+
}
|
11
31
|
|
12
32
|
void mochilo_pack_fixnum(mochilo_buf *buf, VALUE rb_fixnum)
|
13
33
|
{
|
@@ -73,42 +93,49 @@ void mochilo_pack_bignum(mochilo_buf *buf, VALUE rb_bignum)
|
|
73
93
|
}
|
74
94
|
}
|
75
95
|
|
76
|
-
|
96
|
+
static void mochilo_put_ext_size_and_type(mochilo_buf *buf, size_t size, enum mochilo_ext_types_t type)
|
97
|
+
{
|
98
|
+
mochilo_buf_put_ext_size(buf, size + 1);
|
99
|
+
mochilo_buf_putc(buf, MOCHILO_EXT_TYPE);
|
100
|
+
mochilo_buf_putc(buf, type);
|
101
|
+
}
|
102
|
+
|
103
|
+
void mochilo_pack_symbol(mochilo_buf *buf, VALUE rb_symbol)
|
104
|
+
{
|
105
|
+
char *symbol_name;
|
106
|
+
size_t size;
|
107
|
+
|
108
|
+
symbol_name = rb_id2name(SYM2ID(rb_symbol));
|
109
|
+
size = strlen(symbol_name);
|
110
|
+
|
111
|
+
mochilo_put_ext_size_and_type(buf, size, MOCHILO_T_SYMBOL);
|
112
|
+
mochilo_buf_put(buf, symbol_name, size);
|
113
|
+
}
|
114
|
+
|
77
115
|
void mochilo_pack_regexp(mochilo_buf *buf, VALUE rb_regexp)
|
78
116
|
{
|
117
|
+
uint32_t options;
|
79
118
|
size_t size;
|
80
119
|
rb_encoding *encoding;
|
81
120
|
char *enc_name;
|
82
121
|
const struct mochilo_enc_map *enc2id;
|
83
|
-
uint32_t options;
|
84
|
-
const char *regexp;
|
85
|
-
|
86
|
-
size = RREGEXP_SRC_LEN(rb_regexp);
|
87
|
-
|
88
|
-
if (size < (1<<16)) {
|
89
|
-
uint16_t packed_size = size;
|
90
122
|
|
91
|
-
|
92
|
-
|
93
|
-
|
123
|
+
encoding = rb_enc_get(rb_regexp);
|
124
|
+
enc_name = rb_enc_name(encoding);
|
125
|
+
enc2id = mochilo_encoding_to_id(enc_name, (unsigned int)strlen(enc_name));
|
94
126
|
|
95
|
-
|
96
|
-
|
127
|
+
options = rb_reg_options(rb_regexp);
|
128
|
+
size = RREGEXP_SRC_LEN(rb_regexp);
|
97
129
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
mochilo_buf_put(buf, regexp, size);
|
103
|
-
} else {
|
104
|
-
rb_raise(rb_eMochiloPackError,
|
105
|
-
"Regexp too long: must be under %d bytes, %ld given", 1<<16, size);
|
106
|
-
}
|
130
|
+
mochilo_put_ext_size_and_type(buf, 4 + 1 + size, MOCHILO_T_REGEXP);
|
131
|
+
mochilo_buf_put32be(buf, &options);
|
132
|
+
mochilo_buf_putc(buf, enc2id ? enc2id->id : 0);
|
133
|
+
mochilo_buf_put(buf, RREGEXP_SRC_PTR(rb_regexp), size);
|
107
134
|
}
|
108
|
-
#endif
|
109
135
|
|
110
136
|
void mochilo_pack_time(mochilo_buf *buf, VALUE rb_time)
|
111
137
|
{
|
138
|
+
struct time_object *tobj;
|
112
139
|
uint64_t sec;
|
113
140
|
uint64_t usec;
|
114
141
|
int32_t utc_offset;
|
@@ -117,7 +144,7 @@ void mochilo_pack_time(mochilo_buf *buf, VALUE rb_time)
|
|
117
144
|
usec = NUM2ULONG(rb_funcall(rb_time, rb_intern("usec"), 0));
|
118
145
|
utc_offset = NUM2INT(rb_funcall(rb_time, rb_intern("utc_offset"), 0));
|
119
146
|
|
120
|
-
|
147
|
+
mochilo_put_ext_size_and_type(buf, 8+8+4, MOCHILO_T_TIME);
|
121
148
|
mochilo_buf_put64be(buf, &sec);
|
122
149
|
mochilo_buf_put64be(buf, &usec);
|
123
150
|
mochilo_buf_put32be(buf, &utc_offset);
|
@@ -125,14 +152,13 @@ void mochilo_pack_time(mochilo_buf *buf, VALUE rb_time)
|
|
125
152
|
|
126
153
|
struct mochilo_hash_pack {
|
127
154
|
mochilo_buf *buf;
|
128
|
-
int trusted;
|
129
155
|
};
|
130
156
|
|
131
157
|
static int hash_callback(VALUE key, VALUE val, VALUE opaque)
|
132
158
|
{
|
133
159
|
struct mochilo_hash_pack *hash_pack = (struct mochilo_hash_pack*)opaque;
|
134
|
-
mochilo_pack_one(hash_pack->buf, key
|
135
|
-
mochilo_pack_one(hash_pack->buf, val
|
160
|
+
mochilo_pack_one(hash_pack->buf, key);
|
161
|
+
mochilo_pack_one(hash_pack->buf, val);
|
136
162
|
return 0;
|
137
163
|
}
|
138
164
|
|
@@ -143,13 +169,12 @@ void mochilo_pack_double(mochilo_buf *buf, VALUE rb_double)
|
|
143
169
|
mochilo_buf_put64be(buf, &d);
|
144
170
|
}
|
145
171
|
|
146
|
-
void mochilo_pack_hash(mochilo_buf *buf, VALUE rb_hash
|
172
|
+
void mochilo_pack_hash(mochilo_buf *buf, VALUE rb_hash)
|
147
173
|
{
|
148
174
|
struct mochilo_hash_pack hash_pack;
|
149
175
|
long size = RHASH_SIZE(rb_hash);
|
150
176
|
|
151
177
|
hash_pack.buf = buf;
|
152
|
-
hash_pack.trusted = trusted;
|
153
178
|
|
154
179
|
if (size < 0x10) {
|
155
180
|
uint8_t lead = 0x80 | size;
|
@@ -174,46 +199,26 @@ void mochilo_pack_bytes(mochilo_buf *buf, VALUE rb_bytes)
|
|
174
199
|
{
|
175
200
|
long size = RSTRING_LEN(rb_bytes);
|
176
201
|
|
177
|
-
if (size <
|
178
|
-
uint8_t lead =
|
202
|
+
if (size < 0x100) {
|
203
|
+
uint8_t lead = size;
|
204
|
+
mochilo_buf_putc(buf, MSGPACK_T_BIN8);
|
179
205
|
mochilo_buf_putc(buf, lead);
|
180
|
-
}
|
181
|
-
|
182
|
-
else if (size < 0x10000) {
|
206
|
+
} else if (size < 0x10000) {
|
183
207
|
uint16_t lead = size;
|
184
|
-
mochilo_buf_putc(buf,
|
208
|
+
mochilo_buf_putc(buf, MSGPACK_T_BIN16);
|
185
209
|
mochilo_buf_put16be(buf, &lead);
|
186
|
-
}
|
187
|
-
|
188
|
-
else {
|
189
|
-
mochilo_buf_putc(buf, MSGPACK_T_RAW32);
|
210
|
+
} else if (size < 0x100000000) {
|
211
|
+
mochilo_buf_putc(buf, MSGPACK_T_BIN32);
|
190
212
|
mochilo_buf_put32be(buf, &size);
|
191
|
-
}
|
192
|
-
|
193
|
-
mochilo_buf_put(buf, RSTRING_PTR(rb_bytes), size);
|
194
|
-
}
|
195
|
-
|
196
|
-
void mochilo_pack_symbol(mochilo_buf *buf, VALUE rb_symbol)
|
197
|
-
{
|
198
|
-
long size;
|
199
|
-
const char *name;
|
200
|
-
|
201
|
-
name = rb_id2name(SYM2ID(rb_symbol));
|
202
|
-
size = strlen(name);
|
203
|
-
|
204
|
-
if (size < 0x100) {
|
205
|
-
uint8_t lead = size;
|
206
|
-
mochilo_buf_putc(buf, MSGPACK_T_SYM);
|
207
|
-
mochilo_buf_putc(buf, lead);
|
208
213
|
} else {
|
214
|
+
// there is no bin 64
|
209
215
|
rb_raise(rb_eMochiloPackError,
|
210
|
-
"
|
216
|
+
"Binary string cannot be larger than %ld bytes", 0x100000000);
|
211
217
|
}
|
212
218
|
|
213
|
-
mochilo_buf_put(buf,
|
219
|
+
mochilo_buf_put(buf, RSTRING_PTR(rb_bytes), size);
|
214
220
|
}
|
215
221
|
|
216
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
217
222
|
void mochilo_pack_str(mochilo_buf *buf, VALUE rb_str)
|
218
223
|
{
|
219
224
|
long size = RSTRING_LEN(rb_str);
|
@@ -222,27 +227,41 @@ void mochilo_pack_str(mochilo_buf *buf, VALUE rb_str)
|
|
222
227
|
const struct mochilo_enc_map *enc2id;
|
223
228
|
const char *enc_name;
|
224
229
|
|
225
|
-
if (size < 0x10000) {
|
226
|
-
uint16_t lead = size;
|
227
|
-
mochilo_buf_putc(buf, MSGPACK_T_STR16);
|
228
|
-
mochilo_buf_put16be(buf, &lead);
|
229
|
-
}
|
230
|
-
|
231
|
-
else {
|
232
|
-
mochilo_buf_putc(buf, MSGPACK_T_STR32);
|
233
|
-
mochilo_buf_put32be(buf, &size);
|
234
|
-
}
|
235
|
-
|
236
230
|
encoding = rb_enc_get(rb_str);
|
237
231
|
enc_name = rb_enc_name(encoding);
|
238
|
-
enc2id = mochilo_encoding_to_id(enc_name, (unsigned int)strlen(enc_name));
|
239
232
|
|
240
|
-
|
233
|
+
if (encoding == rb_utf8_encoding()) {
|
234
|
+
// use str type from msgpack spec
|
235
|
+
if (size < 0x20) {
|
236
|
+
uint8_t lead = 0xa0 | size;
|
237
|
+
mochilo_buf_putc(buf, lead);
|
238
|
+
} else if (size < 0x100) {
|
239
|
+
uint8_t lead = size;
|
240
|
+
mochilo_buf_putc(buf, MSGPACK_T_STR8);
|
241
|
+
mochilo_buf_putc(buf, lead);
|
242
|
+
} else if (size < 0x10000) {
|
243
|
+
uint16_t lead = size;
|
244
|
+
mochilo_buf_putc(buf, MSGPACK_T_STR16);
|
245
|
+
mochilo_buf_put16be(buf, &lead);
|
246
|
+
} else if (size < 0x100000000) {
|
247
|
+
mochilo_buf_putc(buf, MSGPACK_T_STR32);
|
248
|
+
mochilo_buf_put32be(buf, &size);
|
249
|
+
} else {
|
250
|
+
// there is no str 64
|
251
|
+
rb_raise(rb_eMochiloPackError,
|
252
|
+
"String cannot be larger than %ld bytes", 0x100000000);
|
253
|
+
}
|
254
|
+
} else {
|
255
|
+
// if another encoding is used we need to use our custom types
|
256
|
+
mochilo_buf_put_ext_size(buf, size);
|
257
|
+
enc2id = mochilo_encoding_to_id(enc_name, (unsigned int)strlen(enc_name));
|
258
|
+
mochilo_buf_putc(buf, enc2id ? enc2id->id : 0);
|
259
|
+
}
|
260
|
+
|
241
261
|
mochilo_buf_put(buf, RSTRING_PTR(rb_str), size);
|
242
262
|
}
|
243
|
-
#endif
|
244
263
|
|
245
|
-
void mochilo_pack_array(mochilo_buf *buf, VALUE rb_array
|
264
|
+
void mochilo_pack_array(mochilo_buf *buf, VALUE rb_array)
|
246
265
|
{
|
247
266
|
long i, size = RARRAY_LEN(rb_array);
|
248
267
|
|
@@ -263,11 +282,11 @@ void mochilo_pack_array(mochilo_buf *buf, VALUE rb_array, int trusted)
|
|
263
282
|
}
|
264
283
|
|
265
284
|
for (i = 0; i < size; i++) {
|
266
|
-
mochilo_pack_one(buf, rb_ary_entry(rb_array, i)
|
285
|
+
mochilo_pack_one(buf, rb_ary_entry(rb_array, i));
|
267
286
|
}
|
268
287
|
}
|
269
288
|
|
270
|
-
void mochilo_pack_one(mochilo_buf *buf, VALUE rb_object
|
289
|
+
void mochilo_pack_one(mochilo_buf *buf, VALUE rb_object)
|
271
290
|
{
|
272
291
|
switch (rb_type(rb_object)) {
|
273
292
|
case T_NIL:
|
@@ -286,28 +305,19 @@ void mochilo_pack_one(mochilo_buf *buf, VALUE rb_object, int trusted)
|
|
286
305
|
mochilo_pack_fixnum(buf, rb_object);
|
287
306
|
return;
|
288
307
|
|
289
|
-
case T_SYMBOL:
|
290
|
-
if (trusted)
|
291
|
-
mochilo_pack_symbol(buf, rb_object);
|
292
|
-
else
|
293
|
-
mochilo_pack_str(buf, rb_obj_as_string(rb_object));
|
294
|
-
return;
|
295
|
-
|
296
308
|
case T_STRING:
|
297
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
298
309
|
if (ENCODING_GET(rb_object) != 0)
|
299
310
|
mochilo_pack_str(buf, rb_object);
|
300
311
|
else
|
301
|
-
#endif
|
302
312
|
mochilo_pack_bytes(buf, rb_object);
|
303
313
|
return;
|
304
314
|
|
305
315
|
case T_HASH:
|
306
|
-
mochilo_pack_hash(buf, rb_object
|
316
|
+
mochilo_pack_hash(buf, rb_object);
|
307
317
|
return;
|
308
318
|
|
309
319
|
case T_ARRAY:
|
310
|
-
mochilo_pack_array(buf, rb_object
|
320
|
+
mochilo_pack_array(buf, rb_object);
|
311
321
|
return;
|
312
322
|
|
313
323
|
case T_FLOAT:
|
@@ -318,22 +328,20 @@ void mochilo_pack_one(mochilo_buf *buf, VALUE rb_object, int trusted)
|
|
318
328
|
mochilo_pack_bignum(buf, rb_object);
|
319
329
|
return;
|
320
330
|
|
321
|
-
|
331
|
+
case T_SYMBOL:
|
332
|
+
mochilo_pack_symbol(buf, rb_object);
|
333
|
+
return;
|
334
|
+
|
322
335
|
case T_REGEXP:
|
323
336
|
mochilo_pack_regexp(buf, rb_object);
|
324
337
|
return;
|
325
|
-
#endif
|
326
338
|
|
327
339
|
default:
|
328
340
|
if (rb_cTime == rb_obj_class(rb_object)) {
|
329
341
|
mochilo_pack_time(buf, rb_object);
|
330
|
-
} else if (rb_respond_to(rb_object, rb_intern("to_bpack"))) {
|
331
|
-
VALUE bpack = rb_funcall(rb_object, rb_intern("to_bpack"), 0);
|
332
|
-
|
333
|
-
mochilo_buf_put(buf, RSTRING_PTR(bpack), RSTRING_LEN(bpack));
|
334
342
|
} else {
|
335
343
|
rb_raise(rb_eMochiloPackError,
|
336
|
-
|
344
|
+
"Unsupported object type: %s", rb_obj_classname(rb_object));
|
337
345
|
}
|
338
346
|
return;
|
339
347
|
}
|
@@ -6,6 +6,8 @@
|
|
6
6
|
#include "mochilo.h"
|
7
7
|
#include "mochilo_api.h"
|
8
8
|
|
9
|
+
extern VALUE rb_eMochiloUnpackError;
|
10
|
+
|
9
11
|
static inline int unpack_array(mo_value *_array, size_t elements, mochilo_src *buf)
|
10
12
|
{
|
11
13
|
size_t i;
|
@@ -57,6 +59,69 @@ static inline int unpack_hash(mo_value *_hash, size_t elements, mochilo_src *buf
|
|
57
59
|
return 0; \
|
58
60
|
}
|
59
61
|
|
62
|
+
static int mochilo_unpack_custom(mo_value *_value, mochilo_src *src, size_t length)
|
63
|
+
{
|
64
|
+
uint8_t custom_type;
|
65
|
+
|
66
|
+
SRC_ENSURE_AVAIL(src, length);
|
67
|
+
|
68
|
+
if (length < 1)
|
69
|
+
return -1;
|
70
|
+
length--;
|
71
|
+
mochilo_src_get8be(src, &custom_type);
|
72
|
+
|
73
|
+
switch (custom_type) {
|
74
|
+
case MOCHILO_T_SYMBOL:
|
75
|
+
{
|
76
|
+
const char *ptr;
|
77
|
+
if (!(ptr = mochilo_src_peek(src, length)))
|
78
|
+
return -1;
|
79
|
+
*_value = moapi_symbol_new(ptr, length);
|
80
|
+
return 0;
|
81
|
+
}
|
82
|
+
|
83
|
+
case MOCHILO_T_REGEXP:
|
84
|
+
{
|
85
|
+
uint32_t options;
|
86
|
+
uint8_t encoding;
|
87
|
+
const char *ptr;
|
88
|
+
|
89
|
+
if (length < 5)
|
90
|
+
return -1;
|
91
|
+
mochilo_src_get32be(src, &options);
|
92
|
+
mochilo_src_get8be(src, &encoding);
|
93
|
+
length -= 5;
|
94
|
+
|
95
|
+
if (!(ptr = mochilo_src_peek(src, length)))
|
96
|
+
return -1;
|
97
|
+
|
98
|
+
*_value = moapi_regexp_new(ptr, length, encoding, options);
|
99
|
+
return 0;
|
100
|
+
}
|
101
|
+
|
102
|
+
case MOCHILO_T_TIME:
|
103
|
+
{
|
104
|
+
uint64_t sec;
|
105
|
+
uint64_t usec;
|
106
|
+
int32_t utc_offset;
|
107
|
+
|
108
|
+
if (length != 8+8+4)
|
109
|
+
return -1;
|
110
|
+
|
111
|
+
mochilo_src_get64be(src, &sec);
|
112
|
+
mochilo_src_get64be(src, &usec);
|
113
|
+
mochilo_src_get32be(src, &utc_offset);
|
114
|
+
|
115
|
+
*_value = moapi_time_new(sec, usec, utc_offset);
|
116
|
+
return 0;
|
117
|
+
}
|
118
|
+
|
119
|
+
default:
|
120
|
+
rb_raise(rb_eMochiloUnpackError, "unknown custom type 0x%02x", custom_type);
|
121
|
+
return -1;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
60
125
|
int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
61
126
|
{
|
62
127
|
uint8_t leader;
|
@@ -159,14 +224,10 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
159
224
|
return unpack_hash(_value, (size_t)length, src);
|
160
225
|
}
|
161
226
|
|
162
|
-
case
|
227
|
+
case MSGPACK_T_STR8:
|
163
228
|
{
|
164
229
|
uint8_t length;
|
165
230
|
const char *ptr;
|
166
|
-
|
167
|
-
if (!src->trusted) {
|
168
|
-
return MSGPACK_EUNSAFE;
|
169
|
-
}
|
170
231
|
|
171
232
|
SRC_ENSURE_AVAIL(src, 1);
|
172
233
|
mochilo_src_get8be(src, &length);
|
@@ -174,48 +235,61 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
174
235
|
if (!(ptr = mochilo_src_peek(src, length)))
|
175
236
|
return -1;
|
176
237
|
|
177
|
-
*_value =
|
238
|
+
*_value = moapi_str_new(ptr, length, MSGPACK_ENC_UTF_8);
|
178
239
|
return 0;
|
179
240
|
}
|
180
241
|
|
181
|
-
|
182
|
-
case MSGPACK_T_REGEXP:
|
242
|
+
case MSGPACK_T_STR16:
|
183
243
|
{
|
184
244
|
uint16_t length;
|
185
|
-
uint32_t options;
|
186
|
-
uint8_t encoding;
|
187
245
|
const char *ptr;
|
188
246
|
|
189
|
-
SRC_ENSURE_AVAIL(src, 2+
|
247
|
+
SRC_ENSURE_AVAIL(src, 2 + 1);
|
190
248
|
mochilo_src_get16be(src, &length);
|
191
|
-
mochilo_src_get32be(src, &options);
|
192
|
-
mochilo_src_get8be(src, &encoding);
|
193
249
|
|
194
250
|
if (!(ptr = mochilo_src_peek(src, length)))
|
195
251
|
return -1;
|
196
252
|
|
197
|
-
*_value =
|
253
|
+
*_value = moapi_str_new(ptr, length, MSGPACK_ENC_UTF_8);
|
198
254
|
return 0;
|
199
255
|
}
|
200
|
-
#endif
|
201
256
|
|
202
|
-
case
|
257
|
+
case MSGPACK_T_STR32:
|
203
258
|
{
|
204
|
-
|
205
|
-
|
206
|
-
int32_t utc_offset;
|
259
|
+
uint32_t length;
|
260
|
+
const char *ptr;
|
207
261
|
|
208
|
-
SRC_ENSURE_AVAIL(src,
|
209
|
-
|
210
|
-
mochilo_src_get64be(src, &usec);
|
211
|
-
mochilo_src_get32be(src, &utc_offset);
|
262
|
+
SRC_ENSURE_AVAIL(src, 4 + 1);
|
263
|
+
mochilo_src_get32be(src, &length);
|
212
264
|
|
213
|
-
|
265
|
+
if (!(ptr = mochilo_src_peek(src, length)))
|
266
|
+
return -1;
|
267
|
+
|
268
|
+
*_value = moapi_str_new(ptr, length, MSGPACK_ENC_UTF_8);
|
214
269
|
return 0;
|
215
270
|
}
|
216
271
|
|
217
|
-
|
218
|
-
|
272
|
+
case MSGPACK_T_ENC8:
|
273
|
+
{
|
274
|
+
uint8_t length;
|
275
|
+
uint8_t encoding;
|
276
|
+
const char *ptr;
|
277
|
+
|
278
|
+
SRC_ENSURE_AVAIL(src, 1 + 1);
|
279
|
+
mochilo_src_get8be(src, &length);
|
280
|
+
mochilo_src_get8be(src, &encoding);
|
281
|
+
|
282
|
+
if (encoding == MOCHILO_EXT_TYPE)
|
283
|
+
return mochilo_unpack_custom(_value, src, length);
|
284
|
+
|
285
|
+
if (!(ptr = mochilo_src_peek(src, length)))
|
286
|
+
return -1;
|
287
|
+
|
288
|
+
*_value = moapi_str_new(ptr, length, encoding);
|
289
|
+
return 0;
|
290
|
+
}
|
291
|
+
|
292
|
+
case MSGPACK_T_ENC16:
|
219
293
|
{
|
220
294
|
uint16_t length;
|
221
295
|
uint8_t encoding;
|
@@ -225,6 +299,9 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
225
299
|
mochilo_src_get16be(src, &length);
|
226
300
|
mochilo_src_get8be(src, &encoding);
|
227
301
|
|
302
|
+
if (encoding == MOCHILO_EXT_TYPE)
|
303
|
+
return mochilo_unpack_custom(_value, src, length);
|
304
|
+
|
228
305
|
if (!(ptr = mochilo_src_peek(src, length)))
|
229
306
|
return -1;
|
230
307
|
|
@@ -232,7 +309,7 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
232
309
|
return 0;
|
233
310
|
}
|
234
311
|
|
235
|
-
case
|
312
|
+
case MSGPACK_T_ENC32:
|
236
313
|
{
|
237
314
|
uint32_t length;
|
238
315
|
uint8_t encoding;
|
@@ -242,15 +319,32 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
242
319
|
mochilo_src_get32be(src, &length);
|
243
320
|
mochilo_src_get8be(src, &encoding);
|
244
321
|
|
322
|
+
if (encoding == MOCHILO_EXT_TYPE)
|
323
|
+
return mochilo_unpack_custom(_value, src, length);
|
324
|
+
|
245
325
|
if (!(ptr = mochilo_src_peek(src, length)))
|
246
326
|
return -1;
|
247
327
|
|
248
328
|
*_value = moapi_str_new(ptr, length, encoding);
|
249
329
|
return 0;
|
250
330
|
}
|
251
|
-
#endif
|
252
331
|
|
253
|
-
case
|
332
|
+
case MSGPACK_T_BIN8:
|
333
|
+
{
|
334
|
+
uint8_t length;
|
335
|
+
const char *ptr;
|
336
|
+
|
337
|
+
SRC_ENSURE_AVAIL(src, 1);
|
338
|
+
mochilo_src_get8be(src, &length);
|
339
|
+
|
340
|
+
if (!(ptr = mochilo_src_peek(src, length)))
|
341
|
+
return -1;
|
342
|
+
|
343
|
+
*_value = moapi_bytes_new(ptr, length);
|
344
|
+
return 0;
|
345
|
+
}
|
346
|
+
|
347
|
+
case MSGPACK_T_BIN16:
|
254
348
|
{
|
255
349
|
uint16_t length;
|
256
350
|
const char *ptr;
|
@@ -265,7 +359,7 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
265
359
|
return 0;
|
266
360
|
}
|
267
361
|
|
268
|
-
case
|
362
|
+
case MSGPACK_T_BIN32:
|
269
363
|
{
|
270
364
|
uint32_t length;
|
271
365
|
const char *ptr;
|
@@ -304,7 +398,7 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
304
398
|
if (!(ptr = mochilo_src_peek(src, length)))
|
305
399
|
return -1;
|
306
400
|
|
307
|
-
*_value =
|
401
|
+
*_value = moapi_str_new(ptr, length, MSGPACK_ENC_UTF_8);
|
308
402
|
return 0;
|
309
403
|
}
|
310
404
|
|
@@ -312,4 +406,3 @@ int mochilo_unpack_one(mo_value *_value, mochilo_src *src)
|
|
312
406
|
}
|
313
407
|
}
|
314
408
|
}
|
315
|
-
|
data/lib/mochilo/version.rb
CHANGED
data/mochilo.gemspec
CHANGED
@@ -13,8 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.require_paths = ["lib"]
|
14
14
|
s.rubygems_version = %q{1.4.2}
|
15
15
|
s.summary = %q{A ruby library for BananaPack}
|
16
|
-
s.test_files = `git ls-files
|
16
|
+
s.test_files = `git ls-files spec`.split("\n")
|
17
17
|
s.required_ruby_version = ">= 1.9.3"
|
18
|
+
s.licenses = ["MIT"]
|
18
19
|
|
19
20
|
# tests
|
20
21
|
s.add_development_dependency 'rake-compiler', ">= 0.8.1"
|