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.



171
172
173
# File 'lib/origami/linearization.rb', line 171

def entries
  @entries
end

#header_itemsObject

Returns the value of attribute header_items.



170
171
172
# File 'lib/origami/linearization.rb', line 170

def header_items
  @header_items
end

Class Method Details

.included(receiver) ⇒ Object



164
165
166
167
168
# File 'lib/origami/linearization.rb', line 164

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



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

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

#to_sObject



178
179
180
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 178

def to_s
  data = ""

  nitems = self.class.nb_header_items
  for no in (1..nitems)
    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
  
  i = 0
  nitems = self.class.nb_entry_items
  @entries.each do |entry|
    for no in (1..items)
      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

    i = i + 1
  end

  data
end