class Kaitai::Struct::Struct
Common base class for all structured generated by Kaitai
Struct
. Stores stream object that this object was parsed from in {#_io}, stores reference to parent structure in {#_parent} and root structure in {#_root} and provides a few helper methods.
Attributes
Public Class Methods
Factory method to instantiate a Kaitai
Struct-powered structure, parsing it from a local file with a given filename. @param filename [String] local file to parse
# File lib/kaitai/struct/struct.rb, line 25 def self.from_file(filename) self.new(Stream.open(filename)) end
# File lib/kaitai/struct/struct.rb, line 15 def initialize(_io, _parent = nil, _root = self) @_io = _io @_parent = _parent @_root = _root end
Public Instance Methods
Implementation of {Object#inspect} to aid debugging (at the very least, to aid exception raising) for KS-based classes. This one uses a bit terser syntax than Ruby's default one, purposely skips any internal fields (i.e. starting with `_`, such as `_io`, `_parent` and `_root`) to reduce confusion, and does no recursivity tracking (as proper general-purpose `inspect` implementation should do) because there are no endless recursion in KS-based classes by design (except for already mentioned internal navigation variables).
# File lib/kaitai/struct/struct.rb, line 39 def inspect vars = [] instance_variables.each { |nsym| nstr = nsym.to_s # skip all internal variables next if nstr[0..1] == '@_' # strip mandatory `@` at the beginning of the name for brevity nstr = nstr[1..-1] nvalue = instance_variable_get(nsym).inspect vars << "#{nstr}=#{nvalue}" } "#{self.class}(#{vars.join(' ')})" end