Class: Exerb::NameTable

Inherits:
Object
  • Object
show all
Defined in:
lib/exerb/name_table.rb

Overview

#

Defined Under Namespace

Classes: Entry, Header

Instance Method Summary collapse

Constructor Details

#initializeNameTable

Returns a new instance of NameTable


17
18
19
# File 'lib/exerb/name_table.rb', line 17

def initialize
  @entries = []
end

Instance Method Details

#add(name) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/exerb/name_table.rb', line 21

def add(name)
  @entries.find { |entry|
    if entry.name == name
      return entry.id
    end
  }

  @entries << Exerb::NameTable::Entry.new(@entries.size + 1, name)

  return @entries.last.id
end

#packObject


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/exerb/name_table.rb', line 33

def pack
  headers = ''
  pool    = ''

  @entries.each { |entry|
    headers << entry.pack_header(pool)
    pool    << entry.pack_pool
  }

  packed_headers = Exerb::Utility.alignment16(headers)
  packed_pool    = Exerb::Utility.alignment16(pool)

  table_header = Exerb::NameTable::Header.new
  table_header.signature         = Exerb::NameTable::Header::SIGNATURE
  table_header.number_of_headers = @entries.size
  table_header.offset_of_headers = Exerb::Utility.alignment16(table_header.pack).size
  table_header.offset_of_pool    = table_header.offset_of_headers + packed_headers.size

  return Exerb::Utility.alignment16(table_header.pack) + packed_headers + packed_pool
end