490
|
1 /*
|
|
2 1 2 3 4 5 6 7
|
|
3 12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
4 */
|
|
5
|
491
|
6 namespace VsolStuff222 {
|
490
|
7 export enum EnumMonth0 {
|
|
8 January,
|
|
9 February,
|
|
10 March
|
|
11 };
|
|
12
|
|
13 export class Message1 {
|
|
14 a: number;
|
|
15 b: string;
|
|
16 c: EnumMonth0;
|
|
17 d: boolean;
|
|
18 public StoneSerialize(): string {
|
|
19 let container: object = {};
|
491
|
20 container['type'] = 'VsolStuff.Message1';
|
490
|
21 container['value'] = this;
|
|
22 return JSON.stringify(container);
|
|
23 }
|
|
24 };
|
|
25
|
|
26 export class Message2 {
|
|
27 toto: string;
|
|
28 tata: Message1[];
|
|
29 tutu: string[];
|
|
30 titi: Map<string, string>;
|
|
31 lulu: Map<string, Message1>;
|
|
32
|
|
33 public StoneSerialize(): string {
|
|
34 let container: object = {};
|
491
|
35 container['type'] = 'VsolStuff.Message2';
|
490
|
36 container['value'] = this;
|
|
37 return JSON.stringify(container);
|
|
38 }
|
|
39 };
|
|
40 }
|
|
41
|
|
42 function printf(value: any): void {
|
|
43 console.log(value)
|
|
44 }
|
|
45
|
|
46 function main(): number {
|
|
47
|
|
48 let msg1_0 = new VsolStuff.Message1();
|
|
49 msg1_0.a = 42;
|
|
50 msg1_0.b = "Benjamin";
|
|
51 msg1_0.c = VsolStuff.EnumMonth0.January;
|
|
52 msg1_0.d = true;
|
|
53
|
|
54 let msg1_1 = new VsolStuff.Message1();
|
|
55 msg1_1.a = 43;
|
|
56 msg1_1.b = "Sandrine";
|
|
57 msg1_1.c = VsolStuff.EnumMonth0.March;
|
|
58 msg1_0.d = false;
|
|
59
|
|
60 // std::string toto;
|
|
61 // std::vector<Message1> tata;
|
|
62 // std::vector<std::string> tutu;
|
|
63 // std::map<int32_t, std::string> titi;
|
|
64 // std::map<int32_t, Message1> lulu;
|
|
65
|
|
66 let msg2_0 = new VsolStuff.Message2();
|
|
67 msg2_0.toto = "Prout zizi";
|
|
68 msg2_0.tata = new Array<VsolStuff.Message1>();
|
|
69 msg2_0.tata.push(msg1_0);
|
|
70 msg2_0.tata.push(msg1_1);
|
|
71 msg2_0.tutu.push("Mercadet");
|
491
|
72 msg2_0.tutu.push("Poisson");ing
|
490
|
73 msg2_0.titi["44"] = "key 44";
|
|
74 msg2_0.titi["45"] = "key 45";
|
|
75 msg2_0.lulu["54"] = msg1_1;
|
|
76 msg2_0.lulu["55"] = msg1_0;
|
|
77 let result:string = VsolStuff.StoneSerialize(msg2_0);
|
|
78 return 0;
|
|
79 }
|
|
80
|
|
81 main()
|
|
82
|
|
83 // string StoneSerialize_number(int32_t value)
|
|
84 // {
|
|
85
|
|
86 // Json::Value result(value);
|
|
87 // return result;
|
|
88 // }
|
|
89
|
|
90 // Json::Value StoneSerialize(double value)
|
|
91 // {
|
|
92 // Json::Value result(value);
|
|
93 // return result;
|
|
94 // }
|
|
95
|
|
96 // Json::Value StoneSerialize(bool value)
|
|
97 // {
|
|
98 // Json::Value result(value);
|
|
99 // return result;
|
|
100 // }
|
|
101
|
|
102 // Json::Value StoneSerialize(const std::string& value)
|
|
103 // {
|
|
104 // // the following is better than
|
|
105 // Json::Value result(value.data(),value.data()+value.size());
|
|
106 // return result;
|
|
107 // }
|
|
108
|
|
109 // template<typename T>
|
|
110 // Json::Value StoneSerialize(const std::map<std::string,T>& value)
|
|
111 // {
|
|
112 // Json::Value result(Json::objectValue);
|
|
113
|
|
114 // for (std::map<std::string, T>::const_iterator it = value.cbegin();
|
|
115 // it != value.cend(); ++it)
|
|
116 // {
|
|
117 // // it->first it->second
|
|
118 // result[it->first] = StoneSerialize(it->second);
|
|
119 // }
|
|
120 // return result;
|
|
121 // }
|
|
122
|
|
123 // template<typename T>
|
|
124 // Json::Value StoneSerialize(const std::vector<T>& value)
|
|
125 // {
|
|
126 // Json::Value result(Json::arrayValue);
|
|
127 // for (size_t i = 0; i < value.size(); ++i)
|
|
128 // {
|
|
129 // result.append(StoneSerialize(value[i]));
|
|
130 // }
|
|
131 // return result;
|
|
132 // }
|
|
133
|
|
134 // enum EnumMonth0
|
|
135 // {
|
|
136 // January,
|
|
137 // February,
|
|
138 // March
|
|
139 // };
|
|
140
|
|
141 // std::string ToString(EnumMonth0 value)
|
|
142 // {
|
|
143 // switch(value)
|
|
144 // {
|
|
145 // case January:
|
|
146 // return "January";
|
|
147 // case February:
|
|
148 // return "February";
|
|
149 // case March:
|
|
150 // return "March";
|
|
151 // default:
|
|
152 // {
|
|
153 // std::stringstream ss;
|
|
154 // ss << "Unrecognized EnumMonth0 value (" << static_cast<int64_t>(value) << ")";
|
|
155 // throw std::runtime_error(ss.str());
|
|
156 // }
|
|
157 // }
|
|
158 // }
|
|
159
|
|
160 // void FromString(EnumMonth0& value, std::string strValue)
|
|
161 // {
|
|
162 // if (strValue == "January" || strValue == "EnumMonth0_January")
|
|
163 // {
|
|
164 // return January;
|
|
165 // }
|
|
166 // else if (strValue == "February" || strValue == "EnumMonth0_February")
|
|
167 // {
|
|
168 // return February;
|
|
169 // }
|
|
170 // #error Not implemented yet
|
|
171 // }
|
|
172
|
|
173 // Json::Value StoneSerialize(const EnumMonth0& value)
|
|
174 // {
|
|
175 // return StoneSerialize(ToString(value));
|
|
176 // }
|
|
177 // struct Message1
|
|
178 // {
|
|
179 // int32_t a;
|
|
180 // std::string b;
|
|
181 // EnumMonth0 c;
|
|
182 // bool d;
|
|
183 // };
|
|
184
|
|
185 // struct Message2
|
|
186 // {
|
|
187 // std::string toto;
|
|
188 // std::vector<Message1> tata;
|
|
189 // std::vector<std::string> tutu;
|
|
190 // std::map<std::string, std::string> titi;
|
|
191 // std::map<std::string, Message1> lulu;
|
|
192 // };
|
|
193
|
|
194 // Json::Value StoneSerialize(const Message1& value)
|
|
195 // {
|
|
196 // Json::Value result(Json::objectValue);
|
|
197 // result["a"] = StoneSerialize(value.a);
|
|
198 // result["b"] = StoneSerialize(value.b);
|
|
199 // result["c"] = StoneSerialize(value.c);
|
|
200 // result["d"] = StoneSerialize(value.d);
|
|
201 // return result;
|
|
202 // }
|
|
203
|
|
204 // Json::Value StoneSerialize(const Message2& value)
|
|
205 // {
|
|
206 // Json::Value result(Json::objectValue);
|
|
207 // result["toto"] = StoneSerialize(value.toto);
|
|
208 // result["tata"] = StoneSerialize(value.tata);
|
|
209 // result["tutu"] = StoneSerialize(value.tutu);
|
|
210 // result["titi"] = StoneSerialize(value.titi);
|
|
211 // result["lulu"] = StoneSerialize(value.lulu);
|
|
212 // return result;
|
|
213 // }
|
|
214 // }
|
|
215
|
|
216 // int main()
|
|
217 // {
|
|
218 // VsolStuff::Message1 msg1_0;
|
|
219 // msg1_0.a = 42;
|
|
220 // msg1_0.b = "Benjamin";
|
|
221 // msg1_0.c = VsolStuff::January;
|
|
222 // msg1_0.d = true;
|
|
223
|
|
224 // VsolStuff::Message1 msg1_1;
|
|
225 // msg1_1.a = 43;
|
|
226 // msg1_1.b = "Sandrine";
|
|
227 // msg1_1.c = VsolStuff::March;
|
|
228 // msg1_0.d = false;
|
|
229
|
|
230 // // std::string toto;
|
|
231 // // std::vector<Message1> tata;
|
|
232 // // std::vector<std::string> tutu;
|
|
233 // // std::map<int32_t, std::string> titi;
|
|
234 // // std::map<int32_t, Message1> lulu;
|
|
235
|
|
236 // VsolStuff::Message2 msg2_0;
|
|
237 // msg2_0.toto = "Prout zizi";
|
|
238 // msg2_0.tata.push_back(msg1_0);
|
|
239 // msg2_0.tata.push_back(msg1_1);
|
|
240 // msg2_0.tutu.push_back("Mercadet");
|
|
241 // msg2_0.tutu.push_back("Poisson");
|
|
242 // msg2_0.titi["44"] = "key 44";
|
|
243 // msg2_0.titi["45"] = "key 45";
|
|
244 // msg2_0.lulu["54"] = msg1_1;
|
|
245 // msg2_0.lulu["55"] = msg1_0;
|
|
246 // auto result = VsolStuff::StoneSerialize(msg2_0);
|
|
247 // auto resultStr = result.toStyledString();
|
|
248
|
|
249 // Json::Value readValue;
|
|
250
|
|
251 // Json::CharReaderBuilder builder;
|
|
252 // Json::CharReader* reader = builder.newCharReader();
|
|
253 // std::string errors;
|
|
254
|
|
255 // bool ok = reader->parse(
|
|
256 // resultStr.c_str(),
|
|
257 // resultStr.c_str() + resultStr.size(),
|
|
258 // &readValue,
|
|
259 // &errors
|
|
260 // );
|
|
261 // delete reader;
|
|
262
|
|
263 // if (!ok)
|
|
264 // {
|
|
265 // std::stringstream ss;
|
|
266 // ss << "Json parsing error: " << errors;
|
|
267 // throw std::runtime_error(ss.str());
|
|
268 // }
|
|
269 // std::cout << readValue.get("toto", "Default Value").asString() << std::endl;
|
|
270 // return 0;
|
|
271 // }
|
|
272
|
|
273
|
|
274 }
|
|
275
|