Class: MppReader::Blocks::VarMeta

Inherits:
Object
  • Object
show all
Defined in:
lib/mpp_reader/blocks/var_meta.rb

Overview

Index for a Var2Data block: maps (unique_id, type) to the offset of the item’s payload. Layout (ported from MPXJ VarMeta12): 24-byte header (magic 0xFADFADBA or 0, unknown, item count, unknown x2, data size), then 12-byte entries of (unique_id:u32, offset:u32, type:u16, unknown:u16).

Constant Summary collapse

MAGIC =
0xFADFADBA

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ VarMeta

Returns a new instance of VarMeta.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mpp_reader/blocks/var_meta.rb', line 10

def initialize(data)
  magic = data.byteslice(0, 4).to_s.unpack1("V")
  unless magic.nil? || magic.zero? || magic == MAGIC
    raise CorruptFileError, format("bad VarMeta magic 0x%08x", magic)
  end

  item_count = data.byteslice(8, 4).to_s.unpack1("V").to_i
  @table = Hash.new { |h, k| h[k] = {} }
  pos = 24
  item_count.times do
    break if pos + 12 > data.bytesize

    unique_id, offset, type = data.byteslice(pos, 12).unpack("VVv")
    @table[unique_id][type] = offset
    pos += 12
  end
end

Instance Method Details

#entries?(unique_id) ⇒ Boolean

Returns:

  • (Boolean)


30
# File 'lib/mpp_reader/blocks/var_meta.rb', line 30

def entries?(unique_id) = @table.key?(unique_id)

#offset(unique_id, type) ⇒ Object



32
33
34
35
# File 'lib/mpp_reader/blocks/var_meta.rb', line 32

def offset(unique_id, type)
  entry = @table.fetch(unique_id, nil)
  entry && entry[type]
end

#unique_idsObject



28
# File 'lib/mpp_reader/blocks/var_meta.rb', line 28

def unique_ids = @table.keys.sort