Class: MppReader::Blocks::VarMeta
- Inherits:
-
Object
- Object
- MppReader::Blocks::VarMeta
- 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
- #entries?(unique_id) ⇒ Boolean
-
#initialize(data) ⇒ VarMeta
constructor
A new instance of VarMeta.
- #offset(unique_id, type) ⇒ Object
- #unique_ids ⇒ Object
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
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_ids ⇒ Object
28 |
# File 'lib/mpp_reader/blocks/var_meta.rb', line 28 def unique_ids = @table.keys.sort |