class BinData::Section
- multiple fields are required.
:type
- The single type inside the buffer. Use a struct if
:transform
-
A callable that returns a new BinData::IO::Transform.
an object. These params are:
Parameters may be provided at initialisation to control the behaviour of
== Parameters
obj.read(“x97x9Ax93x93x90”) #=> “hello”
type: [:string, read_length: 5])
obj = BinData::Section.new(transform: -> { XorTransform.new(0xff) },
end
end
chain_write(data.bytes.map { |byte| (byte ^ @xor).chr }.join)
def write(data)
end
chain_read(n).bytes.map { |byte| (byte ^ @xor).chr }.join
def read(n)
end
@xor = xor
super()
def initialize(xor)
class XorTransform < BinData::IO::Transform
require ‘bindata’
encodings. e.g. Some data data is compressed or encrypted.
data. This allows BinData to process a stream that has multiple
A Section is a layer on top of a stream that transforms the underlying
- The single type inside the buffer. Use a struct if
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: to_binary_s.size end
def do_read(io) # :nodoc:
def do_read(io) # :nodoc: io.transform(eval_parameter(:transform)) do |transformed_io, _raw_io| @type.do_read(transformed_io) end end
def do_write(io) # :nodoc:
def do_write(io) # :nodoc: io.transform(eval_parameter(:transform)) do |transformed_io, _raw_io| @type.do_write(transformed_io) end end
def initialize_instance
def initialize_instance @type = get_parameter(:type).instantiate(nil, self) end
def method_missing(symbol, *args, &block) # :nodoc:
def method_missing(symbol, *args, &block) # :nodoc: @type.__send__(symbol, *args, &block) 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