bindata 2.3.3 → 2.3.4
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.
- checksums.yaml +4 -4
- data/ChangeLog.rdoc +4 -0
- data/Rakefile +2 -2
- data/examples/gzip.rb +24 -24
- data/examples/ip_address.rb +3 -4
- data/examples/list.rb +20 -20
- data/examples/nbt.rb +14 -14
- data/examples/tcp_ip.rb +12 -14
- data/lib/bindata/alignment.rb +2 -2
- data/lib/bindata/array.rb +22 -23
- data/lib/bindata/base.rb +13 -12
- data/lib/bindata/base_primitive.rb +20 -17
- data/lib/bindata/bits.rb +4 -4
- data/lib/bindata/buffer.rb +5 -5
- data/lib/bindata/choice.rb +11 -13
- data/lib/bindata/count_bytes_remaining.rb +1 -2
- data/lib/bindata/delayed_io.rb +11 -11
- data/lib/bindata/dsl.rb +57 -64
- data/lib/bindata/float.rb +16 -13
- data/lib/bindata/int.rb +6 -6
- data/lib/bindata/io.rb +16 -16
- data/lib/bindata/lazy.rb +3 -3
- data/lib/bindata/name.rb +2 -2
- data/lib/bindata/offset.rb +3 -3
- data/lib/bindata/params.rb +13 -15
- data/lib/bindata/primitive.rb +3 -3
- data/lib/bindata/registry.rb +12 -12
- data/lib/bindata/rest.rb +1 -2
- data/lib/bindata/sanitize.rb +17 -18
- data/lib/bindata/skip.rb +7 -8
- data/lib/bindata/string.rb +6 -6
- data/lib/bindata/stringz.rb +3 -3
- data/lib/bindata/struct.rb +16 -16
- data/lib/bindata/trace.rb +9 -8
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +3 -3
- data/lib/bindata/warnings.rb +6 -2
- data/test/alignment_test.rb +4 -4
- data/test/array_test.rb +29 -29
- data/test/base_primitive_test.rb +17 -17
- data/test/base_test.rb +6 -6
- data/test/bits_test.rb +1 -1
- data/test/buffer_test.rb +19 -19
- data/test/choice_test.rb +20 -20
- data/test/count_bytes_remaining_test.rb +1 -1
- data/test/delayed_io_test.rb +26 -26
- data/test/lazy_test.rb +16 -16
- data/test/offset_test.rb +8 -8
- data/test/params_test.rb +11 -11
- data/test/primitive_test.rb +11 -11
- data/test/record_test.rb +50 -50
- data/test/registry_test.rb +26 -26
- data/test/rest_test.rb +1 -1
- data/test/skip_test.rb +27 -27
- data/test/string_test.rb +24 -24
- data/test/stringz_test.rb +1 -1
- data/test/struct_test.rb +76 -75
- data/test/system_test.rb +51 -51
- data/test/virtual_test.rb +3 -3
- metadata +2 -2
data/test/system_test.rb
CHANGED
@@ -4,20 +4,20 @@ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
|
|
4
4
|
|
5
5
|
describe "lambdas with index" do
|
6
6
|
class NestedLambdaWithIndex < BinData::Record
|
7
|
-
uint8 :a, :
|
7
|
+
uint8 :a, value: -> { index * 10 }
|
8
8
|
end
|
9
9
|
|
10
10
|
it "uses index of containing array" do
|
11
|
-
arr = BinData::Array.new(:
|
12
|
-
[:uint8, { :
|
13
|
-
:
|
11
|
+
arr = BinData::Array.new(type:
|
12
|
+
[:uint8, { value: -> { index * 10 } }],
|
13
|
+
initial_length: 3)
|
14
14
|
arr.snapshot.must_equal [0, 10, 20]
|
15
15
|
end
|
16
16
|
|
17
17
|
it "uses index of nearest containing array" do
|
18
|
-
arr = BinData::Array.new(:
|
19
|
-
:
|
20
|
-
arr.snapshot.must_equal [{:
|
18
|
+
arr = BinData::Array.new(type: :nested_lambda_with_index,
|
19
|
+
initial_length: 3)
|
20
|
+
arr.snapshot.must_equal [{a: 0}, {a: 10}, {a: 20}]
|
21
21
|
end
|
22
22
|
|
23
23
|
it "fails if there is no containing array" do
|
@@ -29,12 +29,12 @@ end
|
|
29
29
|
describe "lambdas with parent" do
|
30
30
|
it "accesses immediate parent when no parent is specified" do
|
31
31
|
class NestedLambdaWithoutParent < BinData::Record
|
32
|
-
int8 :a, :
|
33
|
-
int8 :b, :
|
32
|
+
int8 :a, value: 5
|
33
|
+
int8 :b, value: -> { a }
|
34
34
|
end
|
35
35
|
|
36
36
|
class TestLambdaWithoutParent < BinData::Record
|
37
|
-
int8 :a, :
|
37
|
+
int8 :a, value: 3
|
38
38
|
nested_lambda_without_parent :x
|
39
39
|
end
|
40
40
|
|
@@ -44,12 +44,12 @@ describe "lambdas with parent" do
|
|
44
44
|
|
45
45
|
it "accesses parent's parent when parent is specified" do
|
46
46
|
class NestedLambdaWithParent < BinData::Record
|
47
|
-
int8 :a, :
|
48
|
-
int8 :b, :
|
47
|
+
int8 :a, value: 5
|
48
|
+
int8 :b, value: -> { parent.a }
|
49
49
|
end
|
50
50
|
|
51
51
|
class TestLambdaWithParent < BinData::Record
|
52
|
-
int8 :a, :
|
52
|
+
int8 :a, value: 3
|
53
53
|
nested_lambda_with_parent :x
|
54
54
|
end
|
55
55
|
|
@@ -60,20 +60,20 @@ end
|
|
60
60
|
|
61
61
|
describe BinData::Record, "with choice field" do
|
62
62
|
class TupleRecord < BinData::Record
|
63
|
-
uint8 :a, :
|
64
|
-
uint8 :b, :
|
63
|
+
uint8 :a, value: 3
|
64
|
+
uint8 :b, value: 5
|
65
65
|
end
|
66
66
|
|
67
67
|
class RecordWithChoiceField < BinData::Record
|
68
|
-
choice :x, :
|
68
|
+
choice :x, selection: 0 do
|
69
69
|
tuple_record
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
class RecordWithNestedChoiceField < BinData::Record
|
74
|
-
uint8 :sel, :
|
75
|
-
choice :x, :
|
76
|
-
choice :
|
74
|
+
uint8 :sel, value: 0
|
75
|
+
choice :x, selection: 0 do
|
76
|
+
choice selection: :sel do
|
77
77
|
tuple_record
|
78
78
|
end
|
79
79
|
end
|
@@ -119,7 +119,7 @@ describe BinData::Record, "containing bitfields" do
|
|
119
119
|
bit4 :w
|
120
120
|
end
|
121
121
|
|
122
|
-
array :b, :
|
122
|
+
array :b, type: :bit1, initial_length: 9
|
123
123
|
|
124
124
|
struct :c do
|
125
125
|
bit2 :x
|
@@ -163,32 +163,32 @@ describe "Objects with debug_name" do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it "includes array index" do
|
166
|
-
arr = BinData::Array.new(:
|
166
|
+
arr = BinData::Array.new(type: :uint8, initial_length: 2)
|
167
167
|
arr[2].debug_name.must_equal "obj[2]"
|
168
168
|
end
|
169
169
|
|
170
170
|
it "includes field name" do
|
171
|
-
s = BinData::Struct.new(:
|
171
|
+
s = BinData::Struct.new(fields: [[:uint8, :a]])
|
172
172
|
s.a.debug_name.must_equal "obj.a"
|
173
173
|
end
|
174
174
|
|
175
175
|
it "delegates to choice" do
|
176
|
-
choice_params = {:
|
177
|
-
s = BinData::Struct.new(:
|
176
|
+
choice_params = {choices: [:uint8], selection: 0}
|
177
|
+
s = BinData::Struct.new(fields: [[:choice, :a, choice_params]])
|
178
178
|
s.a.debug_name.must_equal "obj.a"
|
179
179
|
end
|
180
180
|
|
181
181
|
it "nests" do
|
182
|
-
nested_struct_params = {:
|
183
|
-
struct_params = {:
|
184
|
-
s = BinData::Struct.new(:
|
182
|
+
nested_struct_params = {fields: [[:uint8, :c]]}
|
183
|
+
struct_params = {fields: [[:struct, :b, nested_struct_params]]}
|
184
|
+
s = BinData::Struct.new(fields: [[:struct, :a, struct_params]])
|
185
185
|
s.a.b.c.debug_name.must_equal "obj.a.b.c"
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
189
|
describe "Tracing" do
|
190
190
|
it "should trace arrays" do
|
191
|
-
arr = BinData::Array.new(:
|
191
|
+
arr = BinData::Array.new(type: :int8, initial_length: 5)
|
192
192
|
|
193
193
|
io = StringIO.new
|
194
194
|
BinData::trace_reading(io) { arr.read("\x01\x02\x03\x04\x05") }
|
@@ -213,7 +213,7 @@ describe "Tracing" do
|
|
213
213
|
end
|
214
214
|
|
215
215
|
it "traces choice selection" do
|
216
|
-
obj = BinData::Choice.new(:
|
216
|
+
obj = BinData::Choice.new(choices: [:int8, :int16be], selection: 0)
|
217
217
|
|
218
218
|
io = StringIO.new
|
219
219
|
BinData::trace_reading(io) { obj.read("\x01") }
|
@@ -222,7 +222,7 @@ describe "Tracing" do
|
|
222
222
|
end
|
223
223
|
|
224
224
|
it "trims long trace values" do
|
225
|
-
obj = BinData::String.new(:
|
225
|
+
obj = BinData::String.new(read_length: 40)
|
226
226
|
|
227
227
|
io = StringIO.new
|
228
228
|
BinData::trace_reading(io) { obj.read("0000000000111111111122222222223333333333") }
|
@@ -233,47 +233,47 @@ end
|
|
233
233
|
|
234
234
|
describe "Forward referencing with Primitive" do
|
235
235
|
class FRPrimitive < BinData::Record
|
236
|
-
uint8 :len, :
|
237
|
-
string :data, :
|
236
|
+
uint8 :len, value: -> { data.length }
|
237
|
+
string :data, read_length: :len
|
238
238
|
end
|
239
239
|
|
240
240
|
let(:obj) { FRPrimitive.new }
|
241
241
|
|
242
242
|
it "initialises" do
|
243
|
-
obj.snapshot.must_equal({:
|
243
|
+
obj.snapshot.must_equal({len: 0, data: ""})
|
244
244
|
end
|
245
245
|
|
246
246
|
it "reads" do
|
247
247
|
obj.read("\x04test")
|
248
|
-
obj.snapshot.must_equal({:
|
248
|
+
obj.snapshot.must_equal({len: 4, data: "test"})
|
249
249
|
end
|
250
250
|
|
251
251
|
it "sets value" do
|
252
252
|
obj.data = "hello"
|
253
|
-
obj.snapshot.must_equal({:
|
253
|
+
obj.snapshot.must_equal({len: 5, data: "hello"})
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
257
|
describe "Forward referencing with Array" do
|
258
258
|
class FRArray < BinData::Record
|
259
|
-
uint8 :len, :
|
260
|
-
array :data, :
|
259
|
+
uint8 :len, value: -> { data.length }
|
260
|
+
array :data, type: :uint8, initial_length: :len
|
261
261
|
end
|
262
262
|
|
263
263
|
let(:obj) { FRArray.new }
|
264
264
|
|
265
265
|
it "initialises" do
|
266
|
-
obj.snapshot.must_equal({:
|
266
|
+
obj.snapshot.must_equal({len: 0, data: []})
|
267
267
|
end
|
268
268
|
|
269
269
|
it "reads" do
|
270
270
|
obj.read("\x04\x01\x02\x03\x04")
|
271
|
-
obj.snapshot.must_equal({:
|
271
|
+
obj.snapshot.must_equal({len: 4, data: [1, 2, 3, 4]})
|
272
272
|
end
|
273
273
|
|
274
274
|
it "sets value" do
|
275
275
|
obj.data = [1, 2, 3]
|
276
|
-
obj.snapshot.must_equal({:
|
276
|
+
obj.snapshot.must_equal({len: 3, data: [1, 2, 3]})
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
@@ -281,13 +281,13 @@ describe "Evaluating custom parameters" do
|
|
281
281
|
class CustomParameterRecord < BinData::Record
|
282
282
|
mandatory_parameter :zz
|
283
283
|
|
284
|
-
uint8 :a, :
|
285
|
-
uint8 :b, :
|
286
|
-
uint8 :c, :
|
284
|
+
uint8 :a, value: :zz
|
285
|
+
uint8 :b, value: :a
|
286
|
+
uint8 :c, custom: :b
|
287
287
|
end
|
288
288
|
|
289
289
|
it "recursively evaluates parameter" do
|
290
|
-
obj = CustomParameterRecord.new(:
|
290
|
+
obj = CustomParameterRecord.new(zz: 5)
|
291
291
|
obj.c.eval_parameter(:custom).must_equal 5
|
292
292
|
end
|
293
293
|
end
|
@@ -299,29 +299,29 @@ describe BinData::Record, "with custom sized integers" do
|
|
299
299
|
|
300
300
|
it "reads as expected" do
|
301
301
|
str = "\x00\x00\x00\x00\x05"
|
302
|
-
CustomIntRecord.read(str).snapshot.must_equal({:
|
302
|
+
CustomIntRecord.read(str).snapshot.must_equal({a: 5})
|
303
303
|
end
|
304
304
|
end
|
305
305
|
|
306
306
|
describe BinData::Record, "with choice field" do
|
307
307
|
class ChoiceFieldRecord < BinData::Record
|
308
308
|
int8 :a
|
309
|
-
choice :b, :
|
310
|
-
struct 1, :
|
309
|
+
choice :b, selection: :a do
|
310
|
+
struct 1, fields: [[:int8, :v]]
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
314
314
|
it "assigns" do
|
315
|
-
obj = BinData::Array.new(:
|
316
|
-
data = ChoiceFieldRecord.new(:
|
315
|
+
obj = BinData::Array.new(type: :choice_field_record)
|
316
|
+
data = ChoiceFieldRecord.new(a: 1, b: {v: 3})
|
317
317
|
obj.assign([data])
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
321
321
|
describe BinData::Primitive, "representing a string" do
|
322
322
|
class PascalStringPrimitive < BinData::Primitive
|
323
|
-
uint8 :len, :
|
324
|
-
string :data, :
|
323
|
+
uint8 :len, value: -> { data.length }
|
324
|
+
string :data, read_length: :len
|
325
325
|
|
326
326
|
def get; self.data; end
|
327
327
|
def set(v) self.data = v; end
|
data/test/virtual_test.rb
CHANGED
@@ -22,7 +22,7 @@ describe BinData::Virtual do
|
|
22
22
|
|
23
23
|
it "asserts on #read" do
|
24
24
|
data = []
|
25
|
-
obj = BinData::Virtual.new(:
|
25
|
+
obj = BinData::Virtual.new(assert: -> { data << 1; true })
|
26
26
|
|
27
27
|
obj.read ""
|
28
28
|
data.must_equal [1]
|
@@ -30,7 +30,7 @@ describe BinData::Virtual do
|
|
30
30
|
|
31
31
|
it "asserts on #assign" do
|
32
32
|
data = []
|
33
|
-
obj = BinData::Virtual.new(:
|
33
|
+
obj = BinData::Virtual.new(assert: -> { data << 1; true })
|
34
34
|
|
35
35
|
obj.assign("foo")
|
36
36
|
data.must_equal [1]
|
@@ -42,7 +42,7 @@ describe BinData::Virtual do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "accepts the :value parameter" do
|
45
|
-
obj = BinData::Virtual.new(:
|
45
|
+
obj = BinData::Virtual.new(value: 3)
|
46
46
|
obj.must_equal 3
|
47
47
|
end
|
48
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dion Mendel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|