bindata 1.4.3 → 1.4.4
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/BSDL +1 -1
- data/ChangeLog +8 -0
- data/NEWS +7 -0
- data/lib/bindata.rb +3 -3
- data/lib/bindata/base.rb +7 -0
- data/lib/bindata/base_primitive.rb +2 -2
- data/lib/bindata/choice.rb +4 -0
- data/lib/bindata/io.rb +1 -1
- data/lib/bindata/lazy.rb +2 -2
- data/lib/bindata/sanitize.rb +9 -0
- data/lib/bindata/string.rb +33 -16
- data/manual.haml +55 -53
- data/manual.md +346 -253
- data/spec/alignment_spec.rb +7 -7
- data/spec/array_spec.rb +67 -66
- data/spec/base_primitive_spec.rb +47 -49
- data/spec/base_spec.rb +70 -73
- data/spec/bits_spec.rb +14 -14
- data/spec/choice_spec.rb +44 -41
- data/spec/count_bytes_remaining_spec.rb +8 -11
- data/spec/deprecated_spec.rb +29 -29
- data/spec/float_spec.rb +12 -12
- data/spec/int_spec.rb +24 -24
- data/spec/io_spec.rb +56 -56
- data/spec/lazy_spec.rb +41 -39
- data/spec/primitive_spec.rb +31 -33
- data/spec/record_spec.rb +55 -57
- data/spec/registry_spec.rb +25 -25
- data/spec/rest_spec.rb +5 -5
- data/spec/skip_spec.rb +3 -3
- data/spec/spec_common.rb +2 -2
- data/spec/string_spec.rb +38 -38
- data/spec/stringz_spec.rb +18 -18
- data/spec/struct_spec.rb +48 -48
- data/spec/system_spec.rb +38 -37
- data/spec/wrapper_spec.rb +21 -23
- data/tasks/pkg.rake +3 -3
- data/tasks/rdoc.rake +1 -1
- data/tasks/rspec.rake +7 -7
- metadata +51 -53
data/BSDL
CHANGED
data/ChangeLog
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= BinData Changelog
|
2
2
|
|
3
|
+
== Version 1.4.4 (2012-06-21)
|
4
|
+
|
5
|
+
* Fixed bug where user defined boolean primitive wouldn't set its
|
6
|
+
value to false (reported by Frank Roland).
|
7
|
+
* Fixed infinite looping bug caused by nested Choices.
|
8
|
+
* Renamed String parameter :pad_char to :pad_byte.
|
9
|
+
* Updated manual.
|
10
|
+
|
3
11
|
== Version 1.4.3 (2011-10-01)
|
4
12
|
|
5
13
|
* Exceptions no longer ignored inside lambdas when reading until eof
|
data/NEWS
CHANGED
data/lib/bindata.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# BinData -- Binary data manipulator.
|
2
|
-
# Copyright (c) 2007 -
|
2
|
+
# Copyright (c) 2007 - 2012 Dion Mendel.
|
3
3
|
|
4
4
|
require 'bindata/array'
|
5
5
|
require 'bindata/bits'
|
@@ -30,7 +30,7 @@ require 'bindata/deprecated'
|
|
30
30
|
#
|
31
31
|
# BinData is released under the same license as Ruby.
|
32
32
|
#
|
33
|
-
# Copyright (c) 2007 -
|
33
|
+
# Copyright (c) 2007 - 2012 Dion Mendel.
|
34
34
|
module BinData
|
35
|
-
VERSION = "1.4.
|
35
|
+
VERSION = "1.4.4"
|
36
36
|
end
|
data/lib/bindata/base.rb
CHANGED
@@ -251,6 +251,13 @@ module BinData
|
|
251
251
|
other == snapshot
|
252
252
|
end
|
253
253
|
|
254
|
+
# A version of +respond_to?+ used by the lazy evaluator. It doesn't
|
255
|
+
# reinvoke the evaluator so as to avoid infinite evaluation loops.
|
256
|
+
def safe_respond_to?(symbol, include_private = false) #:nodoc:
|
257
|
+
respond_to?(symbol, include_private)
|
258
|
+
end
|
259
|
+
alias_method :orig_respond_to?, :respond_to? #:nodoc:
|
260
|
+
|
254
261
|
#---------------
|
255
262
|
private
|
256
263
|
|
@@ -179,7 +179,7 @@ module BinData
|
|
179
179
|
# 6. !clear? -> @value
|
180
180
|
|
181
181
|
def _value
|
182
|
-
@value
|
182
|
+
@value != nil ? @value : sensible_default()
|
183
183
|
end
|
184
184
|
|
185
185
|
def _value_with_value #:nodoc:
|
@@ -191,7 +191,7 @@ module BinData
|
|
191
191
|
end
|
192
192
|
|
193
193
|
def _value_with_initial_value #:nodoc:
|
194
|
-
@value
|
194
|
+
@value != nil ? @value : eval_parameter(:initial_value)
|
195
195
|
end
|
196
196
|
|
197
197
|
###########################################################################
|
data/lib/bindata/choice.rb
CHANGED
@@ -144,6 +144,10 @@ module BinData
|
|
144
144
|
current_choice.respond_to?(symbol, include_private) || super
|
145
145
|
end
|
146
146
|
|
147
|
+
def safe_respond_to?(symbol, include_private = false) #:nodoc:
|
148
|
+
orig_respond_to?(symbol, include_private)
|
149
|
+
end
|
150
|
+
|
147
151
|
def method_missing(symbol, *args, &block) #:nodoc:
|
148
152
|
current_choice.__send__(symbol, *args, &block)
|
149
153
|
end
|
data/lib/bindata/io.rb
CHANGED
data/lib/bindata/lazy.rb
CHANGED
@@ -63,7 +63,7 @@ module BinData
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def method_missing(symbol, *args)
|
66
|
-
return @overrides[symbol] if @overrides and @overrides.has_key?(symbol)
|
66
|
+
return @overrides[symbol] if defined? @overrides and @overrides.has_key?(symbol)
|
67
67
|
|
68
68
|
if @obj.parent
|
69
69
|
eval_symbol_in_parent_context(symbol, args)
|
@@ -85,7 +85,7 @@ module BinData
|
|
85
85
|
|
86
86
|
if obj_parent.has_parameter?(symbol)
|
87
87
|
result = obj_parent.get_parameter(symbol)
|
88
|
-
elsif obj_parent.
|
88
|
+
elsif obj_parent.safe_respond_to?(symbol)
|
89
89
|
result = obj_parent.__send__(symbol, *args)
|
90
90
|
else
|
91
91
|
result = symbol
|
data/lib/bindata/sanitize.rb
CHANGED
@@ -188,6 +188,15 @@ module BinData
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
+
def warn_renamed_parameter(old_key, new_key)
|
192
|
+
val = delete(old_key)
|
193
|
+
if val
|
194
|
+
self[new_key] = val
|
195
|
+
warn ":#{old_key} has been renamed to :#{new_key} in #{@the_class}. " +
|
196
|
+
"Using :#{old_key} is now deprecated and will be removed in the future"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
191
200
|
def endian
|
192
201
|
@endian || self[:endian]
|
193
202
|
end
|
data/lib/bindata/string.rb
CHANGED
@@ -25,7 +25,7 @@ module BinData
|
|
25
25
|
# obj #=> "abcd"
|
26
26
|
# obj.to_binary_s #=> "abcd\000\000"
|
27
27
|
#
|
28
|
-
# obj = BinData::String.new(:length => 6, :
|
28
|
+
# obj = BinData::String.new(:length => 6, :pad_byte => 'A')
|
29
29
|
# obj.assign("abcd")
|
30
30
|
# obj #=> "abcdAA"
|
31
31
|
# obj.to_binary_s #=> "abcdAA"
|
@@ -35,20 +35,20 @@ module BinData
|
|
35
35
|
# String objects accept all the params that BinData::BasePrimitive
|
36
36
|
# does, as well as the following:
|
37
37
|
#
|
38
|
-
# <tt>:read_length</tt>:: The length to use when reading a value.
|
38
|
+
# <tt>:read_length</tt>:: The length in bytes to use when reading a value.
|
39
39
|
# <tt>:length</tt>:: The fixed length of the string. If a shorter
|
40
40
|
# string is set, it will be padded to this length.
|
41
|
-
# <tt>:
|
41
|
+
# <tt>:pad_byte</tt>:: The byte to use when padding a string to a
|
42
42
|
# set length. Valid values are Integers and
|
43
43
|
# Strings of length 1. "\0" is the default.
|
44
44
|
# <tt>:trim_padding</tt>:: Boolean, default false. If set, #value will
|
45
|
-
# return the value with all
|
45
|
+
# return the value with all pad_bytes trimmed
|
46
46
|
# from the end of the string. The value will
|
47
47
|
# not be trimmed when writing.
|
48
48
|
class String < BinData::BasePrimitive
|
49
49
|
|
50
50
|
optional_parameters :read_length, :length, :trim_padding
|
51
|
-
default_parameters :
|
51
|
+
default_parameters :pad_byte => "\0"
|
52
52
|
mutually_exclusive_parameters :read_length, :length
|
53
53
|
mutually_exclusive_parameters :length, :value
|
54
54
|
|
@@ -57,27 +57,36 @@ module BinData
|
|
57
57
|
def sanitize_parameters!(params) #:nodoc:
|
58
58
|
params.warn_replacement_parameter(:initial_length, :read_length)
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
params.warn_renamed_parameter(:pad_char, :pad_byte) # Remove this line in the future
|
61
|
+
|
62
|
+
if params.has_parameter?(:pad_byte)
|
63
|
+
byte = params[:pad_byte]
|
64
|
+
params[:pad_byte] = sanitized_pad_byte(byte)
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
68
|
#-------------
|
67
69
|
private
|
68
70
|
|
69
|
-
def
|
70
|
-
result =
|
71
|
+
def sanitized_pad_byte(byte)
|
72
|
+
result = byte.is_a?(Integer) ? byte.chr : byte_string(byte.to_s.dup)
|
71
73
|
if result.length > 1
|
72
|
-
raise ArgumentError, ":
|
74
|
+
raise ArgumentError, ":pad_byte must not contain more than 1 byte"
|
73
75
|
end
|
74
76
|
result
|
75
77
|
end
|
78
|
+
|
79
|
+
def byte_string(str)
|
80
|
+
if RUBY_VERSION >= "1.9"
|
81
|
+
str.force_encoding(Encoding::BINARY)
|
82
|
+
else
|
83
|
+
str
|
84
|
+
end
|
85
|
+
end
|
76
86
|
end
|
77
87
|
|
78
88
|
def assign(val)
|
79
|
-
val
|
80
|
-
super(val)
|
89
|
+
super(byte_string(val.dup))
|
81
90
|
end
|
82
91
|
|
83
92
|
def snapshot
|
@@ -94,8 +103,16 @@ module BinData
|
|
94
103
|
#---------------
|
95
104
|
private
|
96
105
|
|
106
|
+
def byte_string(str)
|
107
|
+
if RUBY_VERSION >= "1.9"
|
108
|
+
str.force_encoding(Encoding::BINARY)
|
109
|
+
else
|
110
|
+
str
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
97
114
|
def clamp_to_length(str)
|
98
|
-
str
|
115
|
+
str = byte_string(str)
|
99
116
|
|
100
117
|
len = eval_parameter(:length) || str.length
|
101
118
|
if str.length == len
|
@@ -103,12 +120,12 @@ module BinData
|
|
103
120
|
elsif str.length > len
|
104
121
|
str.slice(0, len)
|
105
122
|
else
|
106
|
-
str + (eval_parameter(:
|
123
|
+
str + (eval_parameter(:pad_byte) * (len - str.length))
|
107
124
|
end
|
108
125
|
end
|
109
126
|
|
110
127
|
def trim_padding(str)
|
111
|
-
str.sub(/#{eval_parameter(:
|
128
|
+
str.sub(/#{eval_parameter(:pad_byte)}*$/, "")
|
112
129
|
end
|
113
130
|
|
114
131
|
def value_to_binary_string(val)
|
data/manual.haml
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
var TINY={};function T$(i){return document.getElementById(i)}function T$$(e,p){return p.getElementsByTagName(e)}TINY.accordion=function(){function slider(n){this.n=n;this.a=[]}slider.prototype.init=function(t,e,m,o,k){var a=T$(t),i=s=0,n=a.childNodes,l=n.length;this.s=k||0;this.m=m||0;for(i;i<l;i++){var v=n[i];if(v.nodeType!=3){this.a[s]={};this.a[s].h=h=T$$(e,v)[0];this.a[s].c=c=T$$('div',v)[0];h.onclick=new Function(this.n+'.pr(0,'+s+')');if(o==s){h.className=this.s;c.style.height='auto';c.d=1}else{c.style.height=0;c.d=-1}s++}}this.l=s};slider.prototype.pr=function(f,d){for(var i=0;i<this.l;i++){var h=this.a[i].h,c=this.a[i].c,k=c.style.height;k=k=='auto'?1:parseInt(k);clearInterval(c.t);if((k!=1&&c.d==-1)&&(f==1||i==d)){c.style.height='';c.m=c.offsetHeight;c.style.height=k+'px';c.d=1;h.className=this.s;su(c,1)}else if(k>0&&(f==-1||this.m||i==d)){c.d=-1;h.className='';su(c,-1)}}};function su(c){c.t=setInterval(function(){sl(c)},20)};function sl(c){var h=c.offsetHeight,d=c.d==1?c.m-h:h;c.style.height=h+(Math.ceil(d/5)*c.d)+'px';c.style.opacity=h/c.m;c.style.filter='alpha(opacity='+h*100/c.m+')';if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'}clearInterval(c.t)}};return{slider:slider}}();
|
11
11
|
|
12
12
|
var menu1, menu2, menu3, menu4, menu5, menu6, menu7;
|
13
|
-
var menu8, menu9, menu10, menu11, menu12, menu13, menu14;
|
13
|
+
var menu8, menu9, menu10, menu11, menu12, menu13, menu14, menu15;
|
14
14
|
|
15
15
|
function init_accordion() {
|
16
16
|
menu1 = new TINY.accordion.slider("menu1"); menu1.init("menu1","a",1,-1);
|
@@ -27,6 +27,7 @@
|
|
27
27
|
menu12 = new TINY.accordion.slider("menu12"); menu12.init("menu12","a",1,-1);
|
28
28
|
menu13 = new TINY.accordion.slider("menu13"); menu13.init("menu13","a",1,-1);
|
29
29
|
menu14 = new TINY.accordion.slider("menu14"); menu14.init("menu14","a",1,-1);
|
30
|
+
menu15 = new TINY.accordion.slider("menu15"); menu15.init("menu15","a",1,-1);
|
30
31
|
};
|
31
32
|
window.onload = init_accordion;
|
32
33
|
|
@@ -156,33 +157,12 @@
|
|
156
157
|
Overview
|
157
158
|
.acc-section
|
158
159
|
.acc-content
|
159
|
-
%li
|
160
|
-
%a{ :href => "#common_operations" }
|
161
|
-
Common Operations
|
162
|
-
.acc-section
|
163
|
-
.acc-content
|
164
|
-
%ul.level2#menu3
|
165
|
-
%li
|
166
|
-
%a{ :href => "#reading_and_writing" }
|
167
|
-
Reading and writing
|
168
|
-
.acc-section
|
169
|
-
.acc-content
|
170
|
-
%li
|
171
|
-
%a{ :href => "#manipulating" }
|
172
|
-
Manipulating
|
173
|
-
.acc-section
|
174
|
-
.acc-content
|
175
|
-
%li
|
176
|
-
%a{ :href => "#inspecting" }
|
177
|
-
Inspecting
|
178
|
-
.acc-section
|
179
|
-
.acc-content
|
180
160
|
%li
|
181
161
|
%a{ :href => "#records" }
|
182
162
|
Records
|
183
163
|
.acc-section
|
184
164
|
.acc-content
|
185
|
-
%ul.level2#
|
165
|
+
%ul.level2#menu3
|
186
166
|
%li
|
187
167
|
%a{ :href => "#specifying_default_endian" }
|
188
168
|
Specifying default endian
|
@@ -198,11 +178,6 @@
|
|
198
178
|
Nested Records
|
199
179
|
.acc-section
|
200
180
|
.acc-content
|
201
|
-
%li
|
202
|
-
%a{ :href => "#bitfields" }
|
203
|
-
Bitfields
|
204
|
-
.acc-section
|
205
|
-
.acc-content
|
206
181
|
%li
|
207
182
|
%a{ :href => "#optional_fields" }
|
208
183
|
Optional fields
|
@@ -213,13 +188,13 @@
|
|
213
188
|
Primitive Types
|
214
189
|
.acc-section
|
215
190
|
.acc-content
|
216
|
-
%ul.level2#
|
191
|
+
%ul.level2#menu4
|
217
192
|
%li
|
218
193
|
%a{ :href => "#numerics" }
|
219
194
|
Numerics
|
220
195
|
.acc-section
|
221
196
|
.acc-content
|
222
|
-
%ul.level3#
|
197
|
+
%ul.level3#menu5
|
223
198
|
%li
|
224
199
|
%a{ :href => "#byte_based_integers" }
|
225
200
|
Byte based integers
|
@@ -245,7 +220,7 @@
|
|
245
220
|
Strings
|
246
221
|
.acc-section
|
247
222
|
.acc-content
|
248
|
-
%ul.level3#
|
223
|
+
%ul.level3#menu6
|
249
224
|
%li
|
250
225
|
%a{ :href => "#fixed_sized_strings" }
|
251
226
|
Fixed Sized Strings
|
@@ -261,47 +236,74 @@
|
|
261
236
|
User-defined Primitive Types
|
262
237
|
.acc-section
|
263
238
|
.acc-content
|
264
|
-
%ul.level3#
|
239
|
+
%ul.level3#menu7
|
265
240
|
%li
|
266
241
|
%a{ :href => "#advanced_user_defined_primitive_types" }
|
267
242
|
Advanced Example
|
268
243
|
.acc-section
|
269
244
|
.acc-content
|
270
245
|
%li
|
271
|
-
%a{ :href => "#
|
272
|
-
|
246
|
+
%a{ :href => "#compound_types" }
|
247
|
+
Compound Types
|
273
248
|
.acc-section
|
274
249
|
.acc-content
|
275
|
-
%ul.level2#
|
250
|
+
%ul.level2#menu8
|
276
251
|
%li
|
277
|
-
%a{ :href => "#
|
278
|
-
|
252
|
+
%a{ :href => "#arrays" }
|
253
|
+
Arrays
|
279
254
|
.acc-section
|
280
255
|
.acc-content
|
256
|
+
%ul.level3#menu9
|
257
|
+
%li
|
258
|
+
%a{ :href => "#array_syntax" }
|
259
|
+
Array syntax
|
260
|
+
.acc-section
|
261
|
+
.acc-content
|
262
|
+
%li
|
263
|
+
%a{ :href => "#array_parameters" }
|
264
|
+
Array parameters
|
265
|
+
.acc-section
|
266
|
+
.acc-content
|
281
267
|
%li
|
282
|
-
%a{ :href => "#
|
283
|
-
|
268
|
+
%a{ :href => "#choices" }
|
269
|
+
Choices
|
284
270
|
.acc-section
|
285
271
|
.acc-content
|
272
|
+
%ul.level3#menu10
|
273
|
+
%li
|
274
|
+
%a{ :href => "#choice_syntax" }
|
275
|
+
Choice syntax
|
276
|
+
.acc-section
|
277
|
+
.acc-content
|
278
|
+
%li
|
279
|
+
%a{ :href => "#choice_parameters" }
|
280
|
+
Choice parameters
|
281
|
+
.acc-section
|
282
|
+
.acc-content
|
283
|
+
%li
|
284
|
+
%a{ :href => "#default_selection" }
|
285
|
+
Default Selection
|
286
|
+
.acc-section
|
287
|
+
.acc-content
|
286
288
|
%li
|
287
|
-
%a{ :href => "#
|
288
|
-
|
289
|
+
%a{ :href => "#common_operations" }
|
290
|
+
Common Operations
|
289
291
|
.acc-section
|
290
292
|
.acc-content
|
291
|
-
%ul.level2#
|
293
|
+
%ul.level2#menu11
|
292
294
|
%li
|
293
|
-
%a{ :href => "#
|
294
|
-
|
295
|
+
%a{ :href => "#reading_and_writing" }
|
296
|
+
Reading and writing
|
295
297
|
.acc-section
|
296
298
|
.acc-content
|
297
299
|
%li
|
298
|
-
%a{ :href => "#
|
299
|
-
|
300
|
+
%a{ :href => "#manipulating" }
|
301
|
+
Manipulating
|
300
302
|
.acc-section
|
301
303
|
.acc-content
|
302
304
|
%li
|
303
|
-
%a{ :href => "#
|
304
|
-
|
305
|
+
%a{ :href => "#inspecting" }
|
306
|
+
Inspecting
|
305
307
|
.acc-section
|
306
308
|
.acc-content
|
307
309
|
%li
|
@@ -309,7 +311,7 @@
|
|
309
311
|
Advanced Topics
|
310
312
|
.acc-section
|
311
313
|
.acc-content
|
312
|
-
%ul.level2#
|
314
|
+
%ul.level2#menu12
|
313
315
|
%li
|
314
316
|
%a{ :href => "#debugging" }
|
315
317
|
Debugging
|
@@ -336,7 +338,7 @@
|
|
336
338
|
Parameterizing Types
|
337
339
|
.acc-section
|
338
340
|
.acc-content
|
339
|
-
%ul.level3#
|
341
|
+
%ul.level3#menu14
|
340
342
|
%li
|
341
343
|
%a{ :href => "#mandatory_parameters" }
|
342
344
|
Mandatory Parameters
|
@@ -363,8 +365,8 @@
|
|
363
365
|
.acc-section
|
364
366
|
.acc-content
|
365
367
|
%li
|
366
|
-
%a{ :href => "#
|
367
|
-
|
368
|
+
%a{ :href => "#advanced_bitfields" }
|
369
|
+
Advanced Bitfields
|
368
370
|
.acc-section
|
369
371
|
.acc-content
|
370
372
|
%li
|
@@ -372,7 +374,7 @@
|
|
372
374
|
FAQ
|
373
375
|
.acc-section
|
374
376
|
.acc-content
|
375
|
-
%ul.level2#
|
377
|
+
%ul.level2#menu15
|
376
378
|
%li
|
377
379
|
%a{ :href => "#im_using_ruby_19_how_do_i_use_string_encodings_with_bindata" }
|
378
380
|
String encoding - Ruby 1.9
|