This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerger_types.go
87 lines (71 loc) · 1.74 KB
/
merger_types.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
package distnano
import (
"encoding/json"
"log"
"reflect"
)
type Child struct {
Path []uint `json:"path,omitempty"`
X *int `json:"x,omitempty"`
Y *int `json:"y,omitempty"`
Val *int `json:"val,omitempty"`
Children []Child `json:"children,omitempty"`
}
type Root struct {
Val *int `json:"val,omitempty"`
Children []Child `json:"children,omitempty"`
}
type NanocubeResponse struct {
Layers []string `json:"layers"`
Root Root `json:"root"`
}
type Field struct {
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Valnames map[string]int `json:"valnames"`
}
type Metadata struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
}
type SchemaResponse struct {
Fields []Field `json:"fields"`
Metadata []Metadata `json:"metadata"`
}
type JSONResponse interface {
Marshal() ([]byte, error)
Unmarshal([]byte) error
Merge(JSONResponse)
}
func (n *NanocubeResponse) Marshal() ([]byte, error) {
return json.Marshal(n)
}
func (n *NanocubeResponse) Unmarshal(b []byte) error {
return json.Unmarshal(b, n)
}
func (n *NanocubeResponse) Merge(j JSONResponse) {
ncr, ok := j.(*NanocubeResponse)
if !ok {
log.Fatal(
"Tried to merge NanocubeResponse with unexpected type %v\n",
reflect.TypeOf(j),
)
}
mergeNanocubeResponse(n, ncr)
}
func (s *SchemaResponse) Marshal() ([]byte, error) {
return json.Marshal(s)
}
func (s *SchemaResponse) Unmarshal(b []byte) error {
return json.Unmarshal(b, s)
}
func (s *SchemaResponse) Merge(j JSONResponse) {
scr, ok := j.(*SchemaResponse)
if !ok {
log.Fatal(
"Tried to merge SchemaResponse with unexpected type %v\n",
reflect.TypeOf(j),
)
}
mergeSchemaResponse(s, scr)
}