binary_struct 1.0.0 → 1.0.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.
- data/README.md +4 -0
- data/Rakefile +2 -1
- data/binary_struct.gemspec +1 -0
- data/lib/binary_struct.rb +28 -21
- data/lib/binary_struct/version.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/travis.yml +9 -0
- metadata +21 -4
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# BinaryStruct
|
2
2
|
|
3
|
+
[](https://travis-ci.org/ManageIQ/binary_struct)
|
4
|
+
[](https://codeclimate.com/github/ManageIQ/binary_struct)
|
5
|
+
[](https://coveralls.io/r/ManageIQ/binary_struct)
|
6
|
+
|
3
7
|
BinaryStruct is a class for dealing with binary structured data. It simplifies
|
4
8
|
expressing what the binary structure looks like, with the ability to name the
|
5
9
|
parts. Given this definition, it is easy to encode/decode the binary structure
|
data/Rakefile
CHANGED
data/binary_struct.gemspec
CHANGED
data/lib/binary_struct.rb
CHANGED
@@ -131,45 +131,52 @@ class BinaryStruct
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def self.sizeof(definition)
|
134
|
-
|
135
|
-
d = @@structs_by_definition[definition] = definition.kind_of?(self) ? definition : self.new(definition) if d.nil?
|
136
|
-
d.size
|
134
|
+
struct_by_definition(definition).size
|
137
135
|
end
|
138
136
|
|
139
137
|
def self.decode(data, definition)
|
140
|
-
|
141
|
-
d = @@structs_by_definition[definition] = definition.kind_of?(self) ? definition : self.new(definition) if d.nil?
|
142
|
-
d.decode(data)
|
138
|
+
struct_by_definition(definition).decode(data)
|
143
139
|
end
|
144
140
|
|
145
141
|
def self.encode(hash, definition)
|
146
|
-
|
147
|
-
d = @@structs_by_definition[definition] = definition.kind_of?(self) ? definition : self.new(definition) if d.nil?
|
148
|
-
d.encode(hash)
|
142
|
+
struct_by_definition(definition).encode(hash)
|
149
143
|
end
|
150
144
|
|
151
145
|
private
|
152
146
|
|
147
|
+
def self.struct_by_definition(definition)
|
148
|
+
@@structs_by_definition[definition] ||= definition.kind_of?(self) ? definition : self.new(definition)
|
149
|
+
end
|
150
|
+
|
153
151
|
def self.validate_definition(definition)
|
154
152
|
raise "definition must be an array of format/name pairs" if definition.empty? || definition.length % 2 != 0
|
155
|
-
definition.each_slice(2) do |format,
|
153
|
+
definition.each_slice(2) do |format, _|
|
156
154
|
type, count = format[0, 1], format[1..-1]
|
157
|
-
|
158
|
-
|
159
|
-
unless count.empty? || count == '*'
|
160
|
-
begin
|
161
|
-
count = Integer(count)
|
162
|
-
rescue
|
163
|
-
raise "unsupported count: #{count}"
|
164
|
-
end
|
165
|
-
raise "unsupported count: #{count}" if count < 0
|
166
|
-
end
|
155
|
+
validate_definition_entry_type(type)
|
156
|
+
validate_definition_entry_count(count)
|
167
157
|
end
|
168
158
|
end
|
169
159
|
|
160
|
+
def self.validate_definition_entry_type(type)
|
161
|
+
raise "unrecognized format: #{type}" unless SIZES.has_key?(type)
|
162
|
+
raise "unsupported format: #{type}" if SIZES[type].nil?
|
163
|
+
return true
|
164
|
+
end
|
165
|
+
|
166
|
+
def self.validate_definition_entry_count(count)
|
167
|
+
return true if count.empty? || count == '*'
|
168
|
+
|
169
|
+
begin
|
170
|
+
count = Integer(count)
|
171
|
+
rescue
|
172
|
+
raise "unsupported count: #{count}"
|
173
|
+
end
|
174
|
+
raise "unsupported count: #{count}" if count < 0
|
175
|
+
end
|
176
|
+
|
170
177
|
def self.get_size(definition)
|
171
178
|
size = 0
|
172
|
-
definition.each_slice(2) do |format,
|
179
|
+
definition.each_slice(2) do |format, _|
|
173
180
|
type, count = format[0, 1], format[1..-1]
|
174
181
|
count = count.empty? ? 1 : count.to_i
|
175
182
|
size += (count * SIZES[type])
|
data/spec/spec_helper.rb
CHANGED
data/travis.yml
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binary_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-04-
|
13
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -60,6 +60,22 @@ dependencies:
|
|
60
60
|
- - ! '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: coveralls
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
63
79
|
description: ! '
|
64
80
|
|
65
81
|
BinaryStruct is a class for dealing with binary structured data. It simplifies
|
@@ -91,6 +107,7 @@ files:
|
|
91
107
|
- spec/data/test.gif
|
92
108
|
- spec/gif_spec.rb
|
93
109
|
- spec/spec_helper.rb
|
110
|
+
- travis.yml
|
94
111
|
homepage: http://github.com/ManageIQ/binary_struct
|
95
112
|
licenses:
|
96
113
|
- MIT
|
@@ -106,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
123
|
version: '0'
|
107
124
|
segments:
|
108
125
|
- 0
|
109
|
-
hash:
|
126
|
+
hash: 944965749837137154
|
110
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
128
|
none: false
|
112
129
|
requirements:
|
@@ -115,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
132
|
version: '0'
|
116
133
|
segments:
|
117
134
|
- 0
|
118
|
-
hash:
|
135
|
+
hash: 944965749837137154
|
119
136
|
requirements: []
|
120
137
|
rubyforge_project:
|
121
138
|
rubygems_version: 1.8.24
|