bindata 1.6.0 → 1.8.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.
- data/.gitignore +1 -0
- data/.travis.yml +5 -0
- data/ChangeLog.rdoc +9 -0
- data/README.md +8 -1
- data/doc/manual.md +27 -2
- data/examples/tcp_ip.rb +179 -0
- data/lib/bindata.rb +4 -2
- data/lib/bindata/base.rb +2 -2
- data/lib/bindata/buffer.rb +119 -0
- data/lib/bindata/dsl.rb +41 -0
- data/lib/bindata/io.rb +321 -190
- data/lib/bindata/primitive.rb +6 -0
- data/lib/bindata/record.rb +1 -37
- data/lib/bindata/registry.rb +27 -23
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +25 -19
- data/test/buffer_test.rb +144 -0
- data/test/common.rb +1 -1
- data/test/io_test.rb +117 -51
- data/test/lazy_test.rb +12 -12
- data/test/primitive_test.rb +20 -0
- data/test/registry_test.rb +23 -0
- data/test/virtual_test.rb +38 -0
- metadata +9 -4
data/test/lazy_test.rb
CHANGED
@@ -73,16 +73,16 @@ end
|
|
73
73
|
|
74
74
|
describe BinData::LazyEvaluator, "with one parent" do
|
75
75
|
subject {
|
76
|
-
parent_methods = {:m1 => 'Pm1', :
|
77
|
-
parent_params = {:p1 => 'Pp1', :
|
76
|
+
parent_methods = {:m1 => 'Pm1', :com1 => 'PmC', :mm => 3}
|
77
|
+
parent_params = {:p1 => 'Pp1', :com1 => 'PpC'}
|
78
78
|
parent_obj = MockBinDataObject.new(parent_methods, parent_params)
|
79
79
|
|
80
80
|
def parent_obj.echo(a1, a2)
|
81
81
|
[a1, a2]
|
82
82
|
end
|
83
83
|
|
84
|
-
methods = {:m1 => 'm1', :
|
85
|
-
params = {:p1 => 'p1', :
|
84
|
+
methods = {:m1 => 'm1', :com1 => 'mC'}
|
85
|
+
params = {:p1 => 'p1', :com1 => 'pC'}
|
86
86
|
MockBinDataObject.new(methods, params, parent_obj)
|
87
87
|
}
|
88
88
|
|
@@ -119,7 +119,7 @@ describe BinData::LazyEvaluator, "with one parent" do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it "resolves parameters in preference to methods in the parent" do
|
122
|
-
lazy_eval(lambda {
|
122
|
+
lazy_eval(lambda { com1 }).must_equal 'PpC'
|
123
123
|
end
|
124
124
|
|
125
125
|
it "has a parent" do
|
@@ -133,8 +133,8 @@ end
|
|
133
133
|
|
134
134
|
describe BinData::LazyEvaluator, "with nested parents" do
|
135
135
|
subject {
|
136
|
-
pparent_methods = {:m1 => 'PPm1', :m2 => 'PPm2', :
|
137
|
-
pparent_params = {:p1 => 'PPp1', :p2 => 'PPp2', :
|
136
|
+
pparent_methods = {:m1 => 'PPm1', :m2 => 'PPm2', :com1 => 'PPmC'}
|
137
|
+
pparent_params = {:p1 => 'PPp1', :p2 => 'PPp2', :com1 => 'PPpC'}
|
138
138
|
pparent_obj = MockBinDataObject.new(pparent_methods, pparent_params)
|
139
139
|
|
140
140
|
def pparent_obj.echo(arg)
|
@@ -145,16 +145,16 @@ describe BinData::LazyEvaluator, "with nested parents" do
|
|
145
145
|
["PP2", arg]
|
146
146
|
end
|
147
147
|
|
148
|
-
parent_methods = {:m1 => 'Pm1', :
|
149
|
-
parent_params = {:p1 => 'Pp1', :
|
148
|
+
parent_methods = {:m1 => 'Pm1', :com1 => 'PmC', :sym1 => :m2, :sym2 => lambda { m2 }}
|
149
|
+
parent_params = {:p1 => 'Pp1', :com1 => 'PpC'}
|
150
150
|
parent_obj = MockBinDataObject.new(parent_methods, parent_params, pparent_obj)
|
151
151
|
|
152
152
|
def parent_obj.echo(arg)
|
153
153
|
["P", arg]
|
154
154
|
end
|
155
155
|
|
156
|
-
methods = {:m1 => 'm1', :
|
157
|
-
params = {:p1 => 'p1', :
|
156
|
+
methods = {:m1 => 'm1', :com1 => 'mC'}
|
157
|
+
params = {:p1 => 'p1', :com1 => 'pC'}
|
158
158
|
MockBinDataObject.new(methods, params, parent_obj)
|
159
159
|
}
|
160
160
|
|
@@ -198,7 +198,7 @@ describe BinData::LazyEvaluator, "with nested parents" do
|
|
198
198
|
end
|
199
199
|
|
200
200
|
it "resolves parameters in preference to methods in the parent" do
|
201
|
-
lazy_eval(lambda {
|
201
|
+
lazy_eval(lambda { com1 }).must_equal 'PpC'
|
202
202
|
end
|
203
203
|
|
204
204
|
it "resolves methods in the parent explicitly" do
|
data/test/primitive_test.rb
CHANGED
@@ -188,3 +188,23 @@ describe BinData::Primitive, "subclassed with default parameter" do
|
|
188
188
|
a.to_binary_s.must_equal "\000\005"
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
describe BinData::Primitive, "with mutating #get and #set" do
|
193
|
+
class MutatingPrimitive < BinData::Primitive
|
194
|
+
uint16le :a
|
195
|
+
def get; self.a; end
|
196
|
+
def set(v); self.a = v.abs; end
|
197
|
+
end
|
198
|
+
|
199
|
+
it "#assign applies mutator" do
|
200
|
+
obj = MutatingPrimitive.new
|
201
|
+
obj.assign(-50)
|
202
|
+
obj.snapshot.must_equal 50
|
203
|
+
end
|
204
|
+
|
205
|
+
it "#to_binary_s applies mutator" do
|
206
|
+
obj = MutatingPrimitive.new
|
207
|
+
obj.assign(-50)
|
208
|
+
obj.to_binary_s.must_equal "\062\000"
|
209
|
+
end
|
210
|
+
end
|
data/test/registry_test.rb
CHANGED
@@ -102,3 +102,26 @@ describe BinData::Registry, "with numerics" do
|
|
102
102
|
r.lookup("bit3le", :little).to_s.must_equal "BinData::Bit3le"
|
103
103
|
end
|
104
104
|
end
|
105
|
+
|
106
|
+
describe BinData::Registry, "with endian specific types" do
|
107
|
+
let(:r) { BinData::Registry.new }
|
108
|
+
|
109
|
+
before do
|
110
|
+
r.register('a_le', A)
|
111
|
+
r.register('b_be', B)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "lookup little endian types" do
|
115
|
+
r.lookup('a', :little).must_equal A
|
116
|
+
end
|
117
|
+
|
118
|
+
it "lookup big endian types" do
|
119
|
+
r.lookup('b', :big).must_equal B
|
120
|
+
end
|
121
|
+
|
122
|
+
it "does not lookup types with non existent endian" do
|
123
|
+
lambda {
|
124
|
+
r.lookup('a', :big)
|
125
|
+
}.must_raise BinData::UnRegisteredTypeError
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "common"))
|
4
|
+
|
5
|
+
describe BinData::Virtual do
|
6
|
+
let(:stream) { StringIO.new "abcdefghij" }
|
7
|
+
|
8
|
+
it "must not read from any stream" do
|
9
|
+
BinData::Virtual.read(stream)
|
10
|
+
stream.pos.must_equal 0
|
11
|
+
end
|
12
|
+
|
13
|
+
it "must not write to a stream" do
|
14
|
+
obj = BinData::Virtual.new
|
15
|
+
obj.to_binary_s.must_equal ""
|
16
|
+
end
|
17
|
+
|
18
|
+
it "occupies no space" do
|
19
|
+
obj = BinData::Virtual.new
|
20
|
+
obj.num_bytes.must_equal 0
|
21
|
+
end
|
22
|
+
|
23
|
+
it "asserts on #read" do
|
24
|
+
data = []
|
25
|
+
obj = BinData::Virtual.new(:assert => lambda { data << 1 })
|
26
|
+
|
27
|
+
obj.read ""
|
28
|
+
data.must_equal [1]
|
29
|
+
end
|
30
|
+
|
31
|
+
it "asserts on #assign" do
|
32
|
+
data = []
|
33
|
+
obj = BinData::Virtual.new(:assert => lambda { data << 1 })
|
34
|
+
|
35
|
+
obj.assign("foo")
|
36
|
+
data.must_equal [1]
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 8
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dion Mendel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2014-01-06 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -109,6 +109,7 @@ extra_rdoc_files:
|
|
109
109
|
- NEWS.rdoc
|
110
110
|
files:
|
111
111
|
- .gitignore
|
112
|
+
- .travis.yml
|
112
113
|
- BSDL
|
113
114
|
- COPYING
|
114
115
|
- ChangeLog.rdoc
|
@@ -125,12 +126,14 @@ files:
|
|
125
126
|
- examples/ip_address.rb
|
126
127
|
- examples/list.rb
|
127
128
|
- examples/nbt.rb
|
129
|
+
- examples/tcp_ip.rb
|
128
130
|
- lib/bindata.rb
|
129
131
|
- lib/bindata/alignment.rb
|
130
132
|
- lib/bindata/array.rb
|
131
133
|
- lib/bindata/base.rb
|
132
134
|
- lib/bindata/base_primitive.rb
|
133
135
|
- lib/bindata/bits.rb
|
136
|
+
- lib/bindata/buffer.rb
|
134
137
|
- lib/bindata/choice.rb
|
135
138
|
- lib/bindata/count_bytes_remaining.rb
|
136
139
|
- lib/bindata/deprecated.rb
|
@@ -162,6 +165,7 @@ files:
|
|
162
165
|
- test/base_primitive_test.rb
|
163
166
|
- test/base_test.rb
|
164
167
|
- test/bits_test.rb
|
168
|
+
- test/buffer_test.rb
|
165
169
|
- test/choice_test.rb
|
166
170
|
- test/common.rb
|
167
171
|
- test/count_bytes_remaining_test.rb
|
@@ -181,6 +185,7 @@ files:
|
|
181
185
|
- test/stringz_test.rb
|
182
186
|
- test/struct_test.rb
|
183
187
|
- test/system_test.rb
|
188
|
+
- test/virtual_test.rb
|
184
189
|
has_rdoc: true
|
185
190
|
homepage: http://github.com/dmendel/bindata
|
186
191
|
licenses:
|