bindata 2.4.10 → 2.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.rdoc +28 -0
- data/LICENSE +25 -0
- data/NEWS.rdoc +5 -0
- data/README.md +3 -3
- data/bindata.gemspec +7 -2
- data/examples/NBT.txt +1 -1
- data/lib/bindata/bits.rb +10 -10
- data/lib/bindata/delayed_io.rb +9 -1
- data/lib/bindata/dsl.rb +3 -3
- data/lib/bindata/int.rb +5 -7
- data/lib/bindata/params.rb +1 -1
- data/lib/bindata/struct.rb +9 -2
- data/lib/bindata/version.rb +1 -1
- data/test/alignment_test.rb +8 -8
- data/test/array_test.rb +88 -88
- data/test/base_primitive_test.rb +47 -47
- data/test/base_test.rb +24 -24
- data/test/bits_test.rb +15 -15
- data/test/buffer_test.rb +22 -22
- data/test/choice_test.rb +31 -31
- data/test/count_bytes_remaining_test.rb +8 -8
- data/test/delayed_io_test.rb +75 -30
- data/test/float_test.rb +8 -8
- data/test/int_test.rb +14 -14
- data/test/io_test.rb +105 -105
- data/test/lazy_test.rb +38 -38
- data/test/offset_test.rb +8 -8
- data/test/params_test.rb +19 -19
- data/test/primitive_test.rb +26 -26
- data/test/record_test.rb +99 -99
- data/test/registry_test.rb +42 -42
- data/test/rest_test.rb +5 -5
- data/test/skip_test.rb +17 -17
- data/test/string_test.rb +56 -56
- data/test/stringz_test.rb +26 -26
- data/test/struct_test.rb +85 -85
- data/test/system_test.rb +40 -40
- data/test/test_helper.rb +2 -2
- data/test/uint8_array_test.rb +6 -6
- data/test/virtual_test.rb +7 -7
- data/test/warnings_test.rb +2 -2
- metadata +6 -10
- data/.gitignore +0 -2
- data/.travis.yml +0 -15
- data/BSDL +0 -22
- data/COPYING +0 -52
- data/INSTALL +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 80617b407b7a7c2213a57dd816a4c34b144dc7bf84cfbedb021b4121f733d375
|
|
4
|
+
data.tar.gz: 4a71111bd4ee444bd71bde4d2e1cf4242501618d4884b93f72eabdc7f0cd6ed6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4de56ea71fa7e19e79d668eca56fd767a6dc781ce2184ef6d0373835ca73650d423cecd65c9066a1cd3e2055d66f87223688b78737da5630401cda06ec6ab5ee
|
|
7
|
+
data.tar.gz: 33865f2dca175323ed73af86b52ec4c507b3b1ef1af6b4eeef103fbfe422607cb40476e558dda85e13ffad603ab6f8150a5798bdd1051a164dc54604ec7c5cf1
|
data/ChangeLog.rdoc
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
= BinData Changelog
|
|
2
2
|
|
|
3
|
+
== Version 2.4.15 (2023-02-07)
|
|
4
|
+
|
|
5
|
+
* Added ruby 2.4.0 requirement to gemspec. Thanks to theldoria.
|
|
6
|
+
* Added github CI action. Thanks to Peter Goldstein.
|
|
7
|
+
* Convert file from latin1 to UTF-8. Thanks to Cédric Boutillier.
|
|
8
|
+
* Move license from dual license to solely BSD-2-Clause.
|
|
9
|
+
* Remove unnecessary files from gem. Requested by Orien Madgwick.
|
|
10
|
+
* Allow multiple calls to auto_call_delayed_io. Thanks to dwelch-r7.
|
|
11
|
+
|
|
12
|
+
== Version 2.4.14 (2022-10-31)
|
|
13
|
+
|
|
14
|
+
* Use Comparable#clamp instead of manual calculations.
|
|
15
|
+
* Update tests to new minitest requirements.
|
|
16
|
+
* Adjust tests due to changes in ruby 3.1
|
|
17
|
+
|
|
18
|
+
== Version 2.4.13 (2022-10-16)
|
|
19
|
+
|
|
20
|
+
* Relax over-strict parameter naming requirements. Requested by
|
|
21
|
+
vinayak3qilabs.
|
|
22
|
+
|
|
23
|
+
== Version 2.4.12 (2022-10-03)
|
|
24
|
+
|
|
25
|
+
* Do not include DelayedIO objects when :onlyif is false.
|
|
26
|
+
|
|
27
|
+
== Version 2.4.11 (2022-09-27)
|
|
28
|
+
|
|
29
|
+
* Make DelayedIO work with :onlyif. Reported by Spencer McIntyre.
|
|
30
|
+
|
|
3
31
|
== Version 2.4.10 (2021-05-18)
|
|
4
32
|
|
|
5
33
|
* Improve speed of dynamic object creation. Reported by Charlie Ablett.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2007-2022, Dion Mendel
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/NEWS.rdoc
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# What is BinData?
|
|
2
2
|
|
|
3
|
-
[ ](https://rubygems.org/gems/bindata)
|
|
4
|
+
[ ](https://github.com/dmendel/bindata/actions/workflows/ci.yml)
|
|
5
|
+
[ ](https://coveralls.io/r/dmendel/bindata)
|
|
6
6
|
|
|
7
7
|
Do you ever find yourself writing code like this?
|
|
8
8
|
|
data/bindata.gemspec
CHANGED
|
@@ -12,8 +12,13 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.require_path = 'lib'
|
|
13
13
|
s.extra_rdoc_files = ['NEWS.rdoc']
|
|
14
14
|
s.rdoc_options << '--main' << 'NEWS.rdoc'
|
|
15
|
-
s.files =
|
|
16
|
-
|
|
15
|
+
s.files = Dir.chdir(__dir__) do
|
|
16
|
+
`git ls-files -z`.split("\x0").reject do |file|
|
|
17
|
+
file.start_with?(*%w[.git INSTALL])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
s.license = 'BSD-2-Clause'
|
|
21
|
+
s.required_ruby_version = ">= 2.4.0"
|
|
17
22
|
|
|
18
23
|
s.add_development_dependency('rake')
|
|
19
24
|
s.add_development_dependency('minitest', "> 5.0.0", "< 5.12.0")
|
data/examples/NBT.txt
CHANGED
|
@@ -107,7 +107,7 @@ You should end up with this:
|
|
|
107
107
|
TAG_Short("shortTest"): 32767
|
|
108
108
|
TAG_Long("longTest"): 9223372036854775807
|
|
109
109
|
TAG_Float("floatTest"): 0.49823147
|
|
110
|
-
TAG_String("stringTest"): HELLO WORLD THIS IS A TEST STRING
|
|
110
|
+
TAG_String("stringTest"): HELLO WORLD THIS IS A TEST STRING ÅÄÖ!
|
|
111
111
|
TAG_Int("intTest"): 2147483647
|
|
112
112
|
TAG_Compound("nested compound test"): 2 entries
|
|
113
113
|
{
|
data/lib/bindata/bits.rb
CHANGED
|
@@ -99,14 +99,14 @@ module BinData
|
|
|
99
99
|
|
|
100
100
|
def create_dynamic_clamp_code(signed)
|
|
101
101
|
if signed == :signed
|
|
102
|
-
max = "
|
|
103
|
-
min = "
|
|
102
|
+
max = "(1 << (nbits - 1)) - 1"
|
|
103
|
+
min = "-((#{max}) + 1)"
|
|
104
104
|
else
|
|
105
|
-
max = "
|
|
106
|
-
min = "
|
|
105
|
+
max = "(1 << nbits) - 1"
|
|
106
|
+
min = "0"
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
"
|
|
109
|
+
"val = val.clamp(#{min}, #{max})"
|
|
110
110
|
end
|
|
111
111
|
|
|
112
112
|
def create_fixed_clamp_code(nbits, signed)
|
|
@@ -115,14 +115,14 @@ module BinData
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
if signed == :signed
|
|
118
|
-
max = "
|
|
119
|
-
min = "
|
|
118
|
+
max = "(1 << (#{nbits} - 1)) - 1"
|
|
119
|
+
min = "-((#{max}) + 1)"
|
|
120
120
|
else
|
|
121
|
-
min = "
|
|
122
|
-
max = "
|
|
121
|
+
min = "0"
|
|
122
|
+
max = "(1 << #{nbits}) - 1"
|
|
123
123
|
end
|
|
124
124
|
|
|
125
|
-
clamp = "(
|
|
125
|
+
clamp = "(val = val.clamp(#{min}, #{max}))"
|
|
126
126
|
|
|
127
127
|
if nbits == 1
|
|
128
128
|
# allow single bits to be used as booleans
|
data/lib/bindata/delayed_io.rb
CHANGED
|
@@ -116,9 +116,14 @@ module BinData
|
|
|
116
116
|
0
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
+
def include_obj?
|
|
120
|
+
! has_parameter?(:onlyif) || eval_parameter(:onlyif)
|
|
121
|
+
end
|
|
122
|
+
|
|
119
123
|
# DelayedIO objects aren't read when #read is called.
|
|
120
124
|
# The reading is delayed until this method is called.
|
|
121
125
|
def read_now!
|
|
126
|
+
return unless include_obj?
|
|
122
127
|
raise IOError, "read from where?" unless @read_io
|
|
123
128
|
|
|
124
129
|
@read_io.seekbytes(abs_offset - @read_io.offset)
|
|
@@ -130,7 +135,9 @@ module BinData
|
|
|
130
135
|
# DelayedIO objects aren't written when #write is called.
|
|
131
136
|
# The writing is delayed until this method is called.
|
|
132
137
|
def write_now!
|
|
138
|
+
return unless include_obj?
|
|
133
139
|
raise IOError, "write to where?" unless @write_io
|
|
140
|
+
|
|
134
141
|
@write_io.seekbytes(abs_offset - @write_io.offset)
|
|
135
142
|
@type.do_write(@write_io)
|
|
136
143
|
end
|
|
@@ -152,9 +159,10 @@ module BinData
|
|
|
152
159
|
# The +auto_call_delayed_io+ keyword sets a data object tree to perform
|
|
153
160
|
# multi pass I/O automatically.
|
|
154
161
|
def auto_call_delayed_io
|
|
162
|
+
include AutoCallDelayedIO
|
|
163
|
+
|
|
155
164
|
return if DelayedIO.method_defined? :initialize_instance_without_record_io
|
|
156
165
|
|
|
157
|
-
include AutoCallDelayedIO
|
|
158
166
|
DelayedIO.send(:alias_method, :initialize_instance_without_record_io, :initialize_instance)
|
|
159
167
|
DelayedIO.send(:define_method, :initialize_instance) do
|
|
160
168
|
if @parent && !defined? @delayed_io_recorded
|
data/lib/bindata/dsl.rb
CHANGED
|
@@ -420,7 +420,7 @@ module BinData
|
|
|
420
420
|
def ensure_valid_name(name)
|
|
421
421
|
if name && !option?(:fieldnames_are_values)
|
|
422
422
|
if malformed_name?(name)
|
|
423
|
-
raise
|
|
423
|
+
raise SyntaxError, "field '#{name}' is an illegal fieldname"
|
|
424
424
|
end
|
|
425
425
|
|
|
426
426
|
if duplicate_name?(name)
|
|
@@ -428,11 +428,11 @@ module BinData
|
|
|
428
428
|
end
|
|
429
429
|
|
|
430
430
|
if name_shadows_method?(name)
|
|
431
|
-
raise
|
|
431
|
+
raise SyntaxError, "field '#{name}' shadows an existing method"
|
|
432
432
|
end
|
|
433
433
|
|
|
434
434
|
if name_is_reserved?(name)
|
|
435
|
-
raise
|
|
435
|
+
raise SyntaxError, "field '#{name}' is a reserved name"
|
|
436
436
|
end
|
|
437
437
|
end
|
|
438
438
|
end
|
data/lib/bindata/int.rb
CHANGED
|
@@ -59,16 +59,14 @@ module BinData
|
|
|
59
59
|
|
|
60
60
|
def create_clamp_code(nbits, signed)
|
|
61
61
|
if signed == :signed
|
|
62
|
-
max = "
|
|
63
|
-
min = "
|
|
62
|
+
max = "(1 << (#{nbits} - 1)) - 1"
|
|
63
|
+
min = "-((#{max}) + 1)"
|
|
64
64
|
else
|
|
65
|
-
max = "
|
|
66
|
-
min = "
|
|
65
|
+
max = "(1 << #{nbits}) - 1"
|
|
66
|
+
min = "0"
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"val = #{clamp}"
|
|
69
|
+
"val = val.clamp(#{min}, #{max})"
|
|
72
70
|
end
|
|
73
71
|
|
|
74
72
|
def create_read_code(nbits, endian, signed)
|
data/lib/bindata/params.rb
CHANGED
|
@@ -116,7 +116,7 @@ module BinData
|
|
|
116
116
|
|
|
117
117
|
def self.invalid_parameter_names
|
|
118
118
|
@invalid_names ||= begin
|
|
119
|
-
all_names = LazyEvaluator.instance_methods(true)
|
|
119
|
+
all_names = LazyEvaluator.instance_methods(true)
|
|
120
120
|
allowed_names = [:name, :type]
|
|
121
121
|
invalid_names = (all_names - allowed_names).uniq
|
|
122
122
|
|
data/lib/bindata/struct.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'bindata/base'
|
|
2
|
+
require 'bindata/delayed_io'
|
|
2
3
|
|
|
3
4
|
module BinData
|
|
4
5
|
|
|
@@ -136,12 +137,12 @@ module BinData
|
|
|
136
137
|
|
|
137
138
|
def do_read(io) #:nodoc:
|
|
138
139
|
instantiate_all_objs
|
|
139
|
-
@field_objs.each { |f| f.do_read(io) if
|
|
140
|
+
@field_objs.each { |f| f.do_read(io) if include_obj_for_io?(f) }
|
|
140
141
|
end
|
|
141
142
|
|
|
142
143
|
def do_write(io) #:nodoc
|
|
143
144
|
instantiate_all_objs
|
|
144
|
-
@field_objs.each { |f| f.do_write(io) if
|
|
145
|
+
@field_objs.each { |f| f.do_write(io) if include_obj_for_io?(f) }
|
|
145
146
|
end
|
|
146
147
|
|
|
147
148
|
def do_num_bytes #:nodoc:
|
|
@@ -263,6 +264,12 @@ module BinData
|
|
|
263
264
|
end
|
|
264
265
|
end
|
|
265
266
|
|
|
267
|
+
def include_obj_for_io?(obj)
|
|
268
|
+
# Used by #do_read and #do_write, to ensure the stream is passed to
|
|
269
|
+
# DelayedIO objects for delayed processing.
|
|
270
|
+
include_obj?(obj) || DelayedIO === obj
|
|
271
|
+
end
|
|
272
|
+
|
|
266
273
|
def include_obj?(obj)
|
|
267
274
|
!obj.has_parameter?(:onlyif) || obj.eval_parameter(:onlyif)
|
|
268
275
|
end
|
data/lib/bindata/version.rb
CHANGED
data/test/alignment_test.rb
CHANGED
|
@@ -14,20 +14,20 @@ describe BinData::ResumeByteAlignment do
|
|
|
14
14
|
it "resets read alignment" do
|
|
15
15
|
obj.read "\x12\x34"
|
|
16
16
|
|
|
17
|
-
obj.a.must_equal 1
|
|
18
|
-
obj.b.must_equal 3
|
|
17
|
+
_(obj.a).must_equal 1
|
|
18
|
+
_(obj.b).must_equal 3
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "resets write alignment" do
|
|
22
22
|
obj.assign(a: 2, b: 7)
|
|
23
23
|
|
|
24
|
-
obj.to_binary_s.must_equal_binary "\x20\x70"
|
|
24
|
+
_(obj.to_binary_s).must_equal_binary "\x20\x70"
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
describe BinData::BitAligned do
|
|
29
29
|
it "does not apply to BinData::Primitives" do
|
|
30
|
-
|
|
30
|
+
_ {
|
|
31
31
|
class BitAlignedPrimitive < BinData::Primitive
|
|
32
32
|
bit_aligned
|
|
33
33
|
end
|
|
@@ -47,20 +47,20 @@ describe BinData::BitAligned do
|
|
|
47
47
|
let(:obj) { BitAlignedRecord.new }
|
|
48
48
|
|
|
49
49
|
it "#num_bytes as expected" do
|
|
50
|
-
obj.num_bytes.must_equal 3
|
|
50
|
+
_(obj.num_bytes).must_equal 3
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
it "has expected abs_offset" do
|
|
54
|
-
obj.str.abs_offset.must_equal 0
|
|
54
|
+
_(obj.str.abs_offset).must_equal 0
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it "reads as expected" do
|
|
58
58
|
obj.read("\x56\x36\x42")
|
|
59
|
-
obj.snapshot.must_equal({preamble: 5, str: "cd", afterward: 2})
|
|
59
|
+
_(obj.snapshot).must_equal({preamble: 5, str: "cd", afterward: 2})
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "writes as expected" do
|
|
63
63
|
obj.assign(preamble: 5, str: "ab", afterward: 1)
|
|
64
|
-
obj.to_binary_s.must_equal_binary "\x56\x16\x21"
|
|
64
|
+
_(obj.to_binary_s).must_equal_binary "\x56\x16\x21"
|
|
65
65
|
end
|
|
66
66
|
end
|