bindata 1.8.1 → 1.8.2
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/ChangeLog.rdoc +5 -0
- data/lib/bindata/base.rb +1 -1
- data/lib/bindata/base_primitive.rb +15 -8
- data/lib/bindata/version.rb +1 -1
- data/lib/bindata/virtual.rb +11 -19
- data/test/virtual_test.rb +12 -2
- metadata +4 -4
data/ChangeLog.rdoc
CHANGED
data/lib/bindata/base.rb
CHANGED
@@ -97,7 +97,10 @@ module BinData
|
|
97
97
|
def value
|
98
98
|
snapshot
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
|
+
def value=(val)
|
102
|
+
assign(val)
|
103
|
+
end
|
101
104
|
|
102
105
|
def respond_to?(symbol, include_private = false) #:nodoc:
|
103
106
|
child = snapshot
|
@@ -201,14 +204,18 @@ module BinData
|
|
201
204
|
def assert!
|
202
205
|
current_value = snapshot
|
203
206
|
expected = eval_parameter(:assert, :value => current_value)
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
elsif
|
208
|
-
|
209
|
-
|
210
|
-
|
207
|
+
|
208
|
+
msg = if not expected and current_value.nil?
|
209
|
+
"assertion failed"
|
210
|
+
elsif not expected
|
211
|
+
"value '#{current_value}' not as expected"
|
212
|
+
elsif expected != true and current_value != expected
|
213
|
+
"value is '#{current_value}' but expected '#{expected}'"
|
214
|
+
else
|
215
|
+
nil
|
211
216
|
end
|
217
|
+
|
218
|
+
raise ValidityError, "#{msg} for #{debug_name}" if msg
|
212
219
|
end
|
213
220
|
end
|
214
221
|
|
data/lib/bindata/version.rb
CHANGED
data/lib/bindata/virtual.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "bindata/base"
|
2
2
|
|
3
3
|
module BinData
|
4
|
-
# A virtual field is one that is neither read, written nor occupies space
|
5
|
-
# It is used to make assertions or as a convenient label
|
6
|
-
# offsets.
|
4
|
+
# A virtual field is one that is neither read, written nor occupies space in
|
5
|
+
# the data stream. It is used to make assertions or as a convenient label
|
6
|
+
# for determining offsets or storing values.
|
7
7
|
#
|
8
8
|
# require 'bindata'
|
9
9
|
#
|
@@ -26,28 +26,20 @@ module BinData
|
|
26
26
|
#
|
27
27
|
# [<tt>:assert</tt>] Raise an error when reading or assigning if the value
|
28
28
|
# of this evaluated parameter is false.
|
29
|
+
# [<tt>:value</tt>] The virtual object will always have this value.
|
29
30
|
#
|
30
|
-
class Virtual < BinData::
|
31
|
+
class Virtual < BinData::BasePrimitive
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
def clear?; true; end
|
35
|
-
def snapshot; nil; end
|
36
|
-
def do_num_bytes; 0; end
|
37
|
-
def do_write(io); end
|
38
|
-
|
39
|
-
def assign(val)
|
40
|
-
assert!
|
33
|
+
def value_to_binary_string(val)
|
34
|
+
""
|
41
35
|
end
|
42
36
|
|
43
|
-
def
|
44
|
-
|
37
|
+
def read_and_return_value(io)
|
38
|
+
nil
|
45
39
|
end
|
46
40
|
|
47
|
-
def
|
48
|
-
|
49
|
-
raise ValidityError, "assertion failed for #{debug_name}"
|
50
|
-
end
|
41
|
+
def sensible_default
|
42
|
+
nil
|
51
43
|
end
|
52
44
|
end
|
53
45
|
end
|
data/test/virtual_test.rb
CHANGED
@@ -22,7 +22,7 @@ describe BinData::Virtual do
|
|
22
22
|
|
23
23
|
it "asserts on #read" do
|
24
24
|
data = []
|
25
|
-
obj = BinData::Virtual.new(:assert => lambda { data << 1 })
|
25
|
+
obj = BinData::Virtual.new(:assert => lambda { data << 1; true })
|
26
26
|
|
27
27
|
obj.read ""
|
28
28
|
data.must_equal [1]
|
@@ -30,9 +30,19 @@ describe BinData::Virtual do
|
|
30
30
|
|
31
31
|
it "asserts on #assign" do
|
32
32
|
data = []
|
33
|
-
obj = BinData::Virtual.new(:assert => lambda { data << 1 })
|
33
|
+
obj = BinData::Virtual.new(:assert => lambda { data << 1; true })
|
34
34
|
|
35
35
|
obj.assign("foo")
|
36
36
|
data.must_equal [1]
|
37
37
|
end
|
38
|
+
|
39
|
+
it "assigns a value" do
|
40
|
+
obj = BinData::Virtual.new(3)
|
41
|
+
obj.must_equal 3
|
42
|
+
end
|
43
|
+
|
44
|
+
it "accepts the :value parameter" do
|
45
|
+
obj = BinData::Virtual.new(:value => 3)
|
46
|
+
obj.must_equal 3
|
47
|
+
end
|
38
48
|
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: 51
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 1.8.
|
9
|
+
- 2
|
10
|
+
version: 1.8.2
|
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: 2014-
|
18
|
+
date: 2014-02-02 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|