1 package qapi
2
3 import (
4 "encoding/json"
5 "errors"
6 "fmt"
7 "strings"
8 )
9
10
11
12
13
14
15 type StrOrNull struct {
16
17
18
19 Value Any
20 }
21
22 func (s StrOrNull) MarshalJSON() ([]byte, error) {
23 typestr := fmt.Sprintf("%T", s.Value)
24 typestr = typestr[strings.LastIndex(typestr, ".")+1:]
25
26
27 if typestr != "<nil>" &&
28 typestr != "string" &&
29 typestr != "*string" {
30 return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
31 }
32
33 b, err := json.Marshal(s.Value)
34 if err != nil {
35 return nil, err
36 }
37
38 return b, nil
39 }
40
41 func (s *StrOrNull) UnmarshalJSON(data []byte) error {
42
43 {
44 var value *string
45 if err := StrictDecode(&value, data); err == nil && value == nil {
46 s.Value = nil
47 return nil
48 }
49 }
50
51 {
52 var value string
53 if err := StrictDecode(&value, data); err == nil {
54 s.Value = value
55 return nil
56 }
57 }
58
59 {
60 var value Any
61 if err := json.Unmarshal(data, &value); err != nil {
62 return err
63 }
64 return errors.New(fmt.Sprintf("Unsupported type %T (value: %v)", value, value))
65 }
66 }
67
68
69 type BlockDirtyBitmapMergeSource struct {
70
71
72
73 Value Any
74 }
75
76 func (s BlockDirtyBitmapMergeSource) MarshalJSON() ([]byte, error) {
77 typestr := fmt.Sprintf("%T", s.Value)
78 typestr = typestr[strings.LastIndex(typestr, ".")+1:]
79
80
81 if typestr != "<nil>" &&
82 typestr != "string" &&
83 typestr != "BlockDirtyBitmap" {
84 return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
85 }
86
87 b, err := json.Marshal(s.Value)
88 if err != nil {
89 return nil, err
90 }
91
92 return b, nil
93 }
94
95 func (s *BlockDirtyBitmapMergeSource) UnmarshalJSON(data []byte) error {
96
97 {
98 var value string
99 if err := StrictDecode(&value, data); err == nil {
100 s.Value = value
101 return nil
102 }
103 }
104
105 {
106 var value BlockDirtyBitmap
107 if err := StrictDecode(&value, data); err == nil {
108 s.Value = value
109 return nil
110 }
111 }
112
113 {
114 var value Any
115 if err := json.Unmarshal(data, &value); err != nil {
116 return err
117 }
118 return errors.New(fmt.Sprintf("Unsupported type %T (value: %v)", value, value))
119 }
120 }
121
122
123
124
125
126 type Qcow2OverlapChecks struct {
127
128
129
130 Value Any
131 }
132
133 func (s Qcow2OverlapChecks) MarshalJSON() ([]byte, error) {
134 typestr := fmt.Sprintf("%T", s.Value)
135 typestr = typestr[strings.LastIndex(typestr, ".")+1:]
136
137
138 if typestr != "<nil>" &&
139 typestr != "Qcow2OverlapCheckFlags" &&
140 typestr != "Qcow2OverlapCheckMode" {
141 return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
142 }
143
144 b, err := json.Marshal(s.Value)
145 if err != nil {
146 return nil, err
147 }
148
149 return b, nil
150 }
151
152 func (s *Qcow2OverlapChecks) UnmarshalJSON(data []byte) error {
153
154 {
155 var value Qcow2OverlapCheckFlags
156 if err := StrictDecode(&value, data); err == nil {
157 s.Value = value
158 return nil
159 }
160 }
161
162 {
163 var value Qcow2OverlapCheckMode
164 if err := StrictDecode(&value, data); err == nil {
165 s.Value = value
166 return nil
167 }
168 }
169
170 {
171 var value Any
172 if err := json.Unmarshal(data, &value); err != nil {
173 return err
174 }
175 return errors.New(fmt.Sprintf("Unsupported type %T (value: %v)", value, value))
176 }
177 }
178
179
180
181
182 type BlockdevRef struct {
183
184
185
186 Value Any
187 }
188
189 func (s BlockdevRef) MarshalJSON() ([]byte, error) {
190 typestr := fmt.Sprintf("%T", s.Value)
191 typestr = typestr[strings.LastIndex(typestr, ".")+1:]
192
193
194 if typestr != "<nil>" &&
195 typestr != "BlockdevOptions" &&
196 typestr != "string" {
197 return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
198 }
199
200 b, err := json.Marshal(s.Value)
201 if err != nil {
202 return nil, err
203 }
204
205 return b, nil
206 }
207
208 func (s *BlockdevRef) UnmarshalJSON(data []byte) error {
209
210 {
211 var value BlockdevOptions
212 if err := StrictDecode(&value, data); err == nil {
213 s.Value = value
214 return nil
215 }
216 }
217
218 {
219 var value string
220 if err := StrictDecode(&value, data); err == nil {
221 s.Value = value
222 return nil
223 }
224 }
225
226 {
227 var value Any
228 if err := json.Unmarshal(data, &value); err != nil {
229 return err
230 }
231 return errors.New(fmt.Sprintf("Unsupported type %T (value: %v)", value, value))
232 }
233 }
234
235
236
237
238 type BlockdevRefOrNull struct {
239
240
241
242
243 Value Any
244 }
245
246 func (s BlockdevRefOrNull) MarshalJSON() ([]byte, error) {
247 typestr := fmt.Sprintf("%T", s.Value)
248 typestr = typestr[strings.LastIndex(typestr, ".")+1:]
249
250
251 if typestr != "<nil>" &&
252 typestr != "BlockdevOptions" &&
253 typestr != "string" &&
254 typestr != "*string" {
255 return nil, errors.New(fmt.Sprintf("Type is not supported: %s", typestr))
256 }
257
258 b, err := json.Marshal(s.Value)
259 if err != nil {
260 return nil, err
261 }
262
263 return b, nil
264 }
265
266 func (s *BlockdevRefOrNull) UnmarshalJSON(data []byte) error {
267
268 {
269 var value *string
270 if err := StrictDecode(&value, data); err == nil && value == nil {
271 s.Value = nil
272 return nil
273 }
274 }
275
276 {
277 var value BlockdevOptions
278 if err := StrictDecode(&value, data); err == nil {
279 s.Value = value
280 return nil
281 }
282 }
283
284 {
285 var value string
286 if err := StrictDecode(&value, data); err == nil {
287 s.Value = value
288 return nil
289 }
290 }
291
292 {
293 var value Any
294 if err := json.Unmarshal(data, &value); err != nil {
295 return err
296 }
297 return errors.New(fmt.Sprintf("Unsupported type %T (value: %v)", value, value))
298 }
299 }
300
View as plain text