bindata 2.1.0 → 2.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.
- checksums.yaml +4 -4
- data/.travis.yml +7 -2
- data/COPYING +1 -1
- data/ChangeLog.rdoc +8 -0
- data/README.md +1 -1
- data/bindata.gemspec +1 -1
- data/lib/bindata.rb +6 -2
- data/lib/bindata/base.rb +5 -0
- data/lib/bindata/base_primitive.rb +2 -2
- data/lib/bindata/dsl.rb +142 -99
- data/lib/bindata/int.rb +50 -50
- data/lib/bindata/registry.rb +38 -14
- data/lib/bindata/sanitize.rb +33 -21
- data/lib/bindata/string.rb +16 -0
- data/lib/bindata/struct.rb +17 -2
- data/lib/bindata/version.rb +1 -1
- data/test/alignment_test.rb +3 -3
- data/test/array_test.rb +11 -11
- data/test/base_primitive_test.rb +21 -1
- data/test/base_test.rb +7 -1
- data/test/bits_test.rb +1 -1
- data/test/buffer_test.rb +6 -6
- data/test/choice_test.rb +14 -19
- data/test/count_bytes_remaining_test.rb +3 -3
- data/test/float_test.rb +5 -5
- data/test/int_test.rb +4 -4
- data/test/io_test.rb +1 -1
- data/test/lazy_test.rb +1 -1
- data/test/offset_test.rb +1 -1
- data/test/params_test.rb +1 -1
- data/test/primitive_test.rb +6 -6
- data/test/record_test.rb +86 -12
- data/test/registry_test.rb +43 -22
- data/test/rest_test.rb +2 -2
- data/test/skip_test.rb +4 -4
- data/test/string_test.rb +35 -7
- data/test/stringz_test.rb +6 -6
- data/test/struct_test.rb +56 -6
- data/test/system_test.rb +7 -7
- data/test/{common.rb → test_helper.rb} +11 -34
- data/test/virtual_test.rb +2 -2
- data/test/warnings_test.rb +1 -1
- metadata +16 -16
data/test/struct_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
|
4
4
|
|
5
5
|
describe BinData::Struct, "when initializing" do
|
6
6
|
it "fails on non registered types" do
|
@@ -62,7 +62,7 @@ describe BinData::Struct, "with anonymous fields" do
|
|
62
62
|
it "writes anonymous fields" do
|
63
63
|
obj.read("\001\002\003")
|
64
64
|
obj.a.clear
|
65
|
-
obj.to_binary_s.
|
65
|
+
obj.to_binary_s.must_equal_binary "\005\002\005"
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -104,7 +104,7 @@ describe BinData::Struct, "with multiple fields" do
|
|
104
104
|
let(:obj) { BinData::Struct.new({:a => 1, :b => 2}, params) }
|
105
105
|
|
106
106
|
specify { obj.field_names.must_equal [:a, :b] }
|
107
|
-
specify { obj.to_binary_s.
|
107
|
+
specify { obj.to_binary_s.must_equal_binary "\x01\x02" }
|
108
108
|
|
109
109
|
it "returns num_bytes" do
|
110
110
|
obj.a.num_bytes.must_equal 1
|
@@ -290,7 +290,7 @@ describe BinData::Struct, "with an endian defined" do
|
|
290
290
|
|
291
291
|
expected = [1, 2.0, 3, 4, 5, 6, 7, 8].pack('veCCVvNv')
|
292
292
|
|
293
|
-
obj.to_binary_s.
|
293
|
+
obj.to_binary_s.must_equal_binary expected
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
@@ -301,7 +301,7 @@ describe BinData::Struct, "with bit fields" do
|
|
301
301
|
}
|
302
302
|
|
303
303
|
specify { obj.num_bytes.must_equal 3 }
|
304
|
-
specify { obj.to_binary_s.
|
304
|
+
specify { obj.to_binary_s.must_equal_binary [0b0000_0101, 3, 1].pack("C*") }
|
305
305
|
|
306
306
|
it "reads" do
|
307
307
|
str = [0b0000_0110, 5, 0].pack("C*")
|
@@ -338,6 +338,56 @@ describe BinData::Struct, "with nested endian" do
|
|
338
338
|
end
|
339
339
|
end
|
340
340
|
|
341
|
+
describe BinData::Struct, "with a search_prefix" do
|
342
|
+
class AShort < BinData::Uint8; end
|
343
|
+
class BShort < BinData::Uint8; end
|
344
|
+
|
345
|
+
it "searches symbol prefixes" do
|
346
|
+
obj = BinData::Struct.new(:search_prefix => :a,
|
347
|
+
:fields => [ [:short, :f] ])
|
348
|
+
obj.f.class.name.must_equal "AShort"
|
349
|
+
end
|
350
|
+
|
351
|
+
it "searches string prefixes" do
|
352
|
+
obj = BinData::Struct.new(:search_prefix => "a",
|
353
|
+
:fields => [ [:short, :f] ])
|
354
|
+
obj.f.class.name.must_equal "AShort"
|
355
|
+
end
|
356
|
+
|
357
|
+
it "searches string prefixes with optional underscore" do
|
358
|
+
obj = BinData::Struct.new(:search_prefix => "a_",
|
359
|
+
:fields => [ [:short, :f] ])
|
360
|
+
obj.f.class.name.must_equal "AShort"
|
361
|
+
end
|
362
|
+
|
363
|
+
it "searches multiple prefixes" do
|
364
|
+
obj = BinData::Struct.new(:search_prefix => [:x, :a],
|
365
|
+
:fields => [ [:short, :f] ])
|
366
|
+
obj.f.class.name.must_equal "AShort"
|
367
|
+
end
|
368
|
+
|
369
|
+
it "uses parent search_prefix" do
|
370
|
+
nested_params = { :fields => [[:short, :f]] }
|
371
|
+
obj = BinData::Struct.new(:search_prefix => :a,
|
372
|
+
:fields => [[:struct, :s, nested_params]])
|
373
|
+
obj.s.f.class.name.must_equal "AShort"
|
374
|
+
end
|
375
|
+
|
376
|
+
it "searches parent search_prefix" do
|
377
|
+
nested_params = { :search_prefix => :x, :fields => [[:short, :f]] }
|
378
|
+
obj = BinData::Struct.new(:search_prefix => :a,
|
379
|
+
:fields => [[:struct, :s, nested_params]])
|
380
|
+
obj.s.f.class.name.must_equal "AShort"
|
381
|
+
end
|
382
|
+
|
383
|
+
it "prioritises nested search_prefix" do
|
384
|
+
nested_params = { :search_prefix => :a, :fields => [[:short, :f]] }
|
385
|
+
obj = BinData::Struct.new(:search_prefix => :b,
|
386
|
+
:fields => [[:struct, :s, nested_params]])
|
387
|
+
obj.s.f.class.name.must_equal "AShort"
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
341
391
|
describe BinData::Struct, "with byte_align" do
|
342
392
|
let(:obj) {
|
343
393
|
params = { :fields => [[:int8, :a],
|
@@ -358,7 +408,7 @@ describe BinData::Struct, "with byte_align" do
|
|
358
408
|
|
359
409
|
it "writes" do
|
360
410
|
obj.assign(:a => 1, :b => 2, :c => 3, :d => 4)
|
361
|
-
obj.to_binary_s.
|
411
|
+
obj.to_binary_s.must_equal_binary "\x01\x00\x00\x00\x00\x02\xc0\x00\x00\x04"
|
362
412
|
end
|
363
413
|
|
364
414
|
it "has correct offsets" do
|
data/test/system_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "
|
3
|
+
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
|
@@ -152,34 +152,34 @@ describe BinData::Record, "containing bitfields" do
|
|
152
152
|
obj.c.x = 1
|
153
153
|
obj.d = 850
|
154
154
|
obj.e = 35
|
155
|
-
obj.to_binary_s.
|
155
|
+
obj.to_binary_s.must_equal_binary [0b0011_0010, 0b0100_0011, 0b0000_1010, 0b0001_0001, 0b1000_0000].pack("CCCCC")
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
159
159
|
describe "Objects with debug_name" do
|
160
160
|
it "haves default name of obj" do
|
161
|
-
el =
|
161
|
+
el = BinData::Uint8.new
|
162
162
|
el.debug_name.must_equal "obj"
|
163
163
|
end
|
164
164
|
|
165
165
|
it "includes array index" do
|
166
|
-
arr = BinData::Array.new(:type => :
|
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 => [[:
|
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 => [:
|
176
|
+
choice_params = {:choices => [:uint8], :selection => 0}
|
177
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 => [[:
|
182
|
+
nested_struct_params = {:fields => [[:uint8, :c]]}
|
183
183
|
struct_params = {:fields => [[:struct, :b, nested_struct_params]]}
|
184
184
|
s = BinData::Struct.new(:fields => [[:struct, :a, struct_params]])
|
185
185
|
s.a.b.c.debug_name.must_equal "obj.a.b.c"
|
@@ -9,21 +9,6 @@ require 'stringio'
|
|
9
9
|
$LOAD_PATH.unshift File.expand_path("../lib", File.dirname(__FILE__))
|
10
10
|
require 'bindata'
|
11
11
|
|
12
|
-
class Object
|
13
|
-
def expose_methods_for_testing
|
14
|
-
cls = (Class === self) ? self : (class << self ; self; end)
|
15
|
-
private_method_names = cls.private_instance_methods - Object.private_instance_methods
|
16
|
-
cls.send(:public, *private_method_names)
|
17
|
-
|
18
|
-
protected_method_names = cls.protected_instance_methods - Object.protected_instance_methods
|
19
|
-
cls.send(:public, *protected_method_names)
|
20
|
-
end
|
21
|
-
|
22
|
-
def value_read_from_written
|
23
|
-
self.class.read(self.to_binary_s)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
12
|
class StringIO
|
28
13
|
# Returns the value that was written to the io
|
29
14
|
def value
|
@@ -32,31 +17,24 @@ class StringIO
|
|
32
17
|
end
|
33
18
|
end
|
34
19
|
|
35
|
-
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
private
|
20
|
+
module Kernel
|
21
|
+
def expose_methods_for_testing
|
22
|
+
cls = (Class === self) ? self : (class << self ; self; end)
|
23
|
+
private_method_names = cls.private_instance_methods - Object.private_instance_methods
|
24
|
+
cls.send(:public, *private_method_names)
|
41
25
|
|
42
|
-
|
43
|
-
|
26
|
+
protected_method_names = cls.protected_instance_methods - Object.protected_instance_methods
|
27
|
+
cls.send(:public, *protected_method_names)
|
44
28
|
end
|
45
29
|
|
46
|
-
def
|
47
|
-
|
30
|
+
def value_read_from_written
|
31
|
+
self.class.read(self.to_binary_s)
|
48
32
|
end
|
49
33
|
|
50
|
-
def
|
51
|
-
|
34
|
+
def must_equal_binary(expected)
|
35
|
+
must_equal expected.dup.force_encoding(Encoding::BINARY)
|
52
36
|
end
|
53
|
-
end
|
54
37
|
|
55
|
-
def binary(str)
|
56
|
-
str.dup.force_encoding(Encoding::BINARY)
|
57
|
-
end
|
58
|
-
|
59
|
-
module Kernel
|
60
38
|
def must_raise_on_line(exp, line, msg = nil)
|
61
39
|
ex = self.must_raise exp
|
62
40
|
ex.message.must_equal msg if msg
|
@@ -70,4 +48,3 @@ module Kernel
|
|
70
48
|
(err_line - ref_line).must_equal line
|
71
49
|
end
|
72
50
|
end
|
73
|
-
|
data/test/virtual_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require File.expand_path(File.join(File.dirname(__FILE__), "
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
|
4
4
|
|
5
5
|
describe BinData::Virtual do
|
6
6
|
let(:stream) { StringIO.new "abcdefghij" }
|
@@ -12,7 +12,7 @@ describe BinData::Virtual do
|
|
12
12
|
|
13
13
|
it "must not write to a stream" do
|
14
14
|
obj = BinData::Virtual.new
|
15
|
-
obj.to_binary_s.
|
15
|
+
obj.to_binary_s.must_equal_binary ""
|
16
16
|
end
|
17
17
|
|
18
18
|
it "occupies no space" do
|
data/test/warnings_test.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dion Mendel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 5.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: coveralls
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: |
|
@@ -59,14 +59,14 @@ description: |
|
|
59
59
|
data is, and BinData works out *how* to read and write data in this
|
60
60
|
format. It is an easier ( and more readable ) alternative to
|
61
61
|
ruby's #pack and #unpack methods.
|
62
|
-
email:
|
62
|
+
email: bindata@dm9.info
|
63
63
|
executables: []
|
64
64
|
extensions: []
|
65
65
|
extra_rdoc_files:
|
66
66
|
- NEWS.rdoc
|
67
67
|
files:
|
68
|
-
- .gitignore
|
69
|
-
- .travis.yml
|
68
|
+
- ".gitignore"
|
69
|
+
- ".travis.yml"
|
70
70
|
- BSDL
|
71
71
|
- COPYING
|
72
72
|
- ChangeLog.rdoc
|
@@ -120,7 +120,6 @@ files:
|
|
120
120
|
- test/bits_test.rb
|
121
121
|
- test/buffer_test.rb
|
122
122
|
- test/choice_test.rb
|
123
|
-
- test/common.rb
|
124
123
|
- test/count_bytes_remaining_test.rb
|
125
124
|
- test/float_test.rb
|
126
125
|
- test/int_test.rb
|
@@ -137,6 +136,7 @@ files:
|
|
137
136
|
- test/stringz_test.rb
|
138
137
|
- test/struct_test.rb
|
139
138
|
- test/system_test.rb
|
139
|
+
- test/test_helper.rb
|
140
140
|
- test/virtual_test.rb
|
141
141
|
- test/warnings_test.rb
|
142
142
|
homepage: http://github.com/dmendel/bindata
|
@@ -145,23 +145,23 @@ licenses:
|
|
145
145
|
metadata: {}
|
146
146
|
post_install_message:
|
147
147
|
rdoc_options:
|
148
|
-
- --main
|
148
|
+
- "--main"
|
149
149
|
- NEWS.rdoc
|
150
150
|
require_paths:
|
151
151
|
- lib
|
152
152
|
required_ruby_version: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
|
-
- -
|
154
|
+
- - ">="
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: '0'
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
|
-
- -
|
159
|
+
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project: bindata
|
164
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.4.5
|
165
165
|
signing_key:
|
166
166
|
specification_version: 4
|
167
167
|
summary: A declarative way to read and write binary file formats
|