bindata 1.5.1 → 1.6.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.rdoc +7 -0
- data/NEWS.rdoc +11 -0
- data/Rakefile +6 -1
- data/bindata.gemspec +2 -1
- data/doc/manual.md +17 -9
- data/examples/gzip.rb +2 -2
- data/examples/list.rb +2 -2
- data/lib/bindata/alignment.rb +4 -9
- data/lib/bindata/array.rb +57 -51
- data/lib/bindata/base.rb +13 -110
- data/lib/bindata/base_primitive.rb +130 -75
- data/lib/bindata/bits.rb +5 -7
- data/lib/bindata/choice.rb +24 -32
- data/lib/bindata/dsl.rb +1 -6
- data/lib/bindata/framework.rb +81 -0
- data/lib/bindata/int.rb +5 -7
- data/lib/bindata/name.rb +28 -0
- data/lib/bindata/offset.rb +42 -53
- data/lib/bindata/params.rb +33 -38
- data/lib/bindata/struct.rb +2 -6
- data/lib/bindata/trace.rb +16 -16
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +3 -3
- data/{spec/alignment_spec.rb → test/alignment_test.rb} +17 -16
- data/test/array_test.rb +371 -0
- data/test/base_primitive_test.rb +312 -0
- data/test/base_test.rb +183 -0
- data/{spec/bits_spec.rb → test/bits_test.rb} +59 -59
- data/test/choice_test.rb +260 -0
- data/{spec/spec_common.rb → test/common.rb} +33 -18
- data/test/count_bytes_remaining_test.rb +41 -0
- data/{spec/deprecated_spec.rb → test/deprecated_test.rb} +5 -7
- data/test/float_test.rb +72 -0
- data/{spec/int_spec.rb → test/int_test.rb} +34 -43
- data/{spec/io_spec.rb → test/io_test.rb} +70 -71
- data/{spec/lazy_spec.rb → test/lazy_test.rb} +38 -39
- data/test/offset_test.rb +93 -0
- data/test/params_test.rb +144 -0
- data/{spec/primitive_spec.rb → test/primitive_test.rb} +42 -54
- data/{spec/record_spec.rb → test/record_test.rb} +133 -154
- data/test/registry_test.rb +104 -0
- data/test/rest_test.rb +29 -0
- data/test/skip_test.rb +28 -0
- data/{spec/string_spec.rb → test/string_test.rb} +96 -97
- data/test/stringz_test.rb +127 -0
- data/{spec/struct_spec.rb → test/struct_test.rb} +119 -120
- data/{spec/system_spec.rb → test/system_test.rb} +66 -106
- metadata +39 -38
- data/lib/a.rb +0 -24
- data/spec/array_spec.rb +0 -331
- data/spec/base_primitive_spec.rb +0 -238
- data/spec/base_spec.rb +0 -376
- data/spec/choice_spec.rb +0 -263
- data/spec/count_bytes_remaining_spec.rb +0 -38
- data/spec/example.rb +0 -21
- data/spec/float_spec.rb +0 -37
- data/spec/registry_spec.rb +0 -108
- data/spec/rest_spec.rb +0 -26
- data/spec/skip_spec.rb +0 -27
- data/spec/stringz_spec.rb +0 -118
- data/tasks/rspec.rake +0 -17
@@ -1,8 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "
|
4
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "example"))
|
5
|
-
require 'bindata'
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "common"))
|
6
4
|
|
7
5
|
describe "lambdas with index" do
|
8
6
|
class NestedLambdaWithIndex < BinData::Record
|
@@ -13,18 +11,18 @@ describe "lambdas with index" do
|
|
13
11
|
arr = BinData::Array.new(:type =>
|
14
12
|
[:uint8, { :value => lambda { index * 10 } }],
|
15
13
|
:initial_length => 3)
|
16
|
-
arr.snapshot.
|
14
|
+
arr.snapshot.must_equal [0, 10, 20]
|
17
15
|
end
|
18
16
|
|
19
17
|
it "uses index of nearest containing array" do
|
20
18
|
arr = BinData::Array.new(:type => :nested_lambda_with_index,
|
21
19
|
:initial_length => 3)
|
22
|
-
arr.snapshot.
|
20
|
+
arr.snapshot.must_equal [{"a" => 0}, {"a" => 10}, {"a" => 20}]
|
23
21
|
end
|
24
22
|
|
25
23
|
it "fails if there is no containing array" do
|
26
|
-
|
27
|
-
|
24
|
+
obj = NestedLambdaWithIndex.new
|
25
|
+
lambda { obj.a.to_s }.must_raise NoMethodError
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
@@ -40,8 +38,8 @@ describe "lambdas with parent" do
|
|
40
38
|
nested_lambda_without_parent :x
|
41
39
|
end
|
42
40
|
|
43
|
-
|
44
|
-
|
41
|
+
obj = TestLambdaWithoutParent.new
|
42
|
+
obj.x.b.must_equal 5
|
45
43
|
end
|
46
44
|
|
47
45
|
it "accesses parent's parent when parent is specified" do
|
@@ -55,8 +53,8 @@ describe "lambdas with parent" do
|
|
55
53
|
nested_lambda_with_parent :x
|
56
54
|
end
|
57
55
|
|
58
|
-
|
59
|
-
|
56
|
+
obj = TestLambdaWithParent.new
|
57
|
+
obj.x.b.must_equal 3
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -82,58 +80,20 @@ describe BinData::Record, "with choice field" do
|
|
82
80
|
end
|
83
81
|
|
84
82
|
it "treats choice object transparently " do
|
85
|
-
|
83
|
+
obj = RecordWithChoiceField.new
|
86
84
|
|
87
|
-
|
85
|
+
obj.x.a.must_equal 3
|
88
86
|
end
|
89
87
|
|
90
88
|
it "treats nested choice object transparently " do
|
91
|
-
|
89
|
+
obj = RecordWithNestedChoiceField.new
|
92
90
|
|
93
|
-
|
91
|
+
obj.x.a.must_equal 3
|
94
92
|
end
|
95
93
|
|
96
94
|
it "has correct offset" do
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe BinData::Array, "of bits" do
|
103
|
-
let(:data) { BinData::Array.new(:type => :bit1, :initial_length => 15) }
|
104
|
-
|
105
|
-
it "reads" do
|
106
|
-
str = [0b0001_0100, 0b1000_1000].pack("CC")
|
107
|
-
data.read(str)
|
108
|
-
data[0].should == 0
|
109
|
-
data[1].should == 0
|
110
|
-
data[2].should == 0
|
111
|
-
data[3].should == 1
|
112
|
-
data[4].should == 0
|
113
|
-
data[5].should == 1
|
114
|
-
data[6].should == 0
|
115
|
-
data[7].should == 0
|
116
|
-
data[8].should == 1
|
117
|
-
data[9].should == 0
|
118
|
-
data[10].should == 0
|
119
|
-
data[11].should == 0
|
120
|
-
data[12].should == 1
|
121
|
-
data[13].should == 0
|
122
|
-
data[14].should == 0
|
123
|
-
end
|
124
|
-
|
125
|
-
it "writes" do
|
126
|
-
data[3] = 1
|
127
|
-
data.to_binary_s.should == [0b0001_0000, 0b0000_0000].pack("CC")
|
128
|
-
end
|
129
|
-
|
130
|
-
it "returns num_bytes" do
|
131
|
-
data.num_bytes.should == 2
|
132
|
-
end
|
133
|
-
|
134
|
-
it "has correct offset" do
|
135
|
-
data[7].offset.should == 0
|
136
|
-
data[8].offset.should == 1
|
95
|
+
obj = RecordWithNestedChoiceField.new
|
96
|
+
obj.x.b.offset.must_equal 2
|
137
97
|
end
|
138
98
|
end
|
139
99
|
|
@@ -169,60 +129,60 @@ describe BinData::Record, "containing bitfields" do
|
|
169
129
|
bit6 :e
|
170
130
|
end
|
171
131
|
|
172
|
-
|
132
|
+
let(:obj) { BitfieldRecord.new }
|
173
133
|
|
174
134
|
it "has correct num_bytes" do
|
175
|
-
|
135
|
+
obj.num_bytes.must_equal 5
|
176
136
|
end
|
177
137
|
|
178
138
|
it "reads across bitfield boundaries" do
|
179
|
-
|
139
|
+
obj.read [0b0111_0010, 0b0110_0101, 0b0010_1010, 0b1000_0101, 0b1000_0000].pack("CCCCC")
|
180
140
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
141
|
+
obj.a.w.must_equal 7
|
142
|
+
obj.b.must_equal [0, 0, 1, 0, 0, 1, 1, 0, 0]
|
143
|
+
obj.c.x.must_equal 2
|
144
|
+
obj.d.must_equal 954
|
145
|
+
obj.e.must_equal 11
|
186
146
|
end
|
187
147
|
|
188
148
|
it "writes across bitfield boundaries" do
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
149
|
+
obj.a.w = 3
|
150
|
+
obj.b[2] = 1
|
151
|
+
obj.b[5] = 1
|
152
|
+
obj.c.x = 1
|
153
|
+
obj.d = 850
|
154
|
+
obj.e = 35
|
155
|
+
obj.to_binary_s.must_equal [0b0011_0010, 0b0100_0011, 0b0000_1010, 0b0001_0001, 0b1000_0000].pack("CCCCC")
|
196
156
|
end
|
197
157
|
end
|
198
158
|
|
199
159
|
describe "Objects with debug_name" do
|
200
160
|
it "haves default name of obj" do
|
201
161
|
el = ExampleSingle.new
|
202
|
-
el.debug_name.
|
162
|
+
el.debug_name.must_equal "obj"
|
203
163
|
end
|
204
164
|
|
205
165
|
it "includes array index" do
|
206
166
|
arr = BinData::Array.new(:type => :example_single, :initial_length => 2)
|
207
|
-
arr[2].debug_name.
|
167
|
+
arr[2].debug_name.must_equal "obj[2]"
|
208
168
|
end
|
209
169
|
|
210
170
|
it "includes field name" do
|
211
171
|
s = BinData::Struct.new(:fields => [[:example_single, :a]])
|
212
|
-
s.a.debug_name.
|
172
|
+
s.a.debug_name.must_equal "obj.a"
|
213
173
|
end
|
214
174
|
|
215
175
|
it "delegates to choice" do
|
216
176
|
choice_params = {:choices => [:example_single], :selection => 0}
|
217
177
|
s = BinData::Struct.new(:fields => [[:choice, :a, choice_params]])
|
218
|
-
s.a.debug_name.
|
178
|
+
s.a.debug_name.must_equal "obj.a"
|
219
179
|
end
|
220
180
|
|
221
181
|
it "nests" do
|
222
182
|
nested_struct_params = {:fields => [[:example_single, :c]]}
|
223
183
|
struct_params = {:fields => [[:struct, :b, nested_struct_params]]}
|
224
184
|
s = BinData::Struct.new(:fields => [[:struct, :a, struct_params]])
|
225
|
-
s.a.b.c.debug_name.
|
185
|
+
s.a.b.c.debug_name.must_equal "obj.a.b.c"
|
226
186
|
end
|
227
187
|
end
|
228
188
|
|
@@ -234,7 +194,7 @@ describe "Tracing" do
|
|
234
194
|
BinData::trace_reading(io) { arr.read("\x01\x02\x03\x04\x05") }
|
235
195
|
|
236
196
|
expected = (0..4).collect { |i| "obj[#{i}] => #{i + 1}\n" }.join("")
|
237
|
-
io.value.
|
197
|
+
io.value.must_equal expected
|
238
198
|
end
|
239
199
|
|
240
200
|
it "traces custom single values" do
|
@@ -244,30 +204,30 @@ describe "Tracing" do
|
|
244
204
|
def set(val) self.ex = val; end
|
245
205
|
end
|
246
206
|
|
247
|
-
|
207
|
+
obj = DebugNamePrimitive.new
|
248
208
|
|
249
209
|
io = StringIO.new
|
250
|
-
BinData::trace_reading(io) {
|
210
|
+
BinData::trace_reading(io) { obj.read("\x01") }
|
251
211
|
|
252
|
-
io.value.
|
212
|
+
io.value.must_equal ["obj-internal-.ex => 1\n", "obj => 1\n"].join("")
|
253
213
|
end
|
254
214
|
|
255
215
|
it "traces choice selection" do
|
256
|
-
|
216
|
+
obj = BinData::Choice.new(:choices => [:int8, :int16be], :selection => 0)
|
257
217
|
|
258
218
|
io = StringIO.new
|
259
|
-
BinData::trace_reading(io) {
|
219
|
+
BinData::trace_reading(io) { obj.read("\x01") }
|
260
220
|
|
261
|
-
io.value.
|
221
|
+
io.value.must_equal ["obj-selection- => 0\n", "obj => 1\n"].join("")
|
262
222
|
end
|
263
223
|
|
264
224
|
it "trims long trace values" do
|
265
|
-
|
225
|
+
obj = BinData::String.new(:read_length => 40)
|
266
226
|
|
267
227
|
io = StringIO.new
|
268
|
-
BinData::trace_reading(io) {
|
228
|
+
BinData::trace_reading(io) { obj.read("0000000000111111111122222222223333333333") }
|
269
229
|
|
270
|
-
io.value.
|
230
|
+
io.value.must_equal "obj => \"000000000011111111112222222222...\n"
|
271
231
|
end
|
272
232
|
end
|
273
233
|
|
@@ -277,20 +237,20 @@ describe "Forward referencing with Primitive" do
|
|
277
237
|
string :data, :read_length => :len
|
278
238
|
end
|
279
239
|
|
280
|
-
|
240
|
+
let(:obj) { FRPrimitive.new }
|
281
241
|
|
282
242
|
it "initialises" do
|
283
|
-
|
243
|
+
obj.snapshot.must_equal({"len" => 0, "data" => ""})
|
284
244
|
end
|
285
245
|
|
286
246
|
it "reads" do
|
287
|
-
|
288
|
-
|
247
|
+
obj.read("\x04test")
|
248
|
+
obj.snapshot.must_equal({"len" => 4, "data" => "test"})
|
289
249
|
end
|
290
250
|
|
291
251
|
it "sets value" do
|
292
|
-
|
293
|
-
|
252
|
+
obj.data = "hello"
|
253
|
+
obj.snapshot.must_equal({"len" => 5, "data" => "hello"})
|
294
254
|
end
|
295
255
|
end
|
296
256
|
|
@@ -300,20 +260,20 @@ describe "Forward referencing with Array" do
|
|
300
260
|
array :data, :type => :uint8, :initial_length => :len
|
301
261
|
end
|
302
262
|
|
303
|
-
|
263
|
+
let(:obj) { FRArray.new }
|
304
264
|
|
305
265
|
it "initialises" do
|
306
|
-
|
266
|
+
obj.snapshot.must_equal({"len" => 0, "data" => []})
|
307
267
|
end
|
308
268
|
|
309
269
|
it "reads" do
|
310
|
-
|
311
|
-
|
270
|
+
obj.read("\x04\x01\x02\x03\x04")
|
271
|
+
obj.snapshot.must_equal({"len" => 4, "data" => [1, 2, 3, 4]})
|
312
272
|
end
|
313
273
|
|
314
274
|
it "sets value" do
|
315
|
-
|
316
|
-
|
275
|
+
obj.data = [1, 2, 3]
|
276
|
+
obj.snapshot.must_equal({"len" => 3, "data" => [1, 2, 3]})
|
317
277
|
end
|
318
278
|
end
|
319
279
|
|
@@ -327,8 +287,8 @@ describe "Evaluating custom parameters" do
|
|
327
287
|
end
|
328
288
|
|
329
289
|
it "recursively evaluates parameter" do
|
330
|
-
|
331
|
-
|
290
|
+
obj = CustomParameterRecord.new(:zz => 5)
|
291
|
+
obj.c.eval_parameter(:custom).must_equal 5
|
332
292
|
end
|
333
293
|
end
|
334
294
|
|
@@ -339,7 +299,7 @@ describe BinData::Record, "with custom sized integers" do
|
|
339
299
|
|
340
300
|
it "reads as expected" do
|
341
301
|
str = "\x00\x00\x00\x00\x05"
|
342
|
-
CustomIntRecord.read(str).
|
302
|
+
CustomIntRecord.read(str).snapshot.must_equal({"a" => 5})
|
343
303
|
end
|
344
304
|
end
|
345
305
|
|
@@ -352,9 +312,9 @@ describe BinData::Record, "with choice field" do
|
|
352
312
|
end
|
353
313
|
|
354
314
|
it "assigns" do
|
355
|
-
|
356
|
-
|
357
|
-
|
315
|
+
obj = BinData::Array.new(:type => :choice_field_record)
|
316
|
+
data = ChoiceFieldRecord.new(:a => 1, :b => {:v => 3})
|
317
|
+
obj.assign([data])
|
358
318
|
end
|
359
319
|
end
|
360
320
|
|
@@ -367,14 +327,14 @@ describe BinData::Primitive, "representing a string" do
|
|
367
327
|
def set(v) self.data = v; end
|
368
328
|
end
|
369
329
|
|
370
|
-
|
330
|
+
let(:obj) { PascalStringPrimitive.new("testing") }
|
371
331
|
|
372
332
|
it "compares to regexp" do
|
373
|
-
(
|
333
|
+
(obj =~ /es/).must_equal 1
|
374
334
|
end
|
375
335
|
|
376
336
|
it "compares to regexp" do
|
377
|
-
(/es/ =~
|
337
|
+
(/es/ =~ obj).must_equal 1
|
378
338
|
end
|
379
339
|
end
|
380
340
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 1.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dion Mendel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-
|
18
|
+
date: 2013-09-02 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -36,15 +36,15 @@ dependencies:
|
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
hash:
|
41
|
+
hash: 55
|
42
42
|
segments:
|
43
|
-
-
|
44
|
-
- 10
|
43
|
+
- 5
|
45
44
|
- 0
|
46
|
-
|
47
|
-
|
45
|
+
- 0
|
46
|
+
version: 5.0.0
|
47
|
+
name: minitest
|
48
48
|
version_requirements: *id002
|
49
49
|
prerelease: false
|
50
50
|
type: :development
|
@@ -125,7 +125,6 @@ files:
|
|
125
125
|
- examples/ip_address.rb
|
126
126
|
- examples/list.rb
|
127
127
|
- examples/nbt.rb
|
128
|
-
- lib/a.rb
|
129
128
|
- lib/bindata.rb
|
130
129
|
- lib/bindata/alignment.rb
|
131
130
|
- lib/bindata/array.rb
|
@@ -137,9 +136,11 @@ files:
|
|
137
136
|
- lib/bindata/deprecated.rb
|
138
137
|
- lib/bindata/dsl.rb
|
139
138
|
- lib/bindata/float.rb
|
139
|
+
- lib/bindata/framework.rb
|
140
140
|
- lib/bindata/int.rb
|
141
141
|
- lib/bindata/io.rb
|
142
142
|
- lib/bindata/lazy.rb
|
143
|
+
- lib/bindata/name.rb
|
143
144
|
- lib/bindata/offset.rb
|
144
145
|
- lib/bindata/params.rb
|
145
146
|
- lib/bindata/primitive.rb
|
@@ -155,35 +156,35 @@ files:
|
|
155
156
|
- lib/bindata/version.rb
|
156
157
|
- lib/bindata/virtual.rb
|
157
158
|
- setup.rb
|
158
|
-
- spec/alignment_spec.rb
|
159
|
-
- spec/array_spec.rb
|
160
|
-
- spec/base_primitive_spec.rb
|
161
|
-
- spec/base_spec.rb
|
162
|
-
- spec/bits_spec.rb
|
163
|
-
- spec/choice_spec.rb
|
164
|
-
- spec/count_bytes_remaining_spec.rb
|
165
|
-
- spec/deprecated_spec.rb
|
166
|
-
- spec/example.rb
|
167
|
-
- spec/float_spec.rb
|
168
|
-
- spec/int_spec.rb
|
169
|
-
- spec/io_spec.rb
|
170
|
-
- spec/lazy_spec.rb
|
171
|
-
- spec/primitive_spec.rb
|
172
|
-
- spec/record_spec.rb
|
173
|
-
- spec/registry_spec.rb
|
174
|
-
- spec/rest_spec.rb
|
175
|
-
- spec/skip_spec.rb
|
176
|
-
- spec/spec_common.rb
|
177
|
-
- spec/string_spec.rb
|
178
|
-
- spec/stringz_spec.rb
|
179
|
-
- spec/struct_spec.rb
|
180
|
-
- spec/system_spec.rb
|
181
159
|
- tasks/manual.rake
|
182
|
-
-
|
160
|
+
- test/alignment_test.rb
|
161
|
+
- test/array_test.rb
|
162
|
+
- test/base_primitive_test.rb
|
163
|
+
- test/base_test.rb
|
164
|
+
- test/bits_test.rb
|
165
|
+
- test/choice_test.rb
|
166
|
+
- test/common.rb
|
167
|
+
- test/count_bytes_remaining_test.rb
|
168
|
+
- test/deprecated_test.rb
|
169
|
+
- test/float_test.rb
|
170
|
+
- test/int_test.rb
|
171
|
+
- test/io_test.rb
|
172
|
+
- test/lazy_test.rb
|
173
|
+
- test/offset_test.rb
|
174
|
+
- test/params_test.rb
|
175
|
+
- test/primitive_test.rb
|
176
|
+
- test/record_test.rb
|
177
|
+
- test/registry_test.rb
|
178
|
+
- test/rest_test.rb
|
179
|
+
- test/skip_test.rb
|
180
|
+
- test/string_test.rb
|
181
|
+
- test/stringz_test.rb
|
182
|
+
- test/struct_test.rb
|
183
|
+
- test/system_test.rb
|
183
184
|
has_rdoc: true
|
184
185
|
homepage: http://github.com/dmendel/bindata
|
185
|
-
licenses:
|
186
|
-
|
186
|
+
licenses:
|
187
|
+
- Ruby
|
187
188
|
post_install_message:
|
188
189
|
rdoc_options:
|
189
190
|
- --main
|