cbor 0.5.8.0 → 0.5.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -3
- data/ChangeLog +10 -0
- data/README.rdoc +3 -3
- data/Rakefile +3 -0
- data/cbor.gemspec +0 -1
- data/ext/cbor/buffer.h +5 -0
- data/ext/cbor/compat.h +5 -0
- data/ext/cbor/extconf.rb +3 -0
- data/ext/cbor/packer.h +27 -2
- data/ext/cbor/sysdep.h +4 -0
- data/ext/cbor/unpacker.c +13 -3
- data/lib/cbor/version.rb +1 -1
- data/spec/format_spec.rb +11 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/unpacker_spec.rb +24 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f05745e0a68a5a628790baf2d44945a4ce57bae
|
4
|
+
data.tar.gz: 3eff2fd87b1d8ceba13dda6ad6809a4f2b8253be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3b24e6deceaf7061b8302c586f85f9c58eef81fdd92a376ccdcc6de410742ee9947990af2116e6948b8adb82703540d9c8cc3698eb7f7bb26c86373fdce9950
|
7
|
+
data.tar.gz: 1837146a082f666d20d377ad82c52bde5d7c05e24296a967f5184d123e7ca05cc7f3045cf51ee4c603514f0a72caf7a7366ba317998d440bf915d5431c0553cc
|
data/.travis.yml
CHANGED
@@ -2,12 +2,19 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
-
|
6
|
-
- 2.1.0
|
5
|
+
- 2.1
|
7
6
|
- ruby-head
|
7
|
+
- rbx-2
|
8
|
+
- 1.8.7
|
8
9
|
matrix:
|
9
10
|
allow_failures:
|
10
|
-
- rvm:
|
11
|
+
- rvm: ruby-head
|
12
|
+
- rvm: rbx-2
|
13
|
+
- rvm: 1.8.7
|
14
|
+
|
15
|
+
gemfile:
|
16
|
+
- Gemfile
|
17
|
+
|
11
18
|
script: "bundle exec rake spec"
|
12
19
|
|
13
20
|
notifications:
|
data/ChangeLog
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
2014-12-13 Carsten Bormann <cabo@tzi.org>
|
2
|
+
|
3
|
+
* 0.5.9.0: Upstream fixes; prepare for Ruby 2.2 (use GC-able
|
4
|
+
symbols for :keys_as_symbols, use rb_integer_pack if available)
|
5
|
+
|
6
|
+
2014-12-12 Carsten Bormann <cabo@tzi.org>
|
7
|
+
|
8
|
+
* 0.5.8.0: Upstream fixes (including {symbolize_keys: true} as an
|
9
|
+
alternative for :keys_as_symbols); README updates.
|
10
|
+
|
1
11
|
2014-02-09 Carsten Bormann <cabo@tzi.org>
|
2
12
|
|
3
13
|
* 0.5.6.4: Add more checking for bare indefinite breaks and
|
data/README.rdoc
CHANGED
@@ -17,7 +17,7 @@ Use RubyGems to install:
|
|
17
17
|
|
18
18
|
CBOR is an object representation format defined by the IETF[http://ietf.org].
|
19
19
|
The specification[http://tools.ietf.org/html/rfc7049]
|
20
|
-
|
20
|
+
is an IETF Standards-Track specification
|
21
21
|
and has been published as RFC 7049.
|
22
22
|
|
23
23
|
This is all based on wonderful work by frsyuki, and I have no idea how
|
@@ -37,9 +37,9 @@ Todos:
|
|
37
37
|
get some documentation in the directory +doc+ (see +index.html+ there).
|
38
38
|
|
39
39
|
* Cover more rubies.
|
40
|
-
* \[
|
40
|
+
* \[✔✔✔✔] tested on MRI (1.9.3, 2.0.0, 2.1.5, 2.2 head).
|
41
41
|
* (\[✔] There now also is some basic MRI 1.8.7 compatibility, however 1.8.7 does not support differentiation between byte and text strings.)
|
42
|
-
* \[
|
42
|
+
* \[✔] tested on Rubinius 2.4.1.
|
43
43
|
* \[_] Publish the pure-ruby version and make it work the same way on JRuby.
|
44
44
|
|
45
45
|
* Find and implement good ways to offer CBOR's indefinite length
|
data/Rakefile
CHANGED
data/cbor.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = "cabo@tzi.org"
|
11
11
|
s.license = "Apache 2.0"
|
12
12
|
s.homepage = "http://cbor.io/"
|
13
|
-
# s.rubyforge_project = "msgpack"
|
14
13
|
s.has_rdoc = false
|
15
14
|
s.files = `git ls-files`.split("\n")
|
16
15
|
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
data/ext/cbor/buffer.h
CHANGED
@@ -454,6 +454,7 @@ static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_
|
|
454
454
|
|
455
455
|
VALUE result;
|
456
456
|
if (as_symbol) {
|
457
|
+
#ifndef HAVE_RB_STR_INTERN
|
457
458
|
#ifndef HAVE_RB_INTERN_STR
|
458
459
|
/* MRI 1.8 doesn't have rb_intern_str or rb_intern2, hack it... */
|
459
460
|
char *tmp = xmalloc(length+1);
|
@@ -464,6 +465,10 @@ static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_
|
|
464
465
|
#else
|
465
466
|
result = ID2SYM(rb_intern2(b->read_buffer, length));
|
466
467
|
/* FIXME: This is stuck at ASCII encoding */
|
468
|
+
#endif
|
469
|
+
#else
|
470
|
+
/* enable GC-able symbols here: */
|
471
|
+
result = rb_str_intern(rb_str_new(b->read_buffer, length));
|
467
472
|
#endif
|
468
473
|
/* todo: rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc) */
|
469
474
|
} else {
|
data/ext/cbor/compat.h
CHANGED
@@ -105,6 +105,9 @@
|
|
105
105
|
# endif
|
106
106
|
#endif
|
107
107
|
|
108
|
+
|
109
|
+
#ifndef HAVE_RB_INTEGER_UNPACK
|
110
|
+
|
108
111
|
/* More MRI 1.8 */
|
109
112
|
#ifndef RBIGNUM_LEN
|
110
113
|
#define RBIGNUM_LEN(b) (RBIGNUM(b)->len)
|
@@ -122,6 +125,8 @@
|
|
122
125
|
#define rb_big_new(len, sign) rb_funcall(INT2FIX(1),rb_intern("<<"),1,INT2FIX(len > 0 ? ((len) * SIZEOF_BDIGITS * 8) - 1 : 0));
|
123
126
|
#endif
|
124
127
|
|
128
|
+
#endif
|
129
|
+
|
125
130
|
#ifndef RB_TYPE_P
|
126
131
|
#define RB_TYPE_P(obj, type) (TYPE(obj) == (type))
|
127
132
|
#endif
|
data/ext/cbor/extconf.rb
CHANGED
@@ -5,6 +5,9 @@ have_header("st.h")
|
|
5
5
|
have_func("rb_str_replace", ["ruby.h"])
|
6
6
|
have_func("rb_big_new", ["ruby.h"])
|
7
7
|
have_func("rb_intern_str", ["ruby.h"])
|
8
|
+
have_func("rb_sym2str", ["ruby.h"])
|
9
|
+
have_func("rb_str_intern", ["ruby.h"])
|
10
|
+
have_func("rb_integer_unpack", ["ruby.h"])
|
8
11
|
|
9
12
|
$CFLAGS << %[ -I.. -Wall -O3 -g -std=c99]
|
10
13
|
#$CFLAGS << %[ -DDISABLE_RMEM]
|
data/ext/cbor/packer.h
CHANGED
@@ -80,7 +80,7 @@ static inline void cbor_encoder_write_head(msgpack_packer_t* pk, unsigned int ib
|
|
80
80
|
{
|
81
81
|
if (n < 24) {
|
82
82
|
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
|
83
|
-
msgpack_buffer_write_1(PACKER_BUFFER_(pk), ib + n);
|
83
|
+
msgpack_buffer_write_1(PACKER_BUFFER_(pk), ib + (int)n);
|
84
84
|
} else if (n < 256) {
|
85
85
|
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3);
|
86
86
|
msgpack_buffer_write_2(PACKER_BUFFER_(pk), ib + 24, n);
|
@@ -216,6 +216,10 @@ static inline void msgpack_packer_write_string_value(msgpack_packer_t* pk, VALUE
|
|
216
216
|
|
217
217
|
static inline void msgpack_packer_write_symbol_value(msgpack_packer_t* pk, VALUE v)
|
218
218
|
{
|
219
|
+
#ifdef HAVE_RB_SYM2STR
|
220
|
+
/* rb_sym2str is added since MRI 2.2.0 */
|
221
|
+
msgpack_packer_write_string_value(pk, rb_sym2str(v));
|
222
|
+
#else
|
219
223
|
const char* name = rb_id2name(SYM2ID(v));
|
220
224
|
/* actual return type of strlen is size_t */
|
221
225
|
unsigned long len = strlen(name);
|
@@ -225,6 +229,7 @@ static inline void msgpack_packer_write_symbol_value(msgpack_packer_t* pk, VALUE
|
|
225
229
|
}
|
226
230
|
cbor_encoder_write_head(pk, IB_TEXT, len);
|
227
231
|
msgpack_buffer_append(PACKER_BUFFER_(pk), name, len);
|
232
|
+
#endif
|
228
233
|
}
|
229
234
|
|
230
235
|
static inline void msgpack_packer_write_fixnum_value(msgpack_packer_t* pk, VALUE v)
|
@@ -244,7 +249,26 @@ static inline void msgpack_packer_write_bignum_value(msgpack_packer_t* pk, VALUE
|
|
244
249
|
v = rb_funcall(v, rb_intern("~"), 0); /* should be rb_big_neg(), but that is static. */
|
245
250
|
ib = IB_NEGATIVE;
|
246
251
|
}
|
247
|
-
|
252
|
+
|
253
|
+
|
254
|
+
#ifdef HAVE_RB_INTEGER_UNPACK
|
255
|
+
len = rb_absint_size(v, NULL);
|
256
|
+
|
257
|
+
if (len > SIZEOF_LONG_LONG) { /* i.e., need real bignum */
|
258
|
+
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
|
259
|
+
msgpack_buffer_write_1(PACKER_BUFFER_(pk), IB_BIGNUM + IB_NEGFLAG_AS_BIT(ib));
|
260
|
+
cbor_encoder_write_head(pk, IB_BYTES, len);
|
261
|
+
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), len);
|
262
|
+
|
263
|
+
char buf[len]; /* XXX */
|
264
|
+
if (rb_integer_pack(v, buf, len, 1, 0, INTEGER_PACK_BIG_ENDIAN) != 1)
|
265
|
+
rb_raise(rb_eRangeError, "cbor rb_integer_pack() error");
|
266
|
+
|
267
|
+
msgpack_buffer_append(PACKER_BUFFER_(pk), buf, len);
|
268
|
+
|
269
|
+
#else
|
270
|
+
|
271
|
+
len = RBIGNUM_LEN(v);
|
248
272
|
if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS) {
|
249
273
|
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1);
|
250
274
|
msgpack_buffer_write_1(PACKER_BUFFER_(pk), IB_BIGNUM + IB_NEGFLAG_AS_BIT(ib));
|
@@ -296,6 +320,7 @@ static inline void msgpack_packer_write_bignum_value(msgpack_packer_t* pk, VALUE
|
|
296
320
|
}
|
297
321
|
#endif
|
298
322
|
}
|
323
|
+
#endif
|
299
324
|
} else {
|
300
325
|
cbor_encoder_write_head(pk, ib, rb_big2ull(v));
|
301
326
|
}
|
data/ext/cbor/sysdep.h
CHANGED
@@ -121,6 +121,8 @@
|
|
121
121
|
/* TODO default impl for _msgpack_bsp32 */
|
122
122
|
#endif
|
123
123
|
|
124
|
+
#ifndef HAVE_RB_INTEGER_UNPACK
|
125
|
+
|
124
126
|
#if SIZEOF_BDIGITS == 2
|
125
127
|
#define NTOHBDIGIT _msgpack_be16
|
126
128
|
#elif SIZEOF_BDIGITS == 4
|
@@ -133,3 +135,5 @@
|
|
133
135
|
|
134
136
|
#endif
|
135
137
|
|
138
|
+
#endif
|
139
|
+
|
data/ext/cbor/unpacker.c
CHANGED
@@ -422,7 +422,7 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
422
422
|
union {
|
423
423
|
uint32_t u32;
|
424
424
|
float f;
|
425
|
-
} castbuf = { val };
|
425
|
+
} castbuf = { (uint32_t)val };
|
426
426
|
return object_complete(uk, rb_float_new(castbuf.f));
|
427
427
|
}
|
428
428
|
case AI_8: // double
|
@@ -476,6 +476,7 @@ int msgpack_unpacker_read_container_header(msgpack_unpacker_t* uk, uint64_t* res
|
|
476
476
|
return PRIMITIVE_UNEXPECTED_TYPE; /* including INDEF! */
|
477
477
|
}
|
478
478
|
|
479
|
+
reset_head_byte(uk);
|
479
480
|
return 0;
|
480
481
|
}
|
481
482
|
|
@@ -514,11 +515,19 @@ static VALUE msgpack_unpacker_process_tag(uint64_t tag, VALUE v) {
|
|
514
515
|
#endif
|
515
516
|
{
|
516
517
|
char *sp = RSTRING_PTR(v);
|
517
|
-
|
518
|
+
size_t slen = RSTRING_LEN(v);
|
518
519
|
while (slen && *sp == 0) {
|
519
520
|
slen--;
|
520
521
|
sp++;
|
521
522
|
}
|
523
|
+
|
524
|
+
#ifdef HAVE_RB_INTEGER_UNPACK
|
525
|
+
|
526
|
+
res = rb_integer_unpack(sp, slen, 1, 0, INTEGER_PACK_BIG_ENDIAN);
|
527
|
+
/* (const void *words, size_t numwords, size_t wordsize, size_t nails, int flags); */
|
528
|
+
|
529
|
+
#else
|
530
|
+
|
522
531
|
#ifndef CANT_DO_BIGNUMS_FAST_ON_THIS_PLATFORM
|
523
532
|
int ndig = (slen + SIZEOF_BDIGITS - 1)/SIZEOF_BDIGITS;
|
524
533
|
res = rb_big_new(ndig, 1);
|
@@ -554,6 +563,7 @@ static VALUE msgpack_unpacker_process_tag(uint64_t tag, VALUE v) {
|
|
554
563
|
res = rb_cstr2inum(hex, 16);
|
555
564
|
xfree(hex);
|
556
565
|
}
|
566
|
+
#endif
|
557
567
|
#endif
|
558
568
|
if (tag == TAG_BIGNUM) /* non-negative */
|
559
569
|
#ifndef CANT_DO_BIGNUMS_FAST_ON_THIS_PLATFORM
|
@@ -626,7 +636,7 @@ int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth)
|
|
626
636
|
continue;
|
627
637
|
case STACK_TYPE_STRING_INDEF:
|
628
638
|
if (r == PRIMITIVE_BREAK) {
|
629
|
-
object_complete_string(uk, top->object, top->count); /* use count as textflag */
|
639
|
+
object_complete_string(uk, top->object, (int)top->count); /* use count as textflag */
|
630
640
|
goto done;
|
631
641
|
}
|
632
642
|
if (!RB_TYPE_P(uk->last_object, T_STRING))
|
data/lib/cbor/version.rb
CHANGED
data/spec/format_spec.rb
CHANGED
@@ -231,6 +231,17 @@ describe MessagePack do
|
|
231
231
|
match obj, "\xA0"
|
232
232
|
end
|
233
233
|
|
234
|
+
it "very simple bignums" do
|
235
|
+
CBOR.decode("\xc2\x40").should == 0
|
236
|
+
CBOR.decode("\xc2\x41\x00").should == 0
|
237
|
+
CBOR.decode("\xc2\x41a").should == 97
|
238
|
+
CBOR.decode("\xc2\x42aa").should == 24929
|
239
|
+
CBOR.decode("\xc3\x40").should == ~0
|
240
|
+
CBOR.decode("\xc3\x41\x00").should == ~0
|
241
|
+
CBOR.decode("\xc3\x41a").should == ~97
|
242
|
+
CBOR.decode("\xc3\x42aa").should == ~24929
|
243
|
+
end
|
244
|
+
|
234
245
|
it "0x982173487123985791827359872948752345" do
|
235
246
|
check_bn(0x982173487123985791827359872948752345, 0xc2)
|
236
247
|
check_bn(-0x982173487123985791827359872948752345, 0xc3)
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
|
+
require 'rubygems' # for 1.8
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |c|
|
5
|
+
c.syntax = [:should, :expect]
|
6
|
+
end
|
7
|
+
config.mock_with :rspec do |c|
|
8
|
+
c.syntax = [:should, :expect]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
1
13
|
class String
|
2
14
|
if ''.respond_to? :encode
|
3
15
|
def encode_as_utf8
|
4
16
|
encode(Encoding::UTF_8)
|
5
17
|
end
|
18
|
+
def force_as_utf8
|
19
|
+
force_encoding(Encoding::UTF_8)
|
20
|
+
end
|
6
21
|
unless String.instance_methods.include?(:b)
|
7
22
|
def b
|
8
23
|
dup.force_encoding(Encoding::BINARY)
|
@@ -12,10 +27,18 @@ class String
|
|
12
27
|
def encode_as_utf8
|
13
28
|
self # MRI 1.8
|
14
29
|
end
|
30
|
+
def force_as_utf8
|
31
|
+
self # MRI 1.8
|
32
|
+
end
|
15
33
|
def b
|
16
34
|
self
|
17
35
|
end
|
18
36
|
end
|
37
|
+
unless ''.respond_to? :clear
|
38
|
+
def clear
|
39
|
+
replace('')
|
40
|
+
end
|
41
|
+
end
|
19
42
|
def hexbytes(sep = '')
|
20
43
|
bytes.map{|x| "%02x" % x}.join(sep)
|
21
44
|
end
|
data/spec/unpacker_spec.rb
CHANGED
@@ -24,11 +24,33 @@ describe Unpacker do
|
|
24
24
|
}.should raise_error(MessagePack::TypeError)
|
25
25
|
end
|
26
26
|
|
27
|
+
it 'read_array_header converts an array to value sequence' do
|
28
|
+
packer.write_array_header(2)
|
29
|
+
packer.write("e")
|
30
|
+
packer.write(1)
|
31
|
+
unpacker = Unpacker.new
|
32
|
+
unpacker.feed(packer.to_s)
|
33
|
+
unpacker.read_array_header.should == 2
|
34
|
+
unpacker.read.should == "e"
|
35
|
+
unpacker.read.should == 1
|
36
|
+
end
|
37
|
+
|
27
38
|
it 'read_map_header succeeds' do
|
28
39
|
unpacker.feed("\xa1")
|
29
40
|
unpacker.read_map_header.should == 1
|
30
41
|
end
|
31
42
|
|
43
|
+
it 'read_map_header converts an map to key-value sequence' do
|
44
|
+
packer.write_map_header(1)
|
45
|
+
packer.write("k")
|
46
|
+
packer.write("v")
|
47
|
+
unpacker = Unpacker.new
|
48
|
+
unpacker.feed(packer.to_s)
|
49
|
+
unpacker.read_map_header.should == 1
|
50
|
+
unpacker.read.should == "k"
|
51
|
+
unpacker.read.should == "v"
|
52
|
+
end
|
53
|
+
|
32
54
|
it 'read_map_header fails' do
|
33
55
|
unpacker.feed("\x81")
|
34
56
|
lambda {
|
@@ -144,14 +166,14 @@ describe Unpacker do
|
|
144
166
|
end
|
145
167
|
|
146
168
|
it 'frozen short strings' do
|
147
|
-
raw = sample_object.to_cbor.to_s.
|
169
|
+
raw = sample_object.to_cbor.to_s.force_as_utf8
|
148
170
|
lambda {
|
149
171
|
unpacker.feed_each(raw.freeze) { }
|
150
172
|
}.should_not raise_error
|
151
173
|
end
|
152
174
|
|
153
175
|
it 'frozen long strings' do
|
154
|
-
raw = (sample_object.to_cbor.to_s * 10240).
|
176
|
+
raw = (sample_object.to_cbor.to_s * 10240).force_as_utf8
|
155
177
|
lambda {
|
156
178
|
unpacker.feed_each(raw.freeze) { }
|
157
179
|
}.should_not raise_error
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann, standing on the tall shoulders of Sadayuki Furuhashi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
178
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.4.5
|
180
180
|
signing_key:
|
181
181
|
specification_version: 4
|
182
182
|
summary: CBOR, Concise Binary Object Representation.
|