BinData declarations are typically evaluated in a single pass. However, some binary formats require multi-pass processing, such as when you need to seek backwards in the input stream to read data based on values found later in the stream.
BinData::DelayedIO enables this by intercepting normal #read or #write calls and deferring the actual I/O operation. To execute the deferred operation, you must explicitly call #read_now! or #write_now!. These methods use the abs_offset provided during initialization to perform the I/O at the correct position in the stream.
Manual Execution
You can manually trigger the deferred read/write by calling the methods directly or by passing a block to the standard read/write methods:
# Manual call
obj.read_now!
# Using a block
obj.read("\x00\x00") { obj.read_now! }
require 'bindata'
obj = BinData::DelayedIO.new(read_abs_offset: 3, type: :uint16be)
obj.read("\x00\x00\x00\x11\x12")
obj #=> 0
obj.read_now!
obj #=> 0x1112