bindata 2.4.10 → 2.4.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 651bb61168cb520dbec6550dc4ee3d566e950a0a4e3c373752a37d9ced6dc17e
4
- data.tar.gz: 543f3849f0502255c976520e3d11f2e988f0733314b905d098b8617025ef2d99
3
+ metadata.gz: 3688cea66b3a68f7f45ecd4b89b632e9e4438ee40ff4f59c57bbe0a68130e7d6
4
+ data.tar.gz: 647a570fd024d8938297d2fb4d2ac0123d03befaf0e5d3441627601d86694d8f
5
5
  SHA512:
6
- metadata.gz: 5ab4ddc205727d64b5b4f1354c6c738965745ff6736030f440c3982799351e68af06c9f1e0faff28d6e52830a0abf55d678a0ea7ffefa160f9f7bf3c309b6e7b
7
- data.tar.gz: 834bdfa27436e578043e8b92ded99a02e6fc5ca2d0e11f0503bf3d8d68c1c7c9e491e66fe59f264156fb9675437cc9f014193f42132a8e6aec3a11b6f84f5312
6
+ metadata.gz: ddb2cd1156f3200fcc1bcce2d1a0bf5554f52babd692652debb71a8b56a9dced9c0f76db22884599f475b91d549f915344fcc1ec71a7f28be8dcb87192c968a5
7
+ data.tar.gz: ea223714bb2753b3b5dd626711dbffdc328ed326d2218a5ef2d8817ad797de66299d438dbf2ad8a9904ea774e758efd8c6bef47bafe51e391247d32acc92f5ee
data/ChangeLog.rdoc CHANGED
@@ -1,5 +1,13 @@
1
1
  = BinData Changelog
2
2
 
3
+ == Version 2.4.12 (2022-10-03)
4
+
5
+ * Do not include DelayedIO objects when :onlyif is false.
6
+
7
+ == Version 2.4.11 (2022-09-27)
8
+
9
+ * Make DelayedIO work with :onlyif. Reported by Spencer McIntyre.
10
+
3
11
  == Version 2.4.10 (2021-05-18)
4
12
 
5
13
  * Improve speed of dynamic object creation. Reported by Charlie Ablett.
@@ -116,9 +116,14 @@ module BinData
116
116
  0
117
117
  end
118
118
 
119
+ def include_obj?
120
+ ! has_parameter?(:onlyif) || eval_parameter(:onlyif)
121
+ end
122
+
119
123
  # DelayedIO objects aren't read when #read is called.
120
124
  # The reading is delayed until this method is called.
121
125
  def read_now!
126
+ return unless include_obj?
122
127
  raise IOError, "read from where?" unless @read_io
123
128
 
124
129
  @read_io.seekbytes(abs_offset - @read_io.offset)
@@ -130,7 +135,9 @@ module BinData
130
135
  # DelayedIO objects aren't written when #write is called.
131
136
  # The writing is delayed until this method is called.
132
137
  def write_now!
138
+ return unless include_obj?
133
139
  raise IOError, "write to where?" unless @write_io
140
+
134
141
  @write_io.seekbytes(abs_offset - @write_io.offset)
135
142
  @type.do_write(@write_io)
136
143
  end
@@ -1,4 +1,5 @@
1
1
  require 'bindata/base'
2
+ require 'bindata/delayed_io'
2
3
 
3
4
  module BinData
4
5
 
@@ -136,12 +137,12 @@ module BinData
136
137
 
137
138
  def do_read(io) #:nodoc:
138
139
  instantiate_all_objs
139
- @field_objs.each { |f| f.do_read(io) if include_obj?(f) }
140
+ @field_objs.each { |f| f.do_read(io) if include_obj_for_io?(f) }
140
141
  end
141
142
 
142
143
  def do_write(io) #:nodoc
143
144
  instantiate_all_objs
144
- @field_objs.each { |f| f.do_write(io) if include_obj?(f) }
145
+ @field_objs.each { |f| f.do_write(io) if include_obj_for_io?(f) }
145
146
  end
146
147
 
147
148
  def do_num_bytes #:nodoc:
@@ -263,6 +264,12 @@ module BinData
263
264
  end
264
265
  end
265
266
 
267
+ def include_obj_for_io?(obj)
268
+ # Used by #do_read and #do_write, to ensure the stream is passed to
269
+ # DelayedIO objects for delayed processing.
270
+ include_obj?(obj) || DelayedIO === obj
271
+ end
272
+
266
273
  def include_obj?(obj)
267
274
  !obj.has_parameter?(:onlyif) || obj.eval_parameter(:onlyif)
268
275
  end
@@ -1,3 +1,3 @@
1
1
  module BinData
2
- VERSION = "2.4.10"
2
+ VERSION = "2.4.12"
3
3
  end
@@ -184,6 +184,51 @@ describe BinData::DelayedIO, "inside a Record" do
184
184
  end
185
185
  end
186
186
 
187
+ describe BinData::DelayedIO, "inside a Record with onlyif" do
188
+ class DelayedIOOnlyIfRecord < BinData::Record
189
+ endian :little
190
+
191
+ uint8 :flag
192
+ delayed_io :my_int1, read_abs_offset: 4, onlyif: -> { flag != 0 } do
193
+ uint16 initial_value: 6
194
+ end
195
+ delayed_io :my_int2, read_abs_offset: 2, onlyif: -> { flag == 0 } do
196
+ uint16 initial_value: 7
197
+ end
198
+ end
199
+
200
+ it "reads" do
201
+ obj = DelayedIOOnlyIfRecord.read "\x01\x00\x03\x0012345"
202
+ obj.num_bytes.must_equal 1
203
+ obj.snapshot.must_equal({flag: 1, my_int1: 6})
204
+ end
205
+
206
+ it "reads explicitly when flag is set" do
207
+ obj = DelayedIOOnlyIfRecord.read "\x01\xff\x01\x00\x02\x00"
208
+ obj.my_int1.read_now!
209
+ obj.my_int2.read_now!
210
+ obj.num_bytes.must_equal 1
211
+ obj.snapshot.must_equal({flag: 1, my_int1: 2})
212
+ end
213
+
214
+ it "reads explicitly when flag is not set" do
215
+ obj = DelayedIOOnlyIfRecord.read "\x00\xff\x01\x00\x02\x00"
216
+ obj.my_int1.read_now!
217
+ obj.my_int2.read_now!
218
+ obj.num_bytes.must_equal 1
219
+ obj.snapshot.must_equal({flag: 0, my_int2: 1})
220
+ end
221
+
222
+ it "writes" do
223
+ obj = DelayedIOOnlyIfRecord.new(flag:1, my_int1: 3, my_int2: 4)
224
+ io = StringIO.new
225
+ obj.write(io)
226
+ obj.my_int1.write_now!
227
+ obj.my_int2.write_now!
228
+ io.value.must_equal "\x01\x00\x00\x00\x03\x00"
229
+ end
230
+ end
231
+
187
232
  describe BinData::DelayedIO, "with auto_call" do
188
233
  class AutoCallDelayedIORecord < BinData::Record
189
234
  auto_call_delayed_io
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bindata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.10
4
+ version: 2.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dion Mendel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-18 00:00:00.000000000 Z
11
+ date: 2022-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake