@@ -2,58 +2,100 @@ package pb
2
2
3
3
import "encoding/json"
4
4
5
- func (m * Op ) UnmarshalJSON (data []byte ) error {
6
- var v struct {
7
- Inputs []* Input `json:"inputs,omitempty"`
8
- Op struct {
9
- * Op_Exec
10
- * Op_Source
11
- * Op_File
12
- * Op_Build
13
- * Op_Merge
14
- * Op_Diff
15
- }
16
- Platform * Platform `json:"platform,omitempty"`
17
- Constraints * WorkerConstraints `json:"constraints,omitempty"`
5
+ type jsonOp struct {
6
+ Inputs []* Input `json:"inputs,omitempty"`
7
+ Op struct {
8
+ Exec * ExecOp `json:"exec,omitempty"`
9
+ Source * SourceOp `json:"source,omitempty"`
10
+ File * FileOp `json:"file,omitempty"`
11
+ Build * BuildOp `json:"build,omitempty"`
12
+ Merge * MergeOp `json:"merge,omitempty"`
13
+ Diff * DiffOp `json:"diff,omitempty"`
18
14
}
15
+ Platform * Platform `json:"platform,omitempty"`
16
+ Constraints * WorkerConstraints `json:"constraints,omitempty"`
17
+ }
18
+
19
+ func (m * Op ) MarshalJSON () ([]byte , error ) {
20
+ var v jsonOp
21
+ v .Inputs = m .Inputs
22
+ switch op := m .Op .(type ) {
23
+ case * Op_Exec :
24
+ v .Op .Exec = op .Exec
25
+ case * Op_Source :
26
+ v .Op .Source = op .Source
27
+ case * Op_File :
28
+ v .Op .File = op .File
29
+ case * Op_Build :
30
+ v .Op .Build = op .Build
31
+ case * Op_Merge :
32
+ v .Op .Merge = op .Merge
33
+ case * Op_Diff :
34
+ v .Op .Diff = op .Diff
35
+ }
36
+ v .Platform = m .Platform
37
+ v .Constraints = m .Constraints
38
+ return json .Marshal (v )
39
+ }
19
40
41
+ func (m * Op ) UnmarshalJSON (data []byte ) error {
42
+ var v jsonOp
20
43
if err := json .Unmarshal (data , & v ); err != nil {
21
44
return err
22
45
}
23
46
24
47
m .Inputs = v .Inputs
25
48
switch {
26
- case v .Op .Op_Exec != nil :
27
- m .Op = v .Op .Op_Exec
28
- case v .Op .Op_Source != nil :
29
- m .Op = v .Op .Op_Source
30
- case v .Op .Op_File != nil :
31
- m .Op = v .Op .Op_File
32
- case v .Op .Op_Build != nil :
33
- m .Op = v .Op .Op_Build
34
- case v .Op .Op_Merge != nil :
35
- m .Op = v .Op .Op_Merge
36
- case v .Op .Op_Diff != nil :
37
- m .Op = v .Op .Op_Diff
49
+ case v .Op .Exec != nil :
50
+ m .Op = & Op_Exec { v .Op .Exec }
51
+ case v .Op .Source != nil :
52
+ m .Op = & Op_Source { v .Op .Source }
53
+ case v .Op .File != nil :
54
+ m .Op = & Op_File { v .Op .File }
55
+ case v .Op .Build != nil :
56
+ m .Op = & Op_Build { v .Op .Build }
57
+ case v .Op .Merge != nil :
58
+ m .Op = & Op_Merge { v .Op .Merge }
59
+ case v .Op .Diff != nil :
60
+ m .Op = & Op_Diff { v .Op .Diff }
38
61
}
39
62
m .Platform = v .Platform
40
63
m .Constraints = v .Constraints
41
64
return nil
42
65
}
43
66
44
- func (m * FileAction ) UnmarshalJSON (data []byte ) error {
45
- var v struct {
46
- Input InputIndex `json:"input"`
47
- SecondaryInput InputIndex `json:"secondaryInput"`
48
- Output OutputIndex `json:"output"`
49
- Action struct {
50
- * FileAction_Copy
51
- * FileAction_Mkfile
52
- * FileAction_Mkdir
53
- * FileAction_Rm
54
- }
67
+ type jsonFileAction struct {
68
+ Input InputIndex `json:"input"`
69
+ SecondaryInput InputIndex `json:"secondaryInput"`
70
+ Output OutputIndex `json:"output"`
71
+ Action struct {
72
+ Copy * FileActionCopy `json:"copy,omitempty"`
73
+ Mkfile * FileActionMkFile `json:"mkfile,omitempty"`
74
+ Mkdir * FileActionMkDir `json:"mkdir,omitempty"`
75
+ Rm * FileActionRm `json:"rm,omitempty"`
76
+ }
77
+ }
78
+
79
+ func (m * FileAction ) MarshalJSON () ([]byte , error ) {
80
+ var v jsonFileAction
81
+ v .Input = InputIndex (m .Input )
82
+ v .SecondaryInput = InputIndex (m .SecondaryInput )
83
+ v .Output = OutputIndex (m .Output )
84
+ switch action := m .Action .(type ) {
85
+ case * FileAction_Copy :
86
+ v .Action .Copy = action .Copy
87
+ case * FileAction_Mkfile :
88
+ v .Action .Mkfile = action .Mkfile
89
+ case * FileAction_Mkdir :
90
+ v .Action .Mkdir = action .Mkdir
91
+ case * FileAction_Rm :
92
+ v .Action .Rm = action .Rm
55
93
}
94
+ return json .Marshal (v )
95
+ }
56
96
97
+ func (m * FileAction ) UnmarshalJSON (data []byte ) error {
98
+ var v jsonFileAction
57
99
if err := json .Unmarshal (data , & v ); err != nil {
58
100
return err
59
101
}
@@ -62,35 +104,47 @@ func (m *FileAction) UnmarshalJSON(data []byte) error {
62
104
m .SecondaryInput = int64 (v .SecondaryInput )
63
105
m .Output = int64 (v .Output )
64
106
switch {
65
- case v .Action .FileAction_Copy != nil :
66
- m .Action = v .Action .FileAction_Copy
67
- case v .Action .FileAction_Mkfile != nil :
68
- m .Action = v .Action .FileAction_Mkfile
69
- case v .Action .FileAction_Mkdir != nil :
70
- m .Action = v .Action .FileAction_Mkdir
71
- case v .Action .FileAction_Rm != nil :
72
- m .Action = v .Action .FileAction_Rm
107
+ case v .Action .Copy != nil :
108
+ m .Action = & FileAction_Copy { v .Action .Copy }
109
+ case v .Action .Mkfile != nil :
110
+ m .Action = & FileAction_Mkfile { v .Action .Mkfile }
111
+ case v .Action .Mkdir != nil :
112
+ m .Action = & FileAction_Mkdir { v .Action .Mkdir }
113
+ case v .Action .Rm != nil :
114
+ m .Action = & FileAction_Rm { v .Action .Rm }
73
115
}
74
116
return nil
75
117
}
76
118
77
- func (m * UserOpt ) UnmarshalJSON (data []byte ) error {
78
- var v struct {
79
- User struct {
80
- * UserOpt_ByName
81
- * UserOpt_ByID
82
- }
119
+ type jsonUserOpt struct {
120
+ User struct {
121
+ ByName * NamedUserOpt `json:"byName,omitempty"`
122
+ ByID uint32 `json:"byId,omitempty"`
83
123
}
124
+ }
84
125
126
+ func (m * UserOpt ) MarshalJSON () ([]byte , error ) {
127
+ var v jsonUserOpt
128
+ switch userOpt := m .User .(type ) {
129
+ case * UserOpt_ByName :
130
+ v .User .ByName = userOpt .ByName
131
+ case * UserOpt_ByID :
132
+ v .User .ByID = userOpt .ByID
133
+ }
134
+ return json .Marshal (v )
135
+ }
136
+
137
+ func (m * UserOpt ) UnmarshalJSON (data []byte ) error {
138
+ var v jsonUserOpt
85
139
if err := json .Unmarshal (data , & v ); err != nil {
86
140
return err
87
141
}
88
142
89
143
switch {
90
- case v .User .UserOpt_ByName != nil :
91
- m .User = v .User .UserOpt_ByName
92
- case v . User . UserOpt_ByID != nil :
93
- m .User = v .User .UserOpt_ByID
144
+ case v .User .ByName != nil :
145
+ m .User = & UserOpt_ByName { v .User .ByName }
146
+ default :
147
+ m .User = & UserOpt_ByID { v .User .ByID }
94
148
}
95
149
return nil
96
150
}
0 commit comments