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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21f656cdac9fe221206c29eff87e7c068a4460a1cc7922eb25858ec0d657d840
4
- data.tar.gz: 8eca414c087981d96cf919e96a7554dfa4bdb9336af39f56b4950410d815a9bc
3
+ metadata.gz: c7f2b827b6b7e4a2b1cb996da1f9218cd2877d1fc68db4e15fbe22f04a78b368
4
+ data.tar.gz: b9673591f5634d59199e0364ac28f075e18c9f42286b1bdd0ac5d5b3c7e5eeb4
5
5
  SHA512:
6
- metadata.gz: 8d0e8bdad84fb2e8995680dcf9ca7330868101bc196f4ff2d6cde7ec393b9c1c819a1a756dd939e002a8be1b35178ccce8328ef65e54ed85c915d6a5d6801ab9
7
- data.tar.gz: 739cf3c06238c1e7601d52d60e625eec4bfa703c3ffb1503f6ed670200801c63c7913c58b30af860aed907ea5adab0ccbfb2981332b533790d33374e82a9eabb
6
+ metadata.gz: e167d6a4a84f9b7aeac11fe2023c91fc09c322194e783b42201a5d9dffdc090734e8e8efb70fdbe946c88553ba6f9ef6700634f5b96314c9cf1b921d4502c527
7
+ data.tar.gz: 16bedc238561494e96ef5e7d5c6b8db56cb8506a9dfebe8ac780243a1b9edd716bbb07e8ca361df37a9700960daba2cf3037c67573bfa3c225ec646085ac1521
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IOStruct
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
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 = [len.to_i, 1].max
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
@@ -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')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iostruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin