bindata 1.1.0 → 1.2.0
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 +7 -0
- data/README +32 -1167
- data/lib/bindata.rb +3 -3
- data/lib/bindata/array.rb +5 -6
- data/lib/bindata/base.rb +40 -58
- data/lib/bindata/base_primitive.rb +7 -11
- data/lib/bindata/bits.rb +47 -44
- data/lib/bindata/choice.rb +7 -11
- data/lib/bindata/deprecated.rb +17 -2
- data/lib/bindata/dsl.rb +332 -0
- data/lib/bindata/float.rb +48 -50
- data/lib/bindata/int.rb +66 -88
- data/lib/bindata/params.rb +112 -59
- data/lib/bindata/primitive.rb +8 -88
- data/lib/bindata/record.rb +11 -99
- data/lib/bindata/registry.rb +16 -3
- data/lib/bindata/rest.rb +1 -1
- data/lib/bindata/sanitize.rb +71 -53
- data/lib/bindata/skip.rb +2 -1
- data/lib/bindata/string.rb +3 -3
- data/lib/bindata/stringz.rb +1 -1
- data/lib/bindata/struct.rb +21 -20
- data/lib/bindata/trace.rb +8 -0
- data/lib/bindata/wrapper.rb +13 -69
- data/manual.haml +2 -2
- data/spec/array_spec.rb +1 -1
- data/spec/base_primitive_spec.rb +4 -4
- data/spec/base_spec.rb +19 -6
- data/spec/bits_spec.rb +5 -1
- data/spec/choice_spec.rb +13 -2
- data/spec/deprecated_spec.rb +31 -0
- data/spec/example.rb +5 -1
- data/spec/io_spec.rb +2 -4
- data/spec/lazy_spec.rb +10 -5
- data/spec/primitive_spec.rb +13 -5
- data/spec/record_spec.rb +149 -45
- data/spec/registry_spec.rb +18 -6
- data/spec/spec_common.rb +31 -6
- data/spec/string_spec.rb +0 -1
- data/spec/stringz_spec.rb +4 -4
- data/spec/struct_spec.rb +2 -2
- data/spec/system_spec.rb +26 -19
- data/spec/wrapper_spec.rb +52 -4
- data/tasks/manual.rake +1 -1
- data/tasks/pkg.rake +13 -0
- metadata +121 -46
- data/TODO +0 -3
data/spec/string_spec.rb
CHANGED
data/spec/stringz_spec.rb
CHANGED
@@ -49,14 +49,14 @@ describe BinData::Stringz, "when reading" do
|
|
49
49
|
io = StringIO.new("abcd\0xyz\0")
|
50
50
|
@str.read(io)
|
51
51
|
@str.value.should == "abcd"
|
52
|
-
io.
|
52
|
+
io.pos.should == 5
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should handle a zero length string" do
|
56
56
|
io = StringIO.new("\0abcd")
|
57
57
|
@str.read(io)
|
58
58
|
@str.value.should == ""
|
59
|
-
io.
|
59
|
+
io.pos.should == 1
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should fail if no zero byte is found" do
|
@@ -64,7 +64,7 @@ describe BinData::Stringz, "when reading" do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe BinData::Stringz, "
|
67
|
+
describe BinData::Stringz, "when setting the value" do
|
68
68
|
before(:each) do
|
69
69
|
@str = BinData::Stringz.new
|
70
70
|
end
|
@@ -116,7 +116,7 @@ describe BinData::Stringz, "with max_length" do
|
|
116
116
|
io = StringIO.new("abcdefg\0xyz")
|
117
117
|
@str.read(io)
|
118
118
|
@str.value.should == "abcd"
|
119
|
-
io.
|
119
|
+
io.pos.should == 5
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should accept values less than max_length" do
|
data/spec/struct_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe BinData::Struct, "when initializing" do
|
|
8
8
|
params = {:fields => [[:non_registered_type, :a]]}
|
9
9
|
lambda {
|
10
10
|
BinData::Struct.new(params)
|
11
|
-
}.should raise_error(BinData::
|
11
|
+
}.should raise_error(BinData::UnRegisteredTypeError)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should fail on duplicate names" do
|
@@ -107,7 +107,7 @@ describe BinData::Struct, "with multiple fields" do
|
|
107
107
|
it "should return num_bytes" do
|
108
108
|
@obj.a.num_bytes.should == 1
|
109
109
|
@obj.b.num_bytes.should == 1
|
110
|
-
@obj.num_bytes.should
|
110
|
+
@obj.num_bytes.should == 2
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should identify accepted parameters" do
|
data/spec/system_spec.rb
CHANGED
@@ -67,17 +67,17 @@ describe BinData::Record, "with choice field" do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
class RecordWithChoiceField < BinData::Record
|
70
|
-
choice :x, :
|
70
|
+
choice :x, :selection => 0 do
|
71
|
+
tuple_record
|
72
|
+
end
|
71
73
|
end
|
72
74
|
|
73
75
|
class RecordWithNestedChoiceField < BinData::Record
|
74
|
-
choice :x, :
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
],
|
80
|
-
:selection => 0
|
76
|
+
choice :x, :selection => 0 do
|
77
|
+
choice :selection => 0 do
|
78
|
+
tuple_record
|
79
|
+
end
|
80
|
+
end
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should treat choice object transparently " do
|
@@ -174,10 +174,9 @@ describe "Tracing" do
|
|
174
174
|
|
175
175
|
io = StringIO.new
|
176
176
|
BinData::trace_reading(io) { arr.read("\x01\x02\x03\x04\x05") }
|
177
|
-
io.rewind
|
178
177
|
|
179
178
|
expected = (0..4).collect { |i| "obj[#{i}] => #{i + 1}\n" }.join("")
|
180
|
-
io.
|
179
|
+
io.value.should == expected
|
181
180
|
end
|
182
181
|
|
183
182
|
it "should trace custom single values" do
|
@@ -191,9 +190,8 @@ describe "Tracing" do
|
|
191
190
|
|
192
191
|
io = StringIO.new
|
193
192
|
BinData::trace_reading(io) { obj.read("\x01") }
|
194
|
-
io.rewind
|
195
193
|
|
196
|
-
io.
|
194
|
+
io.value.should == ["obj-internal-.ex => 1\n", "obj => 1\n"].join("")
|
197
195
|
end
|
198
196
|
|
199
197
|
it "should trace choice selection" do
|
@@ -201,31 +199,39 @@ describe "Tracing" do
|
|
201
199
|
|
202
200
|
io = StringIO.new
|
203
201
|
BinData::trace_reading(io) { obj.read("\x01") }
|
204
|
-
io.rewind
|
205
202
|
|
206
|
-
io.
|
203
|
+
io.value.should == ["obj-selection- => 0\n", "obj => 1\n"].join("")
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should trim long trace values" do
|
207
|
+
obj = BinData::String.new(:read_length => 40)
|
208
|
+
|
209
|
+
io = StringIO.new
|
210
|
+
BinData::trace_reading(io) { obj.read("0000000000111111111122222222223333333333") }
|
211
|
+
|
212
|
+
io.value.should == "obj => \"000000000011111111112222222222...\n"
|
207
213
|
end
|
208
214
|
end
|
209
215
|
|
210
|
-
describe "Forward referencing with
|
211
|
-
class
|
216
|
+
describe "Forward referencing with Primitive" do
|
217
|
+
class FRPrimitive < BinData::Record
|
212
218
|
uint8 :len, :value => lambda { data.length }
|
213
219
|
string :data, :read_length => :len
|
214
220
|
end
|
215
221
|
|
216
222
|
it "should initialise" do
|
217
|
-
@obj =
|
223
|
+
@obj = FRPrimitive.new
|
218
224
|
@obj.snapshot.should == {"len" => 0, "data" => ""}
|
219
225
|
end
|
220
226
|
|
221
227
|
it "should read" do
|
222
|
-
@obj =
|
228
|
+
@obj = FRPrimitive.new
|
223
229
|
@obj.read("\x04test")
|
224
230
|
@obj.snapshot.should == {"len" => 4, "data" => "test"}
|
225
231
|
end
|
226
232
|
|
227
233
|
it "should set value" do
|
228
|
-
@obj =
|
234
|
+
@obj = FRPrimitive.new
|
229
235
|
@obj.data = "hello"
|
230
236
|
@obj.snapshot.should == {"len" => 5, "data" => "hello"}
|
231
237
|
end
|
@@ -280,3 +286,4 @@ describe BinData::Record, "with custom sized integers" do
|
|
280
286
|
CustomIntRecord.read(str).should == {"a" => 5}
|
281
287
|
end
|
282
288
|
end
|
289
|
+
|
data/spec/wrapper_spec.rb
CHANGED
@@ -10,7 +10,30 @@ describe BinData::Wrapper, "with errors" do
|
|
10
10
|
uint8
|
11
11
|
uint8
|
12
12
|
end
|
13
|
-
}.should
|
13
|
+
}.should raise_error_on_line(SyntaxError, 3) { |err|
|
14
|
+
err.message.should == "attempting to wrap more than one type in #{WrappedMultipleTypes}"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should fail if wrapped type has a name" do
|
19
|
+
lambda {
|
20
|
+
class WrappedWithName < BinData::Wrapper
|
21
|
+
uint8 :a
|
22
|
+
end
|
23
|
+
}.should raise_error_on_line(SyntaxError, 2) { |err|
|
24
|
+
err.message.should == "field must not have a name in #{WrappedWithName}"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should fail if no types to wrap" do
|
29
|
+
class WrappedNoTypes < BinData::Wrapper
|
30
|
+
end
|
31
|
+
|
32
|
+
lambda {
|
33
|
+
WrappedNoTypes.new
|
34
|
+
}.should raise_error(RuntimeError) { |err|
|
35
|
+
err.message.should == "no wrapped type was specified in #{WrappedNoTypes}"
|
36
|
+
}
|
14
37
|
end
|
15
38
|
end
|
16
39
|
|
@@ -23,18 +46,43 @@ describe BinData::Wrapper, "around a Primitive" do
|
|
23
46
|
|
24
47
|
it "should access custom parameter" do
|
25
48
|
obj = WrappedPrimitive.new
|
26
|
-
obj.
|
49
|
+
obj.assign(3)
|
27
50
|
obj.should == 3
|
28
51
|
end
|
29
52
|
|
30
53
|
it "should be able to override custom default parameter" do
|
31
54
|
obj = WrappedPrimitive.new(:a => 5)
|
32
|
-
obj.
|
55
|
+
obj.should == 5
|
33
56
|
end
|
34
57
|
|
35
58
|
it "should be able to override parameter" do
|
36
59
|
obj = WrappedPrimitive.new(:initial_value => 7)
|
37
|
-
obj.
|
60
|
+
obj.should == 7
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should clear" do
|
64
|
+
obj = WrappedPrimitive.new
|
65
|
+
obj.assign(3)
|
66
|
+
obj.should_not be_clear
|
67
|
+
|
68
|
+
obj.clear
|
69
|
+
obj.should be_clear
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should read" do
|
73
|
+
obj = WrappedPrimitive.new
|
74
|
+
obj.assign(3)
|
75
|
+
str = obj.to_binary_s
|
76
|
+
|
77
|
+
WrappedPrimitive.read(str).should == 3
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should respond_to and forward messages to the wrapped object" do
|
81
|
+
obj = WrappedPrimitive.new
|
82
|
+
obj.assign(5)
|
83
|
+
|
84
|
+
obj.should respond_to(:value)
|
85
|
+
obj.value.should == 5
|
38
86
|
end
|
39
87
|
end
|
40
88
|
|
data/tasks/manual.rake
CHANGED
data/tasks/pkg.rake
CHANGED
@@ -16,6 +16,19 @@ begin
|
|
16
16
|
s.extra_rdoc_files = ['NEWS']
|
17
17
|
s.rdoc_options << '--main' << 'NEWS'
|
18
18
|
s.files = PKG_FILES
|
19
|
+
s.add_development_dependency('rspec')
|
20
|
+
s.add_development_dependency('haml')
|
21
|
+
s.add_development_dependency('maruku')
|
22
|
+
s.add_development_dependency('syntax')
|
23
|
+
s.description = <<-END.gsub(/^ +/, "")
|
24
|
+
BinData provides an easy (and more readable) alternative to ruby's
|
25
|
+
#pack and #unpack methods.
|
26
|
+
|
27
|
+
It does this by providing a declarative way of specifying structured
|
28
|
+
binary data. This means the programmer specifies *what* the format
|
29
|
+
of the binary data is, and BinData works out *how* to read and write
|
30
|
+
data in this format.
|
31
|
+
END
|
19
32
|
end
|
20
33
|
|
21
34
|
Rake::GemPackageTask.new(SPEC) do |pkg|
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 31
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 1.2.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Dion Mendel
|
@@ -9,11 +15,74 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-07-09 00:00:00 +08:00
|
13
19
|
default_executable:
|
14
|
-
dependencies:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: haml
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: maruku
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: syntax
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
description: |
|
78
|
+
BinData provides an easy (and more readable) alternative to ruby's
|
79
|
+
#pack and #unpack methods.
|
80
|
+
|
81
|
+
It does this by providing a declarative way of specifying structured
|
82
|
+
binary data. This means the programmer specifies *what* the format
|
83
|
+
of the binary data is, and BinData works out *how* to read and write
|
84
|
+
data in this format.
|
15
85
|
|
16
|
-
description:
|
17
86
|
email: dion@lostrealm.com
|
18
87
|
executables: []
|
19
88
|
|
@@ -23,64 +92,64 @@ extra_rdoc_files:
|
|
23
92
|
- NEWS
|
24
93
|
files:
|
25
94
|
- COPYING
|
95
|
+
- ChangeLog
|
96
|
+
- GPL
|
97
|
+
- Rakefile
|
26
98
|
- INSTALL
|
27
99
|
- README
|
28
100
|
- NEWS
|
29
|
-
- GPL
|
30
|
-
- ChangeLog
|
31
|
-
- Rakefile
|
32
|
-
- TODO
|
33
|
-
- examples/ip_address.rb
|
34
101
|
- examples/gzip.rb
|
102
|
+
- examples/ip_address.rb
|
103
|
+
- spec/base_spec.rb
|
104
|
+
- spec/string_spec.rb
|
105
|
+
- spec/record_spec.rb
|
106
|
+
- spec/example.rb
|
107
|
+
- spec/primitive_spec.rb
|
108
|
+
- spec/stringz_spec.rb
|
109
|
+
- spec/float_spec.rb
|
35
110
|
- spec/io_spec.rb
|
36
|
-
- spec/
|
111
|
+
- spec/system_spec.rb
|
112
|
+
- spec/array_spec.rb
|
37
113
|
- spec/lazy_spec.rb
|
38
|
-
- spec/primitive_spec.rb
|
39
114
|
- spec/wrapper_spec.rb
|
40
|
-
- spec/
|
41
|
-
- spec/
|
42
|
-
- spec/string_spec.rb
|
43
|
-
- spec/stringz_spec.rb
|
44
|
-
- spec/choice_spec.rb
|
45
|
-
- spec/example.rb
|
115
|
+
- spec/struct_spec.rb
|
116
|
+
- spec/rest_spec.rb
|
46
117
|
- spec/base_primitive_spec.rb
|
47
|
-
- spec/
|
48
|
-
- spec/deprecated_spec.rb
|
49
|
-
- spec/base_spec.rb
|
118
|
+
- spec/registry_spec.rb
|
50
119
|
- spec/int_spec.rb
|
51
|
-
- spec/
|
52
|
-
- spec/record_spec.rb
|
53
|
-
- spec/float_spec.rb
|
120
|
+
- spec/bits_spec.rb
|
54
121
|
- spec/skip_spec.rb
|
55
|
-
- spec/
|
56
|
-
- spec/
|
57
|
-
-
|
58
|
-
- lib/bindata
|
59
|
-
- lib/bindata/
|
60
|
-
- lib/bindata/registry.rb
|
61
|
-
- lib/bindata/lazy.rb
|
122
|
+
- spec/choice_spec.rb
|
123
|
+
- spec/spec_common.rb
|
124
|
+
- spec/deprecated_spec.rb
|
125
|
+
- lib/bindata.rb
|
126
|
+
- lib/bindata/skip.rb
|
62
127
|
- lib/bindata/choice.rb
|
63
|
-
- lib/bindata/
|
128
|
+
- lib/bindata/dsl.rb
|
64
129
|
- lib/bindata/params.rb
|
65
|
-
- lib/bindata/
|
66
|
-
- lib/bindata/bits.rb
|
130
|
+
- lib/bindata/array.rb
|
67
131
|
- lib/bindata/trace.rb
|
68
|
-
- lib/bindata/
|
69
|
-
- lib/bindata/
|
132
|
+
- lib/bindata/struct.rb
|
133
|
+
- lib/bindata/lazy.rb
|
70
134
|
- lib/bindata/base.rb
|
71
|
-
- lib/bindata/skip.rb
|
72
|
-
- lib/bindata/rest.rb
|
73
|
-
- lib/bindata/string.rb
|
74
|
-
- lib/bindata/array.rb
|
75
135
|
- lib/bindata/stringz.rb
|
76
|
-
- lib/bindata/
|
136
|
+
- lib/bindata/string.rb
|
77
137
|
- lib/bindata/int.rb
|
78
138
|
- lib/bindata/io.rb
|
79
|
-
- lib/bindata.rb
|
80
|
-
-
|
81
|
-
-
|
139
|
+
- lib/bindata/base_primitive.rb
|
140
|
+
- lib/bindata/wrapper.rb
|
141
|
+
- lib/bindata/bits.rb
|
142
|
+
- lib/bindata/record.rb
|
143
|
+
- lib/bindata/primitive.rb
|
144
|
+
- lib/bindata/sanitize.rb
|
145
|
+
- lib/bindata/rest.rb
|
146
|
+
- lib/bindata/deprecated.rb
|
147
|
+
- lib/bindata/registry.rb
|
148
|
+
- lib/bindata/float.rb
|
82
149
|
- tasks/rspec.rake
|
83
150
|
- tasks/pkg.rake
|
151
|
+
- tasks/manual.rake
|
152
|
+
- tasks/rdoc.rake
|
84
153
|
- setup.rb
|
85
154
|
- manual.haml
|
86
155
|
has_rdoc: true
|
@@ -94,21 +163,27 @@ rdoc_options:
|
|
94
163
|
require_paths:
|
95
164
|
- lib
|
96
165
|
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
97
167
|
requirements:
|
98
168
|
- - ">="
|
99
169
|
- !ruby/object:Gem::Version
|
170
|
+
hash: 3
|
171
|
+
segments:
|
172
|
+
- 0
|
100
173
|
version: "0"
|
101
|
-
version:
|
102
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
103
176
|
requirements:
|
104
177
|
- - ">="
|
105
178
|
- !ruby/object:Gem::Version
|
179
|
+
hash: 3
|
180
|
+
segments:
|
181
|
+
- 0
|
106
182
|
version: "0"
|
107
|
-
version:
|
108
183
|
requirements: []
|
109
184
|
|
110
185
|
rubyforge_project: bindata
|
111
|
-
rubygems_version: 1.3.
|
186
|
+
rubygems_version: 1.3.7
|
112
187
|
signing_key:
|
113
188
|
specification_version: 3
|
114
189
|
summary: A declarative way to read and write binary file formats
|