bindata 2.5.0 → 2.5.1
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 +5 -0
- data/README.md +1 -1
- data/bindata.gemspec +2 -1
- data/lib/bindata/io.rb +1 -1
- data/lib/bindata/registry.rb +30 -35
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata.rb +2 -2
- data/test/test_helper.rb +8 -4
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c768f9ce67cbaab54614d38246801939b4bb65ad02be42996b08613ed07aa92
|
4
|
+
data.tar.gz: d0409b0247506c870c314d089a5a9e0b806a1ab8e0c5ed05b2c280d81b9472c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e8e7d1df5b3220dc61aca18e1aef0a026e09191c6a78cf63e7dd5b4c5437fb04f8db688f926c4e4048dba972518b970254236959948681b7335e1a1302bff6
|
7
|
+
data.tar.gz: 195f0a260ec3cbccaa4e2a2e060ae0cc65b9f843a0c17acafb426041bf0a7d3fe0e96a6ff46befa68ed6f4b36fc2655a3a458f138e5ab92c78684347f39abc8e
|
data/ChangeLog.rdoc
CHANGED
data/README.md
CHANGED
data/bindata.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.summary = 'A declarative way to read and write binary file formats'
|
9
9
|
s.author = 'Dion Mendel'
|
10
|
-
s.email = 'bindata@
|
10
|
+
s.email = 'bindata@dmau.org'
|
11
11
|
s.homepage = 'https://github.com/dmendel/bindata'
|
12
12
|
s.require_path = 'lib'
|
13
13
|
s.extra_rdoc_files = ['NEWS.rdoc']
|
@@ -31,4 +31,5 @@ Gem::Specification.new do |s|
|
|
31
31
|
format. It is an easier ( and more readable ) alternative to
|
32
32
|
ruby's #pack and #unpack methods.
|
33
33
|
END
|
34
|
+
s.metadata['changelog_uri'] = s.homepage + '/blob/master/ChangeLog.rdoc'
|
34
35
|
end
|
data/lib/bindata/io.rb
CHANGED
data/lib/bindata/registry.rb
CHANGED
@@ -36,14 +36,22 @@ module BinData
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def lookup(name, hints = {})
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
raise(UnRegisteredTypeError, name)
|
39
|
+
search_names(name, hints).each do |search|
|
40
|
+
register_dynamic_class(search)
|
41
|
+
if @registry.has_key?(search)
|
42
|
+
return @registry[search]
|
43
|
+
end
|
46
44
|
end
|
45
|
+
|
46
|
+
# give the user a hint if the endian keyword is missing
|
47
|
+
search_names(name, hints.merge(endian: :big)).each do |search|
|
48
|
+
register_dynamic_class(search)
|
49
|
+
if @registry.has_key?(search)
|
50
|
+
raise(UnRegisteredTypeError, "#{name}, do you need to specify endian?")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
raise(UnRegisteredTypeError, name)
|
47
55
|
end
|
48
56
|
|
49
57
|
# Convert CamelCase +name+ to underscore style.
|
@@ -60,27 +68,20 @@ module BinData
|
|
60
68
|
#---------------
|
61
69
|
private
|
62
70
|
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
nwe = name_with_endian(nwp, hints[:endian])
|
76
|
-
if registered?(nwe)
|
77
|
-
name = nwe
|
78
|
-
break
|
79
|
-
end
|
80
|
-
end
|
71
|
+
def search_names(name, hints)
|
72
|
+
base = underscore_name(name)
|
73
|
+
searches = []
|
74
|
+
|
75
|
+
search_prefix = [""] + Array(hints[:search_prefix])
|
76
|
+
search_prefix.each do |prefix|
|
77
|
+
nwp = name_with_prefix(base, prefix)
|
78
|
+
nwe = name_with_endian(nwp, hints[:endian])
|
79
|
+
|
80
|
+
searches << nwp
|
81
|
+
searches << nwe if nwe
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
+
searches
|
84
85
|
end
|
85
86
|
|
86
87
|
def name_with_prefix(name, prefix)
|
@@ -93,7 +94,7 @@ module BinData
|
|
93
94
|
end
|
94
95
|
|
95
96
|
def name_with_endian(name, endian)
|
96
|
-
return
|
97
|
+
return nil if endian.nil?
|
97
98
|
|
98
99
|
suffix = (endian == :little) ? 'le' : 'be'
|
99
100
|
if /^u?int\d+$/.match?(name)
|
@@ -103,17 +104,11 @@ module BinData
|
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
|
-
def registered?(name)
|
107
|
-
register_dynamic_class(name) unless @registry.key?(name)
|
108
|
-
|
109
|
-
@registry.key?(name)
|
110
|
-
end
|
111
|
-
|
112
107
|
def register_dynamic_class(name)
|
113
108
|
if /^u?int\d+(le|be)$/.match?(name) || /^s?bit\d+(le)?$/.match?(name)
|
114
109
|
class_name = name.gsub(/(?:^|_)(.)/) { $1.upcase }
|
115
110
|
begin
|
116
|
-
# call const_get for side
|
111
|
+
# call const_get for side effect of creating class
|
117
112
|
BinData.const_get(class_name)
|
118
113
|
rescue NameError
|
119
114
|
end
|
@@ -124,7 +119,7 @@ module BinData
|
|
124
119
|
prev_class = @registry[name]
|
125
120
|
if prev_class && prev_class != class_to_register
|
126
121
|
Kernel.warn "warning: replacing registered class #{prev_class} " \
|
127
|
-
|
122
|
+
"with #{class_to_register}"
|
128
123
|
end
|
129
124
|
end
|
130
125
|
end
|
data/lib/bindata/version.rb
CHANGED
data/lib/bindata.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# BinData -- Binary data manipulator.
|
2
|
-
# Copyright (c) 2007 -
|
2
|
+
# Copyright (c) 2007 - 2025 Dion Mendel.
|
3
3
|
|
4
4
|
require 'bindata/version'
|
5
5
|
require 'bindata/array'
|
@@ -35,4 +35,4 @@ require 'bindata/warnings'
|
|
35
35
|
#
|
36
36
|
# BinData is released under the same license as Ruby.
|
37
37
|
#
|
38
|
-
# Copyright (c) 2007 -
|
38
|
+
# Copyright (c) 2007 - 2025 Dion Mendel.
|
data/test/test_helper.rb
CHANGED
@@ -43,11 +43,15 @@ module Minitest::Assertions
|
|
43
43
|
ex = assert_raises(exp, &block)
|
44
44
|
assert_equal(msg, ex.message) if msg
|
45
45
|
|
46
|
-
|
46
|
+
line_num_regex = /(.*):(\d+)(:in.*)$/
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
filename = line_num_regex.match(ex.backtrace[0])[1]
|
49
|
+
|
50
|
+
filtered = ex.backtrace.grep(/^#{Regexp.escape(filename)}/)
|
51
|
+
top = filtered.grep(Regexp.new(Regexp.escape("in <top (required)>")))
|
52
|
+
|
53
|
+
err_line = line_num_regex.match(filtered[0])[2].to_i
|
54
|
+
ref_line = line_num_regex.match(top[0])[2].to_i - 1
|
51
55
|
|
52
56
|
assert_equal((err_line - ref_line), line)
|
53
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dion Mendel
|
@@ -59,7 +59,7 @@ 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: bindata@
|
62
|
+
email: bindata@dmau.org
|
63
63
|
executables: []
|
64
64
|
extensions: []
|
65
65
|
extra_rdoc_files:
|
@@ -149,7 +149,8 @@ files:
|
|
149
149
|
homepage: https://github.com/dmendel/bindata
|
150
150
|
licenses:
|
151
151
|
- BSD-2-Clause
|
152
|
-
metadata:
|
152
|
+
metadata:
|
153
|
+
changelog_uri: https://github.com/dmendel/bindata/blob/master/ChangeLog.rdoc
|
153
154
|
post_install_message:
|
154
155
|
rdoc_options:
|
155
156
|
- "--main"
|
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
168
|
- !ruby/object:Gem::Version
|
168
169
|
version: '0'
|
169
170
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
171
|
+
rubygems_version: 3.3.27
|
171
172
|
signing_key:
|
172
173
|
specification_version: 4
|
173
174
|
summary: A declarative way to read and write binary file formats
|