forked from Velocidex/ordereddict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
75 lines (65 loc) · 1.31 KB
/
utils.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
package ordereddict
import "strings"
func GetString(event_map *Dict, members string) (string, bool) {
value, pres := GetAny(event_map, members)
if pres {
switch t := value.(type) {
case string:
return t, true
case *string:
return *t, true
}
}
return "", false
}
func GetMap(event_map *Dict, members string) (*Dict, bool) {
value, pres := GetAny(event_map, members)
if pres {
switch t := value.(type) {
case *Dict:
return t, true
}
}
return nil, false
}
func GetAny(event_map *Dict, members string) (interface{}, bool) {
var value interface{} = event_map
var pres bool
for _, member := range strings.Split(members, ".") {
if event_map == nil {
return nil, false
}
value, pres = event_map.Get(member)
if !pres {
return nil, false
}
event_map, pres = value.(*Dict)
}
return value, true
}
func GetInt(event_map *Dict, members string) (int, bool) {
value, pres := GetAny(event_map, members)
if pres {
switch t := value.(type) {
case int:
return t, true
case uint8:
return int(t), true
case uint16:
return int(t), true
case uint32:
return int(t), true
case uint64:
return int(t), true
case int8:
return int(t), true
case int16:
return int(t), true
case int32:
return int(t), true
case int64:
return int(t), true
}
}
return 0, false
}