-
Notifications
You must be signed in to change notification settings - Fork 20
/
unpack.go
114 lines (101 loc) · 3.37 KB
/
unpack.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package clout
import (
"errors"
"fmt"
"github.com/tliron/go-ard"
)
func Unpack(map_ ard.Map) (*Clout, error) {
clout := NewClout()
if data, ok := map_["version"]; ok {
if version, ok := data.(string); ok {
clout.Version = version
} else {
return nil, fmt.Errorf("malformed Clout: \"version\" not a string: %T", data)
}
} else {
return nil, errors.New("malformed Clout: no \"version\"")
}
if data, ok := map_["metadata"]; ok {
if metadata, ok := data.(ard.Map); ok {
clout.Metadata = ard.CopyMapsToStringMaps(metadata).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed Clout: \"metadata\" not a map: %T", data)
}
}
if data, ok := map_["properties"]; ok {
if properties, ok := data.(ard.Map); ok {
clout.Properties = ard.CopyMapsToStringMaps(properties).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed Clout: \"properties\" not a map: %T", data)
}
}
if data, ok := map_["vertexes"]; ok {
if vertexes, ok := data.(ard.Map); ok {
for key, data := range vertexes {
if id, ok := key.(string); ok {
if map_, ok := data.(ard.Map); ok {
vertex := clout.NewVertex(id)
if data, ok := map_["metadata"]; ok {
if metadata, ok := data.(ard.Map); ok {
vertex.Metadata = ard.CopyMapsToStringMaps(metadata).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed vertex: \"metadata\" not a map: %T", data)
}
}
if data, ok := map_["properties"]; ok {
if properties, ok := data.(ard.Map); ok {
vertex.Properties = ard.CopyMapsToStringMaps(properties).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed vertex: \"properties\" not a map: %T", data)
}
}
if data, ok := map_["edgesOut"]; ok {
if edgesOut, ok := data.(ard.List); ok {
for _, data := range edgesOut {
if map_, ok := data.(ard.Map); ok {
if data, ok := map_["targetID"]; ok {
if targetId, ok := data.(string); ok {
edge := vertex.NewEdgeToID(targetId)
if data, ok := map_["metadata"]; ok {
if metadata, ok := data.(ard.Map); ok {
edge.Metadata = ard.CopyMapsToStringMaps(metadata).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed edge: \"metadata\" not a map: %T", data)
}
}
if data, ok := map_["properties"]; ok {
if properties, ok := data.(ard.Map); ok {
edge.Properties = ard.CopyMapsToStringMaps(properties).(ard.StringMap)
} else {
return nil, fmt.Errorf("malformed edge: \"properties\" not a map: %T", data)
}
}
}
} else {
return nil, errors.New("malformed edge: no \"targetID\"")
}
} else {
return nil, fmt.Errorf("malformed edge: not a map: %T", data)
}
}
} else {
return nil, fmt.Errorf("malformed vertex: \"edgesOut\" not a list: %T", data)
}
}
} else {
return nil, fmt.Errorf("malformed vertex: not a map: %T", data)
}
} else {
return nil, fmt.Errorf("malformed vertex: id not a string: %T", key)
}
}
} else {
return nil, fmt.Errorf("malformed Clout: \"vertexes\" not a map: %T", data)
}
}
if err := clout.Resolve(); err == nil {
return clout, nil
} else {
return nil, err
}
}