asciipack 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/ext/asciipack/unpacker.c +4 -6
- data/lib/asciipack/version.rb +1 -1
- data/spec/bench.rb +0 -1
- data/spec/format_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1691b37fbd3296bc64c616a4e4df2b4cd6889a07
|
4
|
+
data.tar.gz: a5e015148d90c132932e3fbed05c6379ce6f28ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ce558462f2af4a6c07422a912bb78bcb65220e3ea49570ec317e997f98375258ec288fc099ca3531271432d901eb4cc7a429c6f6d58244386809997f2f8709
|
7
|
+
data.tar.gz: ecb62c4e1f7e0e79db03569de77649a67c35338de4db391f091455cf93cdd8c7c8fe7a65669e6b06d489a53de3d85bc41d2f9c175910a2f98473d4b219a740b2
|
data/ext/asciipack/unpacker.c
CHANGED
@@ -56,8 +56,7 @@ to_i16all (unpacker_t* ptr, int len)
|
|
56
56
|
{
|
57
57
|
uint64_t ret = 0;
|
58
58
|
while (len--) {
|
59
|
-
ret += to_i16(*ptr->ch);
|
60
|
-
ptr->ch++;
|
59
|
+
ret += to_i16(*ptr->ch++);
|
61
60
|
if (len != 0) ret = ret << 4;
|
62
61
|
}
|
63
62
|
return ret;
|
@@ -102,6 +101,7 @@ Unpacker_str (unpacker_t* ptr, size_t len)
|
|
102
101
|
|
103
102
|
VALUE str = rb_str_new(head, len);
|
104
103
|
rb_funcall(str, rb_intern("force_encoding"), 1, rb_str_new2("utf-8"));
|
104
|
+
ptr->ch += len;
|
105
105
|
return str;
|
106
106
|
}
|
107
107
|
|
@@ -133,9 +133,7 @@ Unpacker_read (unpacker_t* ptr)
|
|
133
133
|
{
|
134
134
|
uint64_t num;
|
135
135
|
|
136
|
-
ptr->ch
|
137
|
-
|
138
|
-
switch (*(ptr->ch - 1)) {
|
136
|
+
switch (*ptr->ch++) {
|
139
137
|
case 'a': // int 4
|
140
138
|
num = Unpacker_int(ptr, 1);
|
141
139
|
return INT2FIX(num);
|
@@ -267,7 +265,7 @@ Unpacker_read (unpacker_t* ptr)
|
|
267
265
|
case 'Y': return Qtrue;
|
268
266
|
}
|
269
267
|
|
270
|
-
rb_raise(rb_eArgError, "undefined type:%c", *(ptr->ch));
|
268
|
+
rb_raise(rb_eArgError, "undefined type:%c,data:%s,at:%ld", *(ptr->ch), ptr->buffer, ptr->ch - ptr->buffer);
|
271
269
|
return Qnil;
|
272
270
|
}
|
273
271
|
|
data/lib/asciipack/version.rb
CHANGED
data/spec/bench.rb
CHANGED
data/spec/format_spec.rb
CHANGED
@@ -4,7 +4,9 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe AsciiPack do
|
6
6
|
it "intro" do
|
7
|
-
|
7
|
+
demo = {"compact"=>true,"binary"=>0}
|
8
|
+
expect(AsciiPack.pack(demo)).to eq('r2NcompactYMbinary0')
|
9
|
+
expect(AsciiPack.unpack('r2NcompactYMbinary0')).to eq(demo)
|
8
10
|
end
|
9
11
|
|
10
12
|
it "int 4" do
|
@@ -70,6 +72,7 @@ describe AsciiPack do
|
|
70
72
|
check_each_other(1.0000000000000004, T.float64 + '3ff0000000000002')
|
71
73
|
check_each_other(1/3.0, T.float64 + '3fd5555555555555')
|
72
74
|
expect(AsciiPack.pack(Float::NAN)).to eq(T.float64 + '7ff8000000000000')
|
75
|
+
expect(AsciiPack.unpack(T.float64 + '7ff8000000000000').nan?).to be true
|
73
76
|
check_each_other(1 / 0.0, T.float64 + '7ff0000000000000')
|
74
77
|
check_each_other(-1 / 0.0, T.float64 + 'fff0000000000000')
|
75
78
|
end
|
@@ -89,10 +92,8 @@ describe AsciiPack do
|
|
89
92
|
end
|
90
93
|
|
91
94
|
it "str 16" do
|
92
|
-
100.times {
|
93
95
|
format "a" * 0x100, T.str16, 5 + 0x100
|
94
96
|
format "a" * 0xffff, T.str16, 5 + 0xffff
|
95
|
-
}
|
96
97
|
end
|
97
98
|
|
98
99
|
it "str 32" do
|
@@ -148,8 +149,7 @@ describe AsciiPack do
|
|
148
149
|
1000.times {
|
149
150
|
array = [array]
|
150
151
|
}
|
151
|
-
|
152
|
-
expect(AsciiPack.unpack(ap)).to eq(array)
|
152
|
+
check_each_other(array, AsciiPack.pack(array))
|
153
153
|
end
|
154
154
|
|
155
155
|
it "nil" do
|