class WORF::Tag

Constants

FORM_TO_UNPACK
UNPACK_TO_LEN

Attributes

index[R]
type[R]

Public Class Methods

build(index, type, has_children, attr_names, attr_forms) click to toggle source
# File lib/worf.rb, line 61
def self.build index, type, has_children, attr_names, attr_forms
  if attr_forms.all? { |x| FORM_TO_UNPACK.key?(x) }
    packs = attr_forms.map { |x| FORM_TO_UNPACK[x] }
    readlen = packs.map { |p| UNPACK_TO_LEN[p] }.sum
    FixedWidthTag.new index, type, has_children, attr_names, attr_forms, packs.join, readlen
  else
    new index, type, has_children, attr_names, attr_forms
  end
end
new(index, type, has_children, attr_names, attr_forms) click to toggle source
# File lib/worf.rb, line 71
def initialize index, type, has_children, attr_names, attr_forms
  @index        = index
  @type         = type
  @has_children = has_children
  @attr_names   = attr_names
  @attr_forms   = attr_forms
end

Public Instance Methods

attribute_info(name) { |attr_forms, i| ... } click to toggle source
# File lib/worf.rb, line 93
def attribute_info name
  i = index_of(name) || return
  yield @attr_forms, i
end
decode(io, _) click to toggle source
# File lib/worf.rb, line 102
def decode io, _
  @attr_forms.map do |type|
    case type
    when Constants::DW_FORM_addr       then io.read(8).unpack1("Q")
    when Constants::DW_FORM_strp       then io.read(4).unpack1("L")
    when Constants::DW_FORM_data1      then io.read(1).unpack1("C")
    when Constants::DW_FORM_data2      then io.read(2).unpack1("S")
    when Constants::DW_FORM_data4      then io.read(4).unpack1("L")
    when Constants::DW_FORM_data8      then io.read(8).unpack1("Q")
    when Constants::DW_FORM_sec_offset then io.read(4).unpack1("L")
    when Constants::DW_FORM_ref_addr   then io.read(4).unpack1("L")
    when Constants::DW_FORM_ref4       then io.read(4).unpack1("L")
    when Constants::DW_FORM_flag_present
      true
    when Constants::DW_FORM_exprloc
      io.read(WORF.unpackULEB128(io))
    when Constants::DW_FORM_string
      str = []
      loop do
        x = io.readbyte
        break if x == 0
        str << x
      end

      str.pack("C*")
    when Constants::DW_FORM_flag
      io.readbyte
    when Constants::DW_FORM_block1
      io.read io.readbyte
    when Constants::DW_FORM_udata
      WORF.unpackULEB128 io
    when Constants::DW_FORM_sdata
      WORF.unpackSLEB128 io
    else
      raise "Unhandled type: #{Constants.form_for(type)}"
    end
  end
end
has_children?() click to toggle source
# File lib/worf.rb, line 83
def has_children?; @has_children; end
identifier() click to toggle source
# File lib/worf.rb, line 89
def identifier
  Constants.tag_for(@type)
end
index_of(name) click to toggle source
# File lib/worf.rb, line 98
def index_of name
  @attr_names.index(name)
end
inspect() click to toggle source
# File lib/worf.rb, line 141
def inspect
  names = @attr_names.map { |k| Constants.at_for(k) || :Custom }
  forms = @attr_forms.map { |v| Constants.form_for(v) }
  maxlen = names.map { |x| x.length }.max || 0

  "[#{@index}] #{Constants.tag_for(@type)} #{@has_children ? "children" : "no children"}\n" +
    names.zip(forms).map { |k,v| "        #{k.to_s.ljust(maxlen)} #{v}" }.join("\n")

end
user?() click to toggle source
# File lib/worf.rb, line 85
def user?
  @type > Constants::DW_TAG_low_user
end