-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables.go
executable file
·78 lines (67 loc) · 1.29 KB
/
tables.go
1
2
3
4
5
6
7
8
9
10
11
12
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package abi
import (
"encoding/json"
"fmt"
)
type Table struct {
Name string
Type Type
StorageType uint64
Tables Tables
}
type Tables []Table
type Extarg struct {
Name string
Type string
StorageType uint64
Tables []Extarg
}
// UnmarshalJSON implements json.Unmarshaler interface
func (table *Table) UnmarshalJSON(data []byte) error {
var ext Extarg
err := json.Unmarshal(data, &ext)
if err != nil {
return fmt.Errorf("argument json err: %v", err)
}
err = ext.recursive(table)
if err != nil {
return err
}
return nil
}
func (ext *Extarg) recursive(table *Table) error {
if ext.Type == "" {
table.Type = Type{}
} else {
var err error
table.Type, err = NewType(ext.Type)
if err != nil {
return err
}
}
table.Name = ext.Name
table.StorageType = ext.StorageType
// table.Tables = ext.Name
if len(ext.Tables) != 0 {
for _, v := range ext.Tables {
t := &Table{}
err := v.recursive(t)
if err != nil {
return err
}
table.Tables = append(table.Tables, *t)
}
}
return nil
}
func (tbl Table) Traversal(sym string, key *Key) {
if len(tbl.Tables) == 0 {
key.Types[sym] = tbl.Type
key.Keys[sym] = tbl
} else {
for _, v := range tbl.Tables {
s := fmt.Sprintf("%s.%s", sym, v.Name)
v.Traversal(s, key)
}
}
}