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
|
// generated file, do not modify!
// 2016-03-21T14:06:55.360355000000Z
package LambdaCube.PipelineSchema;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.json.*;
import RT.*;
import LambdaCube.IR.*;
public class JSON {
// JSON deserializer
public enum Type {
String,
Map_String_InputType,
Map_String_ObjectArraySchema,
Map_String_StreamType,
FetchPrimitive,
InputType,
ObjectArraySchema,
PipelineSchema,
StreamType
}
public static Object fromJSON(Type type, Object rawObj) throws JSONException, Exception {
switch (type) {
case String: return (String)rawObj;
case Map_String_InputType: {
JSONObject obj = (JSONObject)rawObj;
HashMap<String, InputType> map = new HashMap<String, InputType> ();
Iterator<String> keyIt = obj.keys();
while(keyIt.hasNext()) {
String key = keyIt.next();
map.put(key, (InputType)fromJSON(Type.InputType,obj.get(key)));
}
return map;
}
case Map_String_ObjectArraySchema: {
JSONObject obj = (JSONObject)rawObj;
HashMap<String, ObjectArraySchema> map = new HashMap<String, ObjectArraySchema> ();
Iterator<String> keyIt = obj.keys();
while(keyIt.hasNext()) {
String key = keyIt.next();
map.put(key, (ObjectArraySchema)fromJSON(Type.ObjectArraySchema,obj.get(key)));
}
return map;
}
case Map_String_StreamType: {
JSONObject obj = (JSONObject)rawObj;
HashMap<String, StreamType> map = new HashMap<String, StreamType> ();
Iterator<String> keyIt = obj.keys();
while(keyIt.hasNext()) {
String key = keyIt.next();
map.put(key, (StreamType)fromJSON(Type.StreamType,obj.get(key)));
}
return map;
}
case StreamType: {
JSONObject obj = (JSONObject)rawObj;
String tag = obj.getString("tag");
StreamType.Tag tagType;
switch (tag) {
case "Attribute_Word": tagType = StreamType.Tag.Attribute_Word; break;
case "Attribute_V2U": tagType = StreamType.Tag.Attribute_V2U; break;
case "Attribute_V3U": tagType = StreamType.Tag.Attribute_V3U; break;
case "Attribute_V4U": tagType = StreamType.Tag.Attribute_V4U; break;
case "Attribute_Int": tagType = StreamType.Tag.Attribute_Int; break;
case "Attribute_V2I": tagType = StreamType.Tag.Attribute_V2I; break;
case "Attribute_V3I": tagType = StreamType.Tag.Attribute_V3I; break;
case "Attribute_V4I": tagType = StreamType.Tag.Attribute_V4I; break;
case "Attribute_Float": tagType = StreamType.Tag.Attribute_Float; break;
case "Attribute_V2F": tagType = StreamType.Tag.Attribute_V2F; break;
case "Attribute_V3F": tagType = StreamType.Tag.Attribute_V3F; break;
case "Attribute_V4F": tagType = StreamType.Tag.Attribute_V4F; break;
case "Attribute_M22F": tagType = StreamType.Tag.Attribute_M22F; break;
case "Attribute_M23F": tagType = StreamType.Tag.Attribute_M23F; break;
case "Attribute_M24F": tagType = StreamType.Tag.Attribute_M24F; break;
case "Attribute_M32F": tagType = StreamType.Tag.Attribute_M32F; break;
case "Attribute_M33F": tagType = StreamType.Tag.Attribute_M33F; break;
case "Attribute_M34F": tagType = StreamType.Tag.Attribute_M34F; break;
case "Attribute_M42F": tagType = StreamType.Tag.Attribute_M42F; break;
case "Attribute_M43F": tagType = StreamType.Tag.Attribute_M43F; break;
case "Attribute_M44F": tagType = StreamType.Tag.Attribute_M44F; break;
default: throw new Exception("unknown constructor: " + tag);
}
StreamType o = new StreamType();
o.tag = tagType;
return o;
}
case ObjectArraySchema: {
JSONObject obj = (JSONObject)rawObj;
String tag = obj.getString("tag");
switch (tag) {
case "ObjectArraySchema": {
ObjectArraySchema.ObjectArraySchema_ tv = new ObjectArraySchema().new ObjectArraySchema_();
tv.primitive = (FetchPrimitive)fromJSON(Type.FetchPrimitive,obj.get("primitive"));
tv.attributes = (HashMap<String, StreamType>)fromJSON(Type.Map_String_StreamType,obj.get("attributes"));
return tv;
}
default: throw new Exception("unknown constructor: " + tag);
}
}
case PipelineSchema: {
JSONObject obj = (JSONObject)rawObj;
String tag = obj.getString("tag");
switch (tag) {
case "PipelineSchema": {
PipelineSchema.PipelineSchema_ tv = new PipelineSchema().new PipelineSchema_();
tv.objectArrays = (HashMap<String, ObjectArraySchema>)fromJSON(Type.Map_String_ObjectArraySchema,obj.get("objectArrays"));
tv.uniforms = (HashMap<String, InputType>)fromJSON(Type.Map_String_InputType,obj.get("uniforms"));
return tv;
}
default: throw new Exception("unknown constructor: " + tag);
}
}
}
throw new Exception("unknown type");
}
}
|