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.

Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.rdoc +4 -0
  3. data/Rakefile +2 -2
  4. data/examples/gzip.rb +24 -24
  5. data/examples/ip_address.rb +3 -4
  6. data/examples/list.rb +20 -20
  7. data/examples/nbt.rb +14 -14
  8. data/examples/tcp_ip.rb +12 -14
  9. data/lib/bindata/alignment.rb +2 -2
  10. data/lib/bindata/array.rb +22 -23
  11. data/lib/bindata/base.rb +13 -12
  12. data/lib/bindata/base_primitive.rb +20 -17
  13. data/lib/bindata/bits.rb +4 -4
  14. data/lib/bindata/buffer.rb +5 -5
  15. data/lib/bindata/choice.rb +11 -13
  16. data/lib/bindata/count_bytes_remaining.rb +1 -2
  17. data/lib/bindata/delayed_io.rb +11 -11
  18. data/lib/bindata/dsl.rb +57 -64
  19. data/lib/bindata/float.rb +16 -13
  20. data/lib/bindata/int.rb +6 -6
  21. data/lib/bindata/io.rb +16 -16
  22. data/lib/bindata/lazy.rb +3 -3
  23. data/lib/bindata/name.rb +2 -2
  24. data/lib/bindata/offset.rb +3 -3
  25. data/lib/bindata/params.rb +13 -15
  26. data/lib/bindata/primitive.rb +3 -3
  27. data/lib/bindata/registry.rb +12 -12
  28. data/lib/bindata/rest.rb +1 -2
  29. data/lib/bindata/sanitize.rb +17 -18
  30. data/lib/bindata/skip.rb +7 -8
  31. data/lib/bindata/string.rb +6 -6
  32. data/lib/bindata/stringz.rb +3 -3
  33. data/lib/bindata/struct.rb +16 -16
  34. data/lib/bindata/trace.rb +9 -8
  35. data/lib/bindata/version.rb +1 -1
  36. data/lib/bindata/virtual.rb +3 -3
  37. data/lib/bindata/warnings.rb +6 -2
  38. data/test/alignment_test.rb +4 -4
  39. data/test/array_test.rb +29 -29
  40. data/test/base_primitive_test.rb +17 -17
  41. data/test/base_test.rb +6 -6
  42. data/test/bits_test.rb +1 -1
  43. data/test/buffer_test.rb +19 -19
  44. data/test/choice_test.rb +20 -20
  45. data/test/count_bytes_remaining_test.rb +1 -1
  46. data/test/delayed_io_test.rb +26 -26
  47. data/test/lazy_test.rb +16 -16
  48. data/test/offset_test.rb +8 -8
  49. data/test/params_test.rb +11 -11
  50. data/test/primitive_test.rb +11 -11
  51. data/test/record_test.rb +50 -50
  52. data/test/registry_test.rb +26 -26
  53. data/test/rest_test.rb +1 -1
  54. data/test/skip_test.rb +27 -27
  55. data/test/string_test.rb +24 -24
  56. data/test/stringz_test.rb +1 -1
  57. data/test/struct_test.rb +76 -75
  58. data/test/system_test.rb +51 -51
  59. data/test/virtual_test.rb +3 -3
  60. 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, :value => lambda { index * 10 }
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(:type =>
12
- [:uint8, { :value => lambda { index * 10 } }],
13
- :initial_length => 3)
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(:type => :nested_lambda_with_index,
19
- :initial_length => 3)
20
- arr.snapshot.must_equal [{:a => 0}, {:a => 10}, {:a => 20}]
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, :value => 5
33
- int8 :b, :value => lambda { a }
32
+ int8 :a, value: 5
33
+ int8 :b, value: -> { a }
34
34
  end
35
35
 
36
36
  class TestLambdaWithoutParent < BinData::Record
37
- int8 :a, :value => 3
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, :value => 5
48
- int8 :b, :value => lambda { parent.a }
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, :value => 3
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, :value => 3
64
- uint8 :b, :value => 5
63
+ uint8 :a, value: 3
64
+ uint8 :b, value: 5
65
65
  end
66
66
 
67
67
  class RecordWithChoiceField < BinData::Record
68
- choice :x, :selection => 0 do
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, :value => 0
75
- choice :x, :selection => 0 do
76
- choice :selection => :sel do
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, :type => :bit1, :initial_length => 9
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(:type => :uint8, :initial_length => 2)
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(:fields => [[:uint8, :a]])
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 = {:choices => [:uint8], :selection => 0}
177
- s = BinData::Struct.new(:fields => [[:choice, :a, choice_params]])
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 = {:fields => [[:uint8, :c]]}
183
- struct_params = {:fields => [[:struct, :b, nested_struct_params]]}
184
- s = BinData::Struct.new(:fields => [[:struct, :a, struct_params]])
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(:type => :int8, :initial_length => 5)
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(:choices => [:int8, :int16be], :selection => 0)
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(:read_length => 40)
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, :value => lambda { data.length }
237
- string :data, :read_length => :len
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({:len => 0, :data => ""})
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({:len => 4, :data => "test"})
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({:len => 5, :data => "hello"})
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, :value => lambda { data.length }
260
- array :data, :type => :uint8, :initial_length => :len
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({:len => 0, :data => []})
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({:len => 4, :data => [1, 2, 3, 4]})
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({:len => 3, :data => [1, 2, 3]})
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, :value => :zz
285
- uint8 :b, :value => :a
286
- uint8 :c, :custom => :b
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(:zz => 5)
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({:a => 5})
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, :selection => :a do
310
- struct 1, :fields => [[:int8, :v]]
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(:type => :choice_field_record)
316
- data = ChoiceFieldRecord.new(:a => 1, :b => {:v => 3})
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, :value => lambda { data.length }
324
- string :data, :read_length => :len
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(:assert => lambda { data << 1; true })
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(:assert => lambda { data << 1; true })
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(:value => 3)
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.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-09-07 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake