class BinData::DelayedIO
- a struct if multiple fields are required.
:type
- The single type inside the delayed io. Use
:read_abs_offset
-
The abs_offset to start reading at.
an object. These params are:
Parameters may be provided at initialisation to control the behaviour of
== Parameters
s.to_binary_s #=> “hellox05”
s = ReversePascalString.read(“hellox05”)
end
uint8 :len, value: -> { str.length }
skip to_abs_offset: -> { total_size - 1 }
count_bytes_remaining :total_size
end
string read_length: :len
delayed_io :str, read_abs_offset: 0 do
auto_call_delayed_io
class ReversePascalString < BinData::Record
automatically perform the extra passes.
You can use theauto_call_delayed_io
keyword to cause #read and #write to
obj.to_binary_s { obj.write_now! } #=> “x00x00x00x11x12”
obj.read(“x00x00x00x11x12”) { obj.read_now! } #=> 0x1122
- OR -
obj #=> 0x1112
obj.read_now!
obj #=> 0
obj.read(“x00x00x00x11x12”)
obj = BinData::DelayedIO.new(read_abs_offset: 3, type: :uint16be)
require ‘bindata’
must specify the abs_offset of the I/O operation.
#write_now! methods to process an additional pass. This additional pass
#read or #write calls. The user must explicitly call the #read_now! or
DelayedIO supports multi pass processing. It works by ignoring the normal
reason is seeking backwards in the input stream.
However, some binary formats require multi pass processing. A common
BinData declarations are evaluated in a single pass.
- The single type inside the delayed io. Use
def abs_offset
def abs_offset @abs_offset || eval_parameter(:read_abs_offset) end
def abs_offset=(offset)
def abs_offset=(offset) @abs_offset = offset end
def assign(val)
def assign(val) @type.assign(val) end
def clear?
def clear? @type.clear? end
def do_num_bytes # :nodoc:
def do_num_bytes # :nodoc: 0 end
def do_read(io) # :nodoc:
def do_read(io) # :nodoc: @read_io = io end
def do_write(io) # :nodoc:
def do_write(io) # :nodoc: @write_io = io end
def include_obj?
def include_obj? !has_parameter?(:onlyif) || eval_parameter(:onlyif) end
def initialize_instance
def initialize_instance @type = get_parameter(:type).instantiate(nil, self) @abs_offset = nil @read_io = nil @write_io = nil end
def method_missing(symbol, *args, &block) # :nodoc:
def method_missing(symbol, *args, &block) # :nodoc: @type.__send__(symbol, *args, &block) end
def num_bytes
def num_bytes @type.num_bytes end
def read_now!
DelayedIO objects aren't read when #read is called.
def read_now! return unless include_obj? raise IOError, "read from where?" unless @read_io @read_io.seek_to_abs_offset(abs_offset) start_read do @type.do_read(@read_io) end end
def rel_offset
def rel_offset abs_offset end
def respond_to_missing?(symbol, include_all = false) # :nodoc:
def respond_to_missing?(symbol, include_all = false) # :nodoc: @type.respond_to?(symbol, include_all) || super end
def snapshot
def snapshot @type.snapshot end
def write_now!
DelayedIO objects aren't written when #write is called.
def write_now! return unless include_obj? raise IOError, "write to where?" unless @write_io @write_io.seek_to_abs_offset(abs_offset) @type.do_write(@write_io) end