Class: Scale::Types::MetadataV13

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/metadata/metadata_v13.rb

Instance Attribute Summary collapse

Attributes included from Base

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#==, included, #to_human

Constructor Details

#initialize(value) ⇒ MetadataV13

Returns a new instance of MetadataV13.



7
8
9
10
11
# File 'lib/metadata/metadata_v13.rb', line 7

def initialize(value)
  @call_index = {}
  @event_index = {}
  super(value)
end

Instance Attribute Details

#call_indexObject

Returns the value of attribute call_index.



5
6
7
# File 'lib/metadata/metadata_v13.rb', line 5

def call_index
  @call_index
end

#event_indexObject

Returns the value of attribute event_index.



5
6
7
# File 'lib/metadata/metadata_v13.rb', line 5

def event_index
  @event_index
end

Class Method Details

.decode(scale_bytes) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/metadata/metadata_v13.rb', line 13

def self.decode(scale_bytes)
  modules = Scale::Types.get("Vec<MetadataV13Module>").decode(scale_bytes).value

  value = {
    magicNumber: 1_635_018_093,
    metadata: {
      version: 12,
      modules: modules.map(&:value)
    }
  }

  result = MetadataV13.new(value)

  call_module_index = 0
  event_module_index = 0

  modules.map(&:value).each do |m|
    module_index = m[:index]
    if m[:calls]
      m[:calls].each_with_index do |call, index|
        call[:lookup] = "%02x%02x" % [module_index, index]
        result.call_index[call[:lookup]] = [m, call]
      end
    end

    if m[:events]
      m[:events].each_with_index do |event, index|
        event[:lookup] = "%02x%02x" % [module_index, index]
        result.event_index[event[:lookup]] = [m, event]
      end
    end
  end

  result
end