Module: Origami::HintTable

Included in:
PageOffsetTable, SharedObjectTable
Defined in:
lib/origami/linearization.rb

Defined Under Namespace

Modules: ClassMethods Classes: PageOffsetTable, SharedObjectTable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



174
175
176
# File 'lib/origami/linearization.rb', line 174

def entries
  @entries
end

#header_itemsObject

Returns the value of attribute header_items.



173
174
175
# File 'lib/origami/linearization.rb', line 173

def header_items
  @header_items
end

Class Method Details

.included(receiver) ⇒ Object



167
168
169
170
171
# File 'lib/origami/linearization.rb', line 167

def self.included(receiver)
  receiver.instance_variable_set(:@header_items_size, {})
  receiver.instance_variable_set(:@entry_items_size, {})
  receiver.extend(ClassMethods)
end

Instance Method Details

#initializeObject



176
177
178
179
# File 'lib/origami/linearization.rb', line 176

def initialize
  @header_items = {}
  @entries = []
end

#to_sObject



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/origami/linearization.rb', line 181

def to_s
  data = ""

  nitems = self.class.nb_header_items
  (1..nitems).each do |no|
    unless @header_items.include?(no)
      raise InvalidHintTableError, "Missing item #{no} in header section of #{self.class}"
    end

    value = @header_items[no]
    item_size = self.class.get_header_item_size(no)

    item_size = ((item_size + 7) >> 3) << 3
    item_data = value.to_s(2)
    item_data = "0" * (item_size - item_data.size) + item_data

    data << [item_data].pack("B*")
  end

  nitems = self.class.nb_entry_items
  @entries.each_with_index do |entry, i|
    (1..nitems).each do |no|
      unless entry.include?(no)
        raise InvalidHintTableError, "Missing item #{no} in entry #{i} of #{self.class}"
      end

      value = entry[no]
      item_size = self.class.get_entry_item_size(no)

      item_size = ((item_size + 7) >> 3) << 3
      item_data = value.to_s(2)
      item_data = "0" * (item_size - item_data.size) + item_data

      data << [item_data].pack("B*")
    end
  end

  data
end