summaryrefslogtreecommitdiff
path: root/ddl/out/java/TestData/JSON.java
blob: 098105dceafbdde7fdfd89ea6699b8b0295a87c4 (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
// generated file, do not modify!
// 2016-03-21T15:32:18.087397000000Z

package TestData;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.*;
import RT.*;

import LambdaCube.IR.*;
import LambdaCube.Mesh.*;
import LambdaCube.PipelineSchema.*;

public class JSON {
  // JSON deserializer
  public enum Type { 
    Int,
    Float,
    String,
    Array_Int,
    Array_Float,
    Array_String,
    Array_Frame,
    Array_Mesh,
    Array_PipelineInfo,
    Array_Scene,
    Map_String_Int,
    Map_String_Array_Int,
    Map_String_Value,
    Backend,
    ClientInfo,
    Frame,
    FrameResult,
    Mesh,
    Pipeline,
    PipelineInfo,
    PipelineSchema,
    RenderJob,
    RenderJobResult,
    Scene,
    Value
  }

  public static Object fromJSON(Type type, Object rawObj) throws JSONException, Exception {
    switch (type) {
      case Int: return (Integer)rawObj;
      case Float: return (Float)rawObj;
      case String: return (String)rawObj;
      case Array_Int: {
        JSONArray obj = (JSONArray)rawObj;
        ArrayList<Integer> v = new ArrayList<Integer> ();
        for (int i = 0; i < obj.length(); i++) {
          v.add((Integer)fromJSON (Type.Int, obj.get(i)));
        }
        return v;
      }
      case Array_Float: {
        JSONArray obj = (JSONArray)rawObj;
        ArrayList<Float> v = new ArrayList<Float> ();
        for (int i = 0; i < obj.length(); i++) {
          v.add((Float)fromJSON (Type.Float, obj.get(i)));
        }
        return v;
      }
      case Array_String: {
        JSONArray obj = (JSONArray)rawObj;
        ArrayList<String> v = new ArrayList<String> ();
        for (int i = 0; i < obj.length(); i++) {
          v.add((String)fromJSON (Type.String, obj.get(i)));
        }
        return v;
      }
      case Array_Frame: {
        JSONArray obj = (JSONArray)rawObj;
        ArrayList<Frame> v = new ArrayList<Frame> ();
        for (int i = 0; i < obj.length(); i++) {
          v.add((Frame)fromJSON (Type.Frame, obj.get(i)));
        }
        return v;
      }
      case Array_Mesh: {
        JSONArray obj = (JSONArray)rawObj;
        ArrayList<Mesh> v = new ArrayList<Mesh> ();
        for (int i = 0; i < obj.length(); i++) {
          v.add((Mesh)fromJSON (Type.Mesh, obj.get(i)));
        }
        return v;
      }
      case Array_PipelineInfo: {
        JSONArray obj = (JSONArray)rawObj;
        ArrayList<PipelineInfo> v = new ArrayList<PipelineInfo> ();
        for (int i = 0; i < obj.length(); i++) {
          v.add((PipelineInfo)fromJSON (Type.PipelineInfo, obj.get(i)));
        }
        return v;
      }
      case Array_Scene: {
        JSONArray obj = (JSONArray)rawObj;
        ArrayList<Scene> v = new ArrayList<Scene> ();
        for (int i = 0; i < obj.length(); i++) {
          v.add((Scene)fromJSON (Type.Scene, obj.get(i)));
        }
        return v;
      }
      case Map_String_Int: {
        JSONObject obj = (JSONObject)rawObj;
        HashMap<String, Integer> map = new HashMap<String, Integer> ();
        Iterator<String> keyIt = obj.keys();
        while(keyIt.hasNext()) {
          String key = keyIt.next();
          map.put(key, (Integer)fromJSON(Type.Int,obj.get(key)));
        }
        return map;
      }
      case Map_String_Array_Int: {
        JSONObject obj = (JSONObject)rawObj;
        HashMap<String, ArrayList<Integer>> map = new HashMap<String, ArrayList<Integer>> ();
        Iterator<String> keyIt = obj.keys();
        while(keyIt.hasNext()) {
          String key = keyIt.next();
          map.put(key, (ArrayList<Integer>)fromJSON(Type.Array_Int,obj.get(key)));
        }
        return map;
      }
      case Map_String_Value: {
        JSONObject obj = (JSONObject)rawObj;
        HashMap<String, Value> map = new HashMap<String, Value> ();
        Iterator<String> keyIt = obj.keys();
        while(keyIt.hasNext()) {
          String key = keyIt.next();
          map.put(key, (Value)fromJSON(Type.Value,obj.get(key)));
        }
        return map;
      }

      case ClientInfo: {
        JSONObject obj = (JSONObject)rawObj;
        String tag = obj.getString("tag");
        switch (tag) {
          case "ClientInfo": {
            ClientInfo.ClientInfo_ tv = new ClientInfo().new ClientInfo_();
            tv.clientName = (String)fromJSON(Type.String,obj.get("clientName"));
            tv.clientBackend = (Backend)fromJSON(Type.Backend,obj.get("clientBackend"));
            return tv;
          }
          default: throw new Exception("unknown constructor: " + tag);
        }
      }
      case Frame: {
        JSONObject obj = (JSONObject)rawObj;
        String tag = obj.getString("tag");
        switch (tag) {
          case "Frame": {
            Frame.Frame_ tv = new Frame().new Frame_();
            tv.renderCount = (Integer)fromJSON(Type.Int,obj.get("renderCount"));
            tv.frameUniforms = (HashMap<String, Value>)fromJSON(Type.Map_String_Value,obj.get("frameUniforms"));
            tv.frameTextures = (HashMap<String, Integer>)fromJSON(Type.Map_String_Int,obj.get("frameTextures"));
            return tv;
          }
          default: throw new Exception("unknown constructor: " + tag);
        }
      }
      case Scene: {
        JSONObject obj = (JSONObject)rawObj;
        String tag = obj.getString("tag");
        switch (tag) {
          case "Scene": {
            Scene.Scene_ tv = new Scene().new Scene_();
            tv.objectArrays = (HashMap<String, ArrayList<Integer>>)fromJSON(Type.Map_String_Array_Int,obj.get("objectArrays"));
            tv.renderTargetWidth = (Integer)fromJSON(Type.Int,obj.get("renderTargetWidth"));
            tv.renderTargetHeight = (Integer)fromJSON(Type.Int,obj.get("renderTargetHeight"));
            tv.frames = (ArrayList<Frame>)fromJSON(Type.Array_Frame,obj.get("frames"));
            return tv;
          }
          default: throw new Exception("unknown constructor: " + tag);
        }
      }
      case PipelineInfo: {
        JSONObject obj = (JSONObject)rawObj;
        String tag = obj.getString("tag");
        switch (tag) {
          case "PipelineInfo": {
            PipelineInfo.PipelineInfo_ tv = new PipelineInfo().new PipelineInfo_();
            tv.pipelineName = (String)fromJSON(Type.String,obj.get("pipelineName"));
            tv.pipeline = (Pipeline)fromJSON(Type.Pipeline,obj.get("pipeline"));
            return tv;
          }
          default: throw new Exception("unknown constructor: " + tag);
        }
      }
      case RenderJob: {
        JSONObject obj = (JSONObject)rawObj;
        String tag = obj.getString("tag");
        switch (tag) {
          case "RenderJob": {
            RenderJob.RenderJob_ tv = new RenderJob().new RenderJob_();
            tv.meshes = (ArrayList<Mesh>)fromJSON(Type.Array_Mesh,obj.get("meshes"));
            tv.textures = (ArrayList<String>)fromJSON(Type.Array_String,obj.get("textures"));
            tv.schema = (PipelineSchema)fromJSON(Type.PipelineSchema,obj.get("schema"));
            tv.scenes = (ArrayList<Scene>)fromJSON(Type.Array_Scene,obj.get("scenes"));
            tv.pipelines = (ArrayList<PipelineInfo>)fromJSON(Type.Array_PipelineInfo,obj.get("pipelines"));
            return tv;
          }
          default: throw new Exception("unknown constructor: " + tag);
        }
      }
      case FrameResult: {
        JSONObject obj = (JSONObject)rawObj;
        String tag = obj.getString("tag");
        switch (tag) {
          case "FrameResult": {
            FrameResult.FrameResult_ tv = new FrameResult().new FrameResult_();
            tv.frRenderTimes = (ArrayList<Float>)fromJSON(Type.Array_Float,obj.get("frRenderTimes"));
            tv.frImageWidth = (Integer)fromJSON(Type.Int,obj.get("frImageWidth"));
            tv.frImageHeight = (Integer)fromJSON(Type.Int,obj.get("frImageHeight"));
            return tv;
          }
          default: throw new Exception("unknown constructor: " + tag);
        }
      }
      case RenderJobResult: {
        JSONObject obj = (JSONObject)rawObj;
        String tag = obj.getString("tag");
        switch (tag) {
          case "RenderJobResult": {
            RenderJobResult.RenderJobResult_ tv = new RenderJobResult().new RenderJobResult_();
            tv._0 = (FrameResult)fromJSON(Type.FrameResult,obj.get("arg0"));
            return tv;
          }
          case "RenderJobError": {
            RenderJobResult.RenderJobError_ tv = new RenderJobResult().new RenderJobError_();
            tv._0 = (String)fromJSON(Type.String,obj.get("arg0"));
            return tv;
          }
          default: throw new Exception("unknown constructor: " + tag);
        }
      }
    }
    throw new Exception("unknown type");
  }

  public static Object toJSON(Type type, Object rawObj) throws JSONException, Exception {
    switch (type) {
      case ClientInfo: {
        ClientInfo v = (ClientInfo)rawObj;
        JSONObject obj = new JSONObject();
        switch (v.tag) { 
          case ClientInfo:
            obj.put("tag", "ClientInfo");
            {
              ClientInfo.ClientInfo_ tv = (ClientInfo.ClientInfo_)v;
              obj.put("clientName", toJSON(Type.String,tv.clientName));
              obj.put("clientBackend", toJSON(Type.Backend,tv.clientBackend));
            }
            break;
        }
        return obj;
      }
      case Frame: {
        Frame v = (Frame)rawObj;
        JSONObject obj = new JSONObject();
        switch (v.tag) { 
          case Frame:
            obj.put("tag", "Frame");
            {
              Frame.Frame_ tv = (Frame.Frame_)v;
              obj.put("renderCount", toJSON(Type.Int,tv.renderCount));
              obj.put("frameUniforms", toJSON(Type.Map_String_Value,tv.frameUniforms));
              obj.put("frameTextures", toJSON(Type.Map_String_Int,tv.frameTextures));
            }
            break;
        }
        return obj;
      }
      case Scene: {
        Scene v = (Scene)rawObj;
        JSONObject obj = new JSONObject();
        switch (v.tag) { 
          case Scene:
            obj.put("tag", "Scene");
            {
              Scene.Scene_ tv = (Scene.Scene_)v;
              obj.put("objectArrays", toJSON(Type.Map_String_Array_Int,tv.objectArrays));
              obj.put("renderTargetWidth", toJSON(Type.Int,tv.renderTargetWidth));
              obj.put("renderTargetHeight", toJSON(Type.Int,tv.renderTargetHeight));
              obj.put("frames", toJSON(Type.Array_Frame,tv.frames));
            }
            break;
        }
        return obj;
      }
      case PipelineInfo: {
        PipelineInfo v = (PipelineInfo)rawObj;
        JSONObject obj = new JSONObject();
        switch (v.tag) { 
          case PipelineInfo:
            obj.put("tag", "PipelineInfo");
            {
              PipelineInfo.PipelineInfo_ tv = (PipelineInfo.PipelineInfo_)v;
              obj.put("pipelineName", toJSON(Type.String,tv.pipelineName));
              obj.put("pipeline", toJSON(Type.Pipeline,tv.pipeline));
            }
            break;
        }
        return obj;
      }
      case RenderJob: {
        RenderJob v = (RenderJob)rawObj;
        JSONObject obj = new JSONObject();
        switch (v.tag) { 
          case RenderJob:
            obj.put("tag", "RenderJob");
            {
              RenderJob.RenderJob_ tv = (RenderJob.RenderJob_)v;
              obj.put("meshes", toJSON(Type.Array_Mesh,tv.meshes));
              obj.put("textures", toJSON(Type.Array_String,tv.textures));
              obj.put("schema", toJSON(Type.PipelineSchema,tv.schema));
              obj.put("scenes", toJSON(Type.Array_Scene,tv.scenes));
              obj.put("pipelines", toJSON(Type.Array_PipelineInfo,tv.pipelines));
            }
            break;
        }
        return obj;
      }
      case FrameResult: {
        FrameResult v = (FrameResult)rawObj;
        JSONObject obj = new JSONObject();
        switch (v.tag) { 
          case FrameResult:
            obj.put("tag", "FrameResult");
            {
              FrameResult.FrameResult_ tv = (FrameResult.FrameResult_)v;
              obj.put("frRenderTimes", toJSON(Type.Array_Float,tv.frRenderTimes));
              obj.put("frImageWidth", toJSON(Type.Int,tv.frImageWidth));
              obj.put("frImageHeight", toJSON(Type.Int,tv.frImageHeight));
            }
            break;
        }
        return obj;
      }
      case RenderJobResult: {
        RenderJobResult v = (RenderJobResult)rawObj;
        JSONObject obj = new JSONObject();
        switch (v.tag) { 
          case RenderJobResult:
            obj.put("tag", "RenderJobResult");
            {
              RenderJobResult.RenderJobResult_ tv = (RenderJobResult.RenderJobResult_)v;
              obj.put("arg0", toJSON(Type.FrameResult,tv._0));
            }
            break;
          case RenderJobError:
            obj.put("tag", "RenderJobError");
            {
              RenderJobResult.RenderJobError_ tv = (RenderJobResult.RenderJobError_)v;
              obj.put("arg0", toJSON(Type.String,tv._0));
            }
            break;
        }
        return obj;
      }

      case Int: { return rawObj; }
      case Float: { return rawObj; }
      case String: { return rawObj; }
      case Array_Int: {
        ArrayList<Integer> v = (ArrayList<Integer>)rawObj;
        JSONArray obj = new JSONArray();
        for(Integer i : v) {
          obj.put(toJSON(Type.Int,i));
        }
        return obj;
      }
      case Array_Float: {
        ArrayList<Float> v = (ArrayList<Float>)rawObj;
        JSONArray obj = new JSONArray();
        for(Float i : v) {
          obj.put(toJSON(Type.Float,i));
        }
        return obj;
      }
      case Array_String: {
        ArrayList<String> v = (ArrayList<String>)rawObj;
        JSONArray obj = new JSONArray();
        for(String i : v) {
          obj.put(toJSON(Type.String,i));
        }
        return obj;
      }
      case Array_Frame: {
        ArrayList<Frame> v = (ArrayList<Frame>)rawObj;
        JSONArray obj = new JSONArray();
        for(Frame i : v) {
          obj.put(toJSON(Type.Frame,i));
        }
        return obj;
      }
      case Array_Mesh: {
        ArrayList<Mesh> v = (ArrayList<Mesh>)rawObj;
        JSONArray obj = new JSONArray();
        for(Mesh i : v) {
          obj.put(toJSON(Type.Mesh,i));
        }
        return obj;
      }
      case Array_PipelineInfo: {
        ArrayList<PipelineInfo> v = (ArrayList<PipelineInfo>)rawObj;
        JSONArray obj = new JSONArray();
        for(PipelineInfo i : v) {
          obj.put(toJSON(Type.PipelineInfo,i));
        }
        return obj;
      }
      case Array_Scene: {
        ArrayList<Scene> v = (ArrayList<Scene>)rawObj;
        JSONArray obj = new JSONArray();
        for(Scene i : v) {
          obj.put(toJSON(Type.Scene,i));
        }
        return obj;
      }
      case Map_String_Int: {
        HashMap<String, Integer> v = (HashMap<String, Integer>)rawObj;
        JSONObject obj = new JSONObject();
        for (Map.Entry<String,Integer> i : v.entrySet()) {
          obj.put(i.getKey(), toJSON(Type.Int,i.getValue()));
        }
        return obj;
      }
      case Map_String_Array_Int: {
        HashMap<String, ArrayList<Integer>> v = (HashMap<String, ArrayList<Integer>>)rawObj;
        JSONObject obj = new JSONObject();
        for (Map.Entry<String,ArrayList<Integer>> i : v.entrySet()) {
          obj.put(i.getKey(), toJSON(Type.Array_Int,i.getValue()));
        }
        return obj;
      }
      case Map_String_Value: {
        HashMap<String, Value> v = (HashMap<String, Value>)rawObj;
        JSONObject obj = new JSONObject();
        for (Map.Entry<String,Value> i : v.entrySet()) {
          obj.put(i.getKey(), toJSON(Type.Value,i.getValue()));
        }
        return obj;
      }
    }
    return null;
  }
}