bindata 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bindata might be problematic. Click here for more details.
- data/ChangeLog +9 -3
- data/README +10 -0
- data/examples/gzip.rb +32 -45
- data/lib/bindata.rb +2 -1
- data/lib/bindata/array.rb +51 -51
- data/lib/bindata/base.rb +69 -39
- data/lib/bindata/bits.rb +807 -0
- data/lib/bindata/choice.rb +3 -3
- data/lib/bindata/float.rb +2 -2
- data/lib/bindata/int.rb +5 -5
- data/lib/bindata/io.rb +192 -0
- data/lib/bindata/rest.rb +1 -1
- data/lib/bindata/single.rb +42 -53
- data/lib/bindata/string.rb +1 -1
- data/lib/bindata/stringz.rb +1 -1
- data/lib/bindata/struct.rb +45 -37
- data/spec/array_spec.rb +37 -0
- data/spec/base_spec.rb +34 -17
- data/spec/bits_spec.rb +139 -0
- data/spec/io_spec.rb +288 -0
- data/spec/single_spec.rb +4 -3
- data/spec/string_spec.rb +2 -1
- data/spec/struct_spec.rb +25 -0
- metadata +6 -2
data/spec/single_spec.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__)) + '/spec_common'
|
4
|
+
require 'bindata/io'
|
4
5
|
require 'bindata/single'
|
5
6
|
|
6
7
|
# An implementation of a unsigned 4 byte integer.
|
7
8
|
class ConcreteSingle < BinData::Single
|
8
9
|
def val_to_str(val) [val].pack("V") end
|
9
|
-
def read_val(io) readbytes(
|
10
|
+
def read_val(io) io.readbytes(4).unpack("V")[0] end
|
10
11
|
def sensible_default() 0 end
|
11
12
|
|
12
13
|
def in_read?() @in_read end
|
@@ -22,7 +23,7 @@ describe BinData::Single do
|
|
22
23
|
it "should conform to rule 2 for returning a value" do
|
23
24
|
io = StringIO.new([42].pack("V"))
|
24
25
|
data = ConcreteSingle.new(:value => 5)
|
25
|
-
data.do_read(io)
|
26
|
+
data.do_read(BinData::IO.new(io))
|
26
27
|
data.should be_in_read
|
27
28
|
data.value.should == 42
|
28
29
|
end
|
@@ -159,7 +160,7 @@ describe BinData::Single, "with :value" do
|
|
159
160
|
|
160
161
|
it "should change during reading" do
|
161
162
|
io = StringIO.new([56].pack("V"))
|
162
|
-
@data.do_read(io)
|
163
|
+
@data.do_read(BinData::IO.new(io))
|
163
164
|
@data.value.should == 56
|
164
165
|
@data.done_read
|
165
166
|
end
|
data/spec/string_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__)) + '/spec_common'
|
4
|
+
require 'bindata/io'
|
4
5
|
require 'bindata/string'
|
5
6
|
|
6
7
|
describe BinData::String, "with mutually exclusive parameters" do
|
@@ -146,7 +147,7 @@ describe BinData::String, "with :read_length and :value" do
|
|
146
147
|
it "should return read value before calling done_read" do
|
147
148
|
io = StringIO.new("ABCDEFGHIJKLMNOPQRST")
|
148
149
|
|
149
|
-
@str.do_read(io)
|
150
|
+
@str.do_read(BinData::IO.new(io))
|
150
151
|
@str.value.should == "ABCDE"
|
151
152
|
|
152
153
|
@str.done_read
|
data/spec/struct_spec.rb
CHANGED
@@ -254,3 +254,28 @@ describe BinData::Struct, "with an endian defined" do
|
|
254
254
|
io.read.should == expected
|
255
255
|
end
|
256
256
|
end
|
257
|
+
|
258
|
+
describe BinData::Struct, "with bit fields" do
|
259
|
+
before(:each) do
|
260
|
+
@params = { :fields => [ [:bit1le, :a], [:bit2le, :b] ] }
|
261
|
+
@obj = BinData::Struct.new(@params)
|
262
|
+
@obj.a = 1
|
263
|
+
@obj.b = 2
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should return num_bytes" do
|
267
|
+
@obj.num_bytes.should == 1
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should write" do
|
271
|
+
@obj.to_s.should == [0b0000_0101].pack("C")
|
272
|
+
end
|
273
|
+
|
274
|
+
it "should read" do
|
275
|
+
str = [0b0000_0110].pack("C")
|
276
|
+
@obj.read(str)
|
277
|
+
@obj.a.should == 0
|
278
|
+
@obj.b.should == 3
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: bindata
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.9.
|
7
|
-
date: 2008-06-
|
6
|
+
version: 0.9.1
|
7
|
+
date: 2008-06-15 00:00:00 +08:00
|
8
8
|
summary: A declarative way to read and write binary file formats
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- README
|
38
38
|
- examples/gzip.rb
|
39
39
|
- spec/registry_spec.rb
|
40
|
+
- spec/bits_spec.rb
|
40
41
|
- spec/sanitize_spec.rb
|
41
42
|
- spec/array_spec.rb
|
42
43
|
- spec/float_spec.rb
|
@@ -51,11 +52,13 @@ files:
|
|
51
52
|
- spec/base_spec.rb
|
52
53
|
- spec/single_value_spec.rb
|
53
54
|
- spec/int_spec.rb
|
55
|
+
- spec/io_spec.rb
|
54
56
|
- spec/stringz_spec.rb
|
55
57
|
- lib/bindata.rb
|
56
58
|
- lib/bindata
|
57
59
|
- lib/bindata/lazy.rb
|
58
60
|
- lib/bindata/sanitize.rb
|
61
|
+
- lib/bindata/io.rb
|
59
62
|
- lib/bindata/string.rb
|
60
63
|
- lib/bindata/int.rb
|
61
64
|
- lib/bindata/multi_value.rb
|
@@ -68,6 +71,7 @@ files:
|
|
68
71
|
- lib/bindata/single.rb
|
69
72
|
- lib/bindata/base.rb
|
70
73
|
- lib/bindata/array.rb
|
74
|
+
- lib/bindata/bits.rb
|
71
75
|
- lib/bindata/float.rb
|
72
76
|
test_files: []
|
73
77
|
|