iostruct 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iostruct/version.rb +1 -1
- data/lib/iostruct.rb +1 -1
- data/spec/iostruct_spec.rb +27 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f2b827b6b7e4a2b1cb996da1f9218cd2877d1fc68db4e15fbe22f04a78b368
|
4
|
+
data.tar.gz: b9673591f5634d59199e0364ac28f075e18c9f42286b1bdd0ac5d5b3c7e5eeb4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e167d6a4a84f9b7aeac11fe2023c91fc09c322194e783b42201a5d9dffdc090734e8e8efb70fdbe946c88553ba6f9ef6700634f5b96314c9cf1b921d4502c527
|
7
|
+
data.tar.gz: 16bedc238561494e96ef5e7d5c6b8db56cb8506a9dfebe8ac780243a1b9edd716bbb07e8ca361df37a9700960daba2cf3037c67573bfa3c225ec646085ac1521
|
data/lib/iostruct/version.rb
CHANGED
data/lib/iostruct.rb
CHANGED
@@ -57,7 +57,7 @@ module IOStruct
|
|
57
57
|
fields = []
|
58
58
|
fmt.scan(/([a-z])(\d*)/i).map do |type,len|
|
59
59
|
size, klass = FMTSPEC[type] || raise("Unknown field type #{type.inspect}")
|
60
|
-
len =
|
60
|
+
len = len.empty? ? 1 : len.to_i
|
61
61
|
case type
|
62
62
|
when 'A', 'a', 'x'
|
63
63
|
fields << FieldInfo.new(klass, size*len, offset) if klass
|
data/spec/iostruct_spec.rb
CHANGED
@@ -25,6 +25,33 @@ describe IOStruct do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
context "zero-length strings" do
|
29
|
+
let(:data) { [1, 2].pack('CC') }
|
30
|
+
let(:struct) { IOStruct.new('C a0 C', :a, :b, :c) }
|
31
|
+
|
32
|
+
it "deserializes" do
|
33
|
+
x = struct.read(data)
|
34
|
+
expect(x.a).to eq 1
|
35
|
+
expect(x.b).to eq ""
|
36
|
+
expect(x.c).to eq 2
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has correct size" do
|
40
|
+
expect(struct::SIZE).to eq 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it "reads correct number of bytes from IO" do
|
44
|
+
io = StringIO.new(data*2)
|
45
|
+
x = struct.read(io)
|
46
|
+
expect(io.pos).to eq 2
|
47
|
+
end
|
48
|
+
|
49
|
+
it "serializes" do
|
50
|
+
x = struct.read(data)
|
51
|
+
expect(x.pack).to eq data
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
28
55
|
it "skips on 'x'" do
|
29
56
|
a = [12345, 56789]
|
30
57
|
data = a.pack('L2')
|