com.xmobitea.changx.gn-unity 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/Editor/GNServerSettingsEditor.cs +27 -23
  2. package/Runtime/Common/GNArray.cs +302 -302
  3. package/Runtime/Common/GNArray.cs.meta +11 -11
  4. package/Runtime/Common/GNData.cs +48 -48
  5. package/Runtime/Common/GNData.cs.meta +11 -11
  6. package/Runtime/Common/GNHashtable.cs +241 -241
  7. package/Runtime/Common/GNHashtable.cs.meta +11 -11
  8. package/Runtime/Common/IGNData.cs +11 -11
  9. package/Runtime/Common/IGNData.cs.meta +11 -11
  10. package/Runtime/Common.meta +8 -8
  11. package/Runtime/Config/GNServerSettings.cs.meta +11 -11
  12. package/Runtime/Config.meta +8 -8
  13. package/Runtime/Constant/Commands.cs.meta +11 -11
  14. package/Runtime/Constant/EnumType/FriendStatus.cs +12 -12
  15. package/Runtime/Constant/EnumType/FriendStatus.cs.meta +11 -11
  16. package/Runtime/Constant/EnumType/GoogleLoginType.cs.meta +11 -11
  17. package/Runtime/Constant/EnumType/GroupStatus.cs.meta +11 -11
  18. package/Runtime/Constant/EnumType/InvalidMemberType.cs +23 -23
  19. package/Runtime/Constant/EnumType/InvalidMemberType.cs.meta +11 -11
  20. package/Runtime/Constant/EnumType/ItemType.cs.meta +11 -11
  21. package/Runtime/Constant/EnumType/MatchmakingMemberStatus.cs.meta +11 -11
  22. package/Runtime/Constant/EnumType/MatchmakingTicketStatus.cs.meta +11 -11
  23. package/Runtime/Constant/EnumType/OwnerType.cs.meta +11 -11
  24. package/Runtime/Constant/EnumType/PermissionDataItem.cs +10 -10
  25. package/Runtime/Constant/EnumType/PermissionDataItem.cs.meta +11 -11
  26. package/Runtime/Constant/EnumType/RequestRole.cs +11 -11
  27. package/Runtime/Constant/EnumType/RequestRole.cs.meta +7 -7
  28. package/Runtime/Constant/EnumType/RequestType.cs +19 -19
  29. package/Runtime/Constant/EnumType/RequestType.cs.meta +11 -11
  30. package/Runtime/Constant/EnumType.meta +8 -8
  31. package/Runtime/Constant/ErrorCode/GNErrorCode.cs.meta +7 -7
  32. package/Runtime/Constant/ErrorCode.meta +8 -8
  33. package/Runtime/Constant/EventCode.cs +16 -16
  34. package/Runtime/Constant/EventCode.cs.meta +11 -11
  35. package/Runtime/Constant/OperationCode.cs.meta +11 -11
  36. package/Runtime/Constant/ParameterCode/GNParameterCode.cs.meta +11 -11
  37. package/Runtime/Constant/ParameterCode/ParameterCode.cs +12 -12
  38. package/Runtime/Constant/ParameterCode/ParameterCode.cs.meta +11 -11
  39. package/Runtime/Constant/ParameterCode.meta +8 -8
  40. package/Runtime/Constant/ReturnCode.cs +25 -25
  41. package/Runtime/Constant/ReturnCode.cs.meta +11 -11
  42. package/Runtime/Constant.meta +8 -8
  43. package/Runtime/Entity/DataMember.cs +124 -124
  44. package/Runtime/Entity/DataMember.cs.meta +11 -11
  45. package/Runtime/Entity/GNMetadata.cs +27 -27
  46. package/Runtime/Entity/GNMetadata.cs.meta +11 -11
  47. package/Runtime/Entity/InvalidMember.cs +33 -33
  48. package/Runtime/Entity/InvalidMember.cs.meta +11 -11
  49. package/Runtime/Entity/Models/AuthenticateModels.cs.meta +11 -11
  50. package/Runtime/Entity/Models/AuthenticateRequestModels.cs.meta +11 -11
  51. package/Runtime/Entity/Models/AuthenticateResponseModels.cs.meta +11 -11
  52. package/Runtime/Entity/Models/CharacterPlayerModels.cs.meta +11 -11
  53. package/Runtime/Entity/Models/CharacterPlayerRequestModels.cs.meta +11 -11
  54. package/Runtime/Entity/Models/CharacterPlayerResponseModels.cs.meta +11 -11
  55. package/Runtime/Entity/Models/ContentModels.cs.meta +11 -11
  56. package/Runtime/Entity/Models/ContentRequestModels.cs.meta +11 -11
  57. package/Runtime/Entity/Models/ContentResponseModels.cs.meta +11 -11
  58. package/Runtime/Entity/Models/DashboardModels.cs.meta +11 -11
  59. package/Runtime/Entity/Models/DashboardRequestModels.cs.meta +11 -11
  60. package/Runtime/Entity/Models/DashboardResponseModels.cs.meta +11 -11
  61. package/Runtime/Entity/Models/GamePlayerModels.cs.meta +11 -11
  62. package/Runtime/Entity/Models/GamePlayerRequestModels.cs.meta +11 -11
  63. package/Runtime/Entity/Models/GamePlayerResponseModels.cs.meta +11 -11
  64. package/Runtime/Entity/Models/GenericModels.cs.meta +11 -11
  65. package/Runtime/Entity/Models/GroupModels.cs.meta +11 -11
  66. package/Runtime/Entity/Models/GroupRequestModels.cs.meta +11 -11
  67. package/Runtime/Entity/Models/GroupResponseModels.cs.meta +11 -11
  68. package/Runtime/Entity/Models/InventoryModels.cs.meta +11 -11
  69. package/Runtime/Entity/Models/InventoryRequestModels.cs.meta +11 -11
  70. package/Runtime/Entity/Models/InventoryResponseModels.cs.meta +11 -11
  71. package/Runtime/Entity/Models/MasterPlayerModels.cs.meta +11 -11
  72. package/Runtime/Entity/Models/MasterPlayerRequestModels.cs.meta +11 -11
  73. package/Runtime/Entity/Models/MasterPlayerResponseModels.cs.meta +11 -11
  74. package/Runtime/Entity/Models/MultiplayerModels.cs.meta +11 -11
  75. package/Runtime/Entity/Models/MultiplayerRequestModels.cs.meta +11 -11
  76. package/Runtime/Entity/Models/MultiplayerResponseModels.cs +49 -49
  77. package/Runtime/Entity/Models/MultiplayerResponseModels.cs.meta +11 -11
  78. package/Runtime/Entity/Models/StoreInventoryModels.cs.meta +11 -11
  79. package/Runtime/Entity/Models/StoreInventoryRequestModels.cs.meta +11 -11
  80. package/Runtime/Entity/Models/StoreInventoryResponseModels.cs.meta +11 -11
  81. package/Runtime/Entity/Models.meta +8 -8
  82. package/Runtime/Entity/OperationEvent.cs +75 -75
  83. package/Runtime/Entity/OperationEvent.cs.meta +11 -11
  84. package/Runtime/Entity/OperationHelper.cs +35 -35
  85. package/Runtime/Entity/OperationHelper.cs.meta +11 -11
  86. package/Runtime/Entity/OperationRequest.cs +99 -99
  87. package/Runtime/Entity/OperationRequest.cs.meta +11 -11
  88. package/Runtime/Entity/OperationResponse.cs.meta +11 -11
  89. package/Runtime/Entity/Request/CustomOperationRequest.cs +61 -61
  90. package/Runtime/Entity/Request/CustomOperationRequest.cs.meta +11 -11
  91. package/Runtime/Entity/Request.meta +8 -8
  92. package/Runtime/Entity/Response/CustomOperationResponse.cs +63 -63
  93. package/Runtime/Entity/Response/CustomOperationResponse.cs.meta +11 -11
  94. package/Runtime/Entity/Response.meta +8 -8
  95. package/Runtime/Entity.meta +8 -8
  96. package/Runtime/GNNetwork.cs +182 -184
  97. package/Runtime/GNNetwork.cs.meta +11 -11
  98. package/Runtime/GNNetworkApi.cs +19 -26
  99. package/Runtime/GNNetworkApi.cs.meta +11 -11
  100. package/Runtime/GNNetworkAuthenticateApi.cs.meta +11 -11
  101. package/Runtime/GNNetworkCharacterPlayerApi.cs.meta +11 -11
  102. package/Runtime/GNNetworkContentApi.cs.meta +11 -11
  103. package/Runtime/GNNetworkDashboardApi.cs.meta +11 -11
  104. package/Runtime/GNNetworkGamePlayerApi.cs.meta +11 -11
  105. package/Runtime/GNNetworkGroupApi.cs.meta +11 -11
  106. package/Runtime/GNNetworkInventoryApi.cs.meta +11 -11
  107. package/Runtime/GNNetworkMasterPlayerApi.cs.meta +11 -11
  108. package/Runtime/GNNetworkMultiplayerApi.cs.meta +11 -11
  109. package/Runtime/GNNetworkStoreInventoryApi.cs.meta +11 -11
  110. package/Runtime/Helper/CodeHelper.cs +97 -97
  111. package/Runtime/Helper/CodeHelper.cs.meta +11 -11
  112. package/Runtime/Helper/ConverterService.cs +12 -22
  113. package/Runtime/Helper/ConverterService.cs.meta +11 -11
  114. package/Runtime/Helper/ParseGNHelper.cs +451 -451
  115. package/Runtime/Helper/ParseGNHelper.cs.meta +11 -11
  116. package/Runtime/Helper.meta +8 -8
  117. package/Runtime/Logger/GNDebug.cs +49 -49
  118. package/Runtime/Logger/GNDebug.cs.meta +11 -11
  119. package/Runtime/Logger.meta +8 -8
  120. package/Runtime/Networking/AuthenticateStatus.cs +35 -35
  121. package/Runtime/Networking/AuthenticateStatus.cs.meta +11 -11
  122. package/Runtime/Networking/Handler/IServerEventHandler.cs +25 -25
  123. package/Runtime/Networking/Handler/IServerEventHandler.cs.meta +11 -11
  124. package/Runtime/Networking/Handler/OnCharacterPlayerFriendUpdateEventHandler.cs +32 -32
  125. package/Runtime/Networking/Handler/OnCharacterPlayerFriendUpdateEventHandler.cs.meta +11 -11
  126. package/Runtime/Networking/Handler/OnCharacterPlayerGroupUpdateEventHandler.cs +33 -33
  127. package/Runtime/Networking/Handler/OnCharacterPlayerGroupUpdateEventHandler.cs.meta +11 -11
  128. package/Runtime/Networking/Handler/OnGamePlayerFriendUpdateEventHandler.cs +32 -32
  129. package/Runtime/Networking/Handler/OnGamePlayerFriendUpdateEventHandler.cs.meta +11 -11
  130. package/Runtime/Networking/Handler/OnGamePlayerGroupUpdateEventHandler.cs +32 -32
  131. package/Runtime/Networking/Handler/OnGamePlayerGroupUpdateEventHandler.cs.meta +11 -11
  132. package/Runtime/Networking/Handler/OnGroupMemberUpdateEventHandler.cs +29 -29
  133. package/Runtime/Networking/Handler/OnGroupMemberUpdateEventHandler.cs.meta +11 -11
  134. package/Runtime/Networking/Handler/OnGroupMessageUpdateEventHandler.cs +29 -29
  135. package/Runtime/Networking/Handler/OnGroupMessageUpdateEventHandler.cs.meta +11 -11
  136. package/Runtime/Networking/Handler.meta +8 -8
  137. package/Runtime/Networking/Http/HttpPeer.cs.meta +11 -11
  138. package/Runtime/Networking/Http/NetworkingHttpPeerBase.cs +25 -25
  139. package/Runtime/Networking/Http/NetworkingHttpPeerBase.cs.meta +11 -11
  140. package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs +486 -486
  141. package/Runtime/Networking/Http/NetworkingPeerHttpClientRequest.cs.meta +11 -11
  142. package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs +142 -142
  143. package/Runtime/Networking/Http/NetworkingPeerHttpRequest.cs.meta +11 -11
  144. package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs +188 -192
  145. package/Runtime/Networking/Http/NetworkingPeerUnityWebRequest.cs.meta +11 -11
  146. package/Runtime/Networking/Http.meta +8 -8
  147. package/Runtime/Networking/IPeer.cs +19 -19
  148. package/Runtime/Networking/IPeer.cs.meta +11 -11
  149. package/Runtime/Networking/NetworkingPeer.cs +144 -144
  150. package/Runtime/Networking/NetworkingPeer.cs.meta +11 -11
  151. package/Runtime/Networking/NetworkingPeerAPI.cs.meta +11 -11
  152. package/Runtime/Networking/OperationPending.cs +95 -95
  153. package/Runtime/Networking/OperationPending.cs.meta +11 -11
  154. package/Runtime/Networking/PeerBase.cs +242 -242
  155. package/Runtime/Networking/PeerBase.cs.meta +11 -11
  156. package/Runtime/Networking/Socket/NetworkingPeerSocketV2.cs +185 -183
  157. package/Runtime/Networking/Socket/NetworkingPeerSocketV2.cs.meta +11 -11
  158. package/Runtime/Networking/Socket/NetworkingPeerSocketV3.cs +177 -175
  159. package/Runtime/Networking/Socket/NetworkingPeerSocketV3.cs.meta +11 -11
  160. package/Runtime/Networking/Socket/NetworkingSocketPeerBase.cs.meta +11 -11
  161. package/Runtime/Networking/Socket/SocketPeer.cs +197 -191
  162. package/Runtime/Networking/Socket/SocketPeer.cs.meta +11 -11
  163. package/Runtime/Networking/Socket.meta +8 -8
  164. package/Runtime/Networking.meta +8 -8
  165. package/Runtime/Unity/ServiceUpdate.cs +20 -20
  166. package/Runtime/Unity/ServiceUpdate.cs.meta +11 -11
  167. package/Runtime/Unity.meta +8 -8
  168. package/Runtime/XmobiTea.GN.runtime.asmdef +16 -16
  169. package/Runtime/XmobiTea.GN.runtime.asmdef.meta +7 -7
  170. package/package.json +1 -1
@@ -1,451 +1,451 @@
1
- namespace XmobiTea.GN.Helper
2
- {
3
- using System;
4
- using System.Collections.Generic;
5
- using System.Globalization;
6
- using System.IO;
7
- using System.Text;
8
-
9
- using IDictionary = System.Collections.IDictionary;
10
- using IEnumerable = System.Collections.IEnumerable;
11
- using IList = System.Collections.IList;
12
-
13
- public class Parser : IDisposable
14
- {
15
- private StringReader json;
16
-
17
- private Parser(string jsonString)
18
- {
19
- this.json = new StringReader(jsonString);
20
- }
21
-
22
- public static object Parse(string jsonString)
23
- {
24
- using (var parser = new Parser(jsonString))
25
- return parser.ParseValue();
26
- }
27
-
28
- public void Dispose()
29
- {
30
- this.json.Dispose();
31
- this.json = (StringReader)null;
32
- }
33
-
34
- private Dictionary<string, object> ParseObject()
35
- {
36
- Dictionary<string, object> dictionary = new Dictionary<string, object>();
37
- this.json.Read();
38
- while (true)
39
- {
40
- Parser.TOKEN nextToken;
41
- do
42
- {
43
- nextToken = this.NextToken;
44
- switch (nextToken)
45
- {
46
- case Parser.TOKEN.NONE:
47
- goto label_3;
48
- case Parser.TOKEN.CURLY_OPEN:
49
- goto label_5;
50
- case Parser.TOKEN.CURLY_CLOSE:
51
- goto label_4;
52
- default:
53
- continue;
54
- }
55
- }
56
- while (nextToken == Parser.TOKEN.COMMA);
57
- label_5:
58
- string index = this.ParseString();
59
- if (index != null)
60
- {
61
- if (this.NextToken == Parser.TOKEN.COLON)
62
- {
63
- this.json.Read();
64
- dictionary[index] = this.ParseValue();
65
- }
66
- else
67
- goto label_8;
68
- }
69
- else
70
- goto label_6;
71
- }
72
- label_3:
73
- return (Dictionary<string, object>)null;
74
- label_4:
75
- return dictionary;
76
- label_6:
77
- return (Dictionary<string, object>)null;
78
- label_8:
79
- return (Dictionary<string, object>)null;
80
- }
81
-
82
- private List<object> ParseArray()
83
- {
84
- List<object> objectList = new List<object>();
85
- this.json.Read();
86
- bool flag = true;
87
- while (flag)
88
- {
89
- var nextToken = this.NextToken;
90
- switch (nextToken)
91
- {
92
- case Parser.TOKEN.NONE:
93
- return (List<object>)null;
94
- case Parser.TOKEN.SQUARED_CLOSE:
95
- flag = false;
96
- continue;
97
- case Parser.TOKEN.COMMA:
98
- continue;
99
- default:
100
- object byToken = this.ParseByToken(nextToken);
101
- objectList.Add(byToken);
102
- continue;
103
- }
104
- }
105
- return objectList;
106
- }
107
-
108
- private object ParseValue()
109
- {
110
- return this.ParseByToken(this.NextToken);
111
- }
112
-
113
- private object ParseByToken(Parser.TOKEN token)
114
- {
115
- switch (token)
116
- {
117
- case Parser.TOKEN.CURLY_OPEN:
118
- return (object)this.ParseObject();
119
- case Parser.TOKEN.SQUARED_OPEN:
120
- return (object)this.ParseArray();
121
- case Parser.TOKEN.STRING:
122
- return (object)this.ParseString();
123
- case Parser.TOKEN.NUMBER:
124
- return this.ParseNumber();
125
- case Parser.TOKEN.TRUE:
126
- return (object)true;
127
- case Parser.TOKEN.FALSE:
128
- return (object)false;
129
- case Parser.TOKEN.NULL:
130
- return (object)null;
131
- default:
132
- return (object)null;
133
- }
134
- }
135
-
136
- private string ParseString()
137
- {
138
- StringBuilder stringBuilder1 = new StringBuilder();
139
- this.json.Read();
140
- bool flag = true;
141
- while (flag)
142
- {
143
- if (this.json.Peek() == -1)
144
- break;
145
- char nextChar1 = this.NextChar;
146
- switch (nextChar1)
147
- {
148
- case '"':
149
- flag = false;
150
- continue;
151
- case '\\':
152
- if (this.json.Peek() == -1)
153
- {
154
- flag = false;
155
- continue;
156
- }
157
- char nextChar2 = this.NextChar;
158
- switch (nextChar2)
159
- {
160
- case '"':
161
- case '/':
162
- case '\\':
163
- stringBuilder1.Append(nextChar2);
164
- continue;
165
- case 'b':
166
- stringBuilder1.Append('\b');
167
- continue;
168
- case 'f':
169
- stringBuilder1.Append('\f');
170
- continue;
171
- case 'n':
172
- stringBuilder1.Append('\n');
173
- continue;
174
- case 'r':
175
- stringBuilder1.Append('\r');
176
- continue;
177
- case 't':
178
- stringBuilder1.Append('\t');
179
- continue;
180
- case 'u':
181
- StringBuilder stringBuilder2 = new StringBuilder();
182
- for (int index = 0; index < 4; ++index)
183
- stringBuilder2.Append(this.NextChar);
184
- stringBuilder1.Append((char)Convert.ToInt32(stringBuilder2.ToString(), 16));
185
- continue;
186
- default:
187
- continue;
188
- }
189
- default:
190
- stringBuilder1.Append(nextChar1);
191
- continue;
192
- }
193
- }
194
- return stringBuilder1.ToString();
195
- }
196
-
197
- private object ParseNumber()
198
- {
199
- double result;
200
- double.TryParse(this.NextWord, NumberStyles.Any, (IFormatProvider)CultureInfo.InvariantCulture, out result);
201
- return (object)result;
202
- }
203
-
204
- private void EatWhitespace()
205
- {
206
- while (" \t\n\r".IndexOf(this.PeekChar) != -1)
207
- {
208
- this.json.Read();
209
- if (this.json.Peek() == -1)
210
- break;
211
- }
212
- }
213
-
214
- private char PeekChar
215
- {
216
- get
217
- {
218
- return Convert.ToChar(this.json.Peek());
219
- }
220
- }
221
-
222
- private char NextChar
223
- {
224
- get
225
- {
226
- return Convert.ToChar(this.json.Read());
227
- }
228
- }
229
-
230
- private string NextWord
231
- {
232
- get
233
- {
234
- StringBuilder stringBuilder = new StringBuilder();
235
- while (" \t\n\r{}[],:\"".IndexOf(this.PeekChar) == -1)
236
- {
237
- stringBuilder.Append(this.NextChar);
238
- if (this.json.Peek() == -1)
239
- break;
240
- }
241
- return stringBuilder.ToString();
242
- }
243
- }
244
-
245
- private Parser.TOKEN NextToken
246
- {
247
- get
248
- {
249
- this.EatWhitespace();
250
- if (this.json.Peek() == -1)
251
- return Parser.TOKEN.NONE;
252
- switch (this.PeekChar)
253
- {
254
- case '"':
255
- return Parser.TOKEN.STRING;
256
- case ',':
257
- this.json.Read();
258
- return Parser.TOKEN.COMMA;
259
- case '-':
260
- case '0':
261
- case '1':
262
- case '2':
263
- case '3':
264
- case '4':
265
- case '5':
266
- case '6':
267
- case '7':
268
- case '8':
269
- case '9':
270
- case 'I':
271
- case 'N':
272
- return Parser.TOKEN.NUMBER;
273
- case ':':
274
- return Parser.TOKEN.COLON;
275
- case '[':
276
- return Parser.TOKEN.SQUARED_OPEN;
277
- case ']':
278
- this.json.Read();
279
- return Parser.TOKEN.SQUARED_CLOSE;
280
- case '{':
281
- return Parser.TOKEN.CURLY_OPEN;
282
- case '}':
283
- this.json.Read();
284
- return Parser.TOKEN.CURLY_CLOSE;
285
- default:
286
- switch (this.NextWord)
287
- {
288
- case "false":
289
- return Parser.TOKEN.FALSE;
290
- case "true":
291
- return Parser.TOKEN.TRUE;
292
- case "null":
293
- return Parser.TOKEN.NULL;
294
- default:
295
- return Parser.TOKEN.NONE;
296
- }
297
- }
298
- }
299
- }
300
-
301
- private enum TOKEN
302
- {
303
- NONE,
304
- CURLY_OPEN,
305
- CURLY_CLOSE,
306
- SQUARED_OPEN,
307
- SQUARED_CLOSE,
308
- COLON,
309
- COMMA,
310
- STRING,
311
- NUMBER,
312
- TRUE,
313
- FALSE,
314
- NULL,
315
- }
316
- }
317
-
318
- public class Serializer
319
- {
320
- private StringBuilder builder;
321
-
322
- private Serializer()
323
- {
324
- this.builder = new StringBuilder();
325
- }
326
-
327
- public static string Serialize(object obj)
328
- {
329
- var serializer = new Serializer();
330
- serializer.SerializeValue(obj);
331
- return serializer.builder.ToString();
332
- }
333
-
334
- private void SerializeValue(object value)
335
- {
336
- //if (value is IGSData)
337
- // value = (object)((IGSData)value).BaseData;
338
- if (value == null)
339
- this.builder.Append("null");
340
- else if (value is string str)
341
- this.SerializeString(str);
342
- else if (value is bool)
343
- this.builder.Append(value.ToString().ToLower());
344
- else if (value is IList anArray)
345
- this.SerializeArray(anArray);
346
- else if (value is IDictionary dictionary)
347
- this.SerializeObject(dictionary);
348
- else if (value is char)
349
- this.SerializeString(value.ToString());
350
- else
351
- this.SerializeOther(value);
352
- }
353
-
354
- private void SerializeObject(IDictionary obj)
355
- {
356
- bool flag = true;
357
- this.builder.Append('{');
358
- foreach (object key in (IEnumerable)obj.Keys)
359
- {
360
- if (!flag)
361
- this.builder.Append(',');
362
- this.SerializeString(key.ToString());
363
- this.builder.Append(':');
364
- this.SerializeValue(obj[key]);
365
- flag = false;
366
- }
367
- this.builder.Append('}');
368
- }
369
-
370
- private void SerializeArray(IList anArray)
371
- {
372
- this.builder.Append('[');
373
- bool flag = true;
374
- foreach (object an in (IEnumerable)anArray)
375
- {
376
- if (!flag)
377
- this.builder.Append(',');
378
- this.SerializeValue(an);
379
- flag = false;
380
- }
381
- this.builder.Append(']');
382
- }
383
-
384
- private void SerializeString(string str)
385
- {
386
- this.builder.Append('"');
387
- foreach (char ch in str.ToCharArray())
388
- {
389
- switch (ch)
390
- {
391
- case '\b':
392
- this.builder.Append("\\b");
393
- break;
394
- case '\t':
395
- this.builder.Append("\\t");
396
- break;
397
- case '\n':
398
- this.builder.Append("\\n");
399
- break;
400
- case '\f':
401
- this.builder.Append("\\f");
402
- break;
403
- case '\r':
404
- this.builder.Append("\\r");
405
- break;
406
- case '"':
407
- this.builder.Append("\\\"");
408
- break;
409
- case '\\':
410
- this.builder.Append("\\\\");
411
- break;
412
- default:
413
- int int32 = Convert.ToInt32(ch);
414
- if (int32 >= 32 && int32 <= 126)
415
- {
416
- this.builder.Append(ch);
417
- break;
418
- }
419
- this.builder.Append("\\u" + Convert.ToString(int32, 16).PadLeft(4, '0'));
420
- break;
421
- }
422
- }
423
- this.builder.Append('"');
424
- }
425
-
426
- private void SerializeOther(object value)
427
- {
428
- switch (value)
429
- {
430
- case float _:
431
- case int _:
432
- case uint _:
433
- case long _:
434
- case double _:
435
- case sbyte _:
436
- case byte _:
437
- case short _:
438
- case ushort _:
439
- case ulong _:
440
- case Decimal _:
441
- this.builder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, "{0}", value);
442
- break;
443
- default:
444
- this.SerializeString(value.ToString());
445
- break;
446
- }
447
- }
448
-
449
- }
450
-
451
- }
1
+ namespace XmobiTea.GN.Helper
2
+ {
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Globalization;
6
+ using System.IO;
7
+ using System.Text;
8
+
9
+ using IDictionary = System.Collections.IDictionary;
10
+ using IEnumerable = System.Collections.IEnumerable;
11
+ using IList = System.Collections.IList;
12
+
13
+ public class Parser : IDisposable
14
+ {
15
+ private StringReader json;
16
+
17
+ private Parser(string jsonString)
18
+ {
19
+ this.json = new StringReader(jsonString);
20
+ }
21
+
22
+ public static object Parse(string jsonString)
23
+ {
24
+ using (var parser = new Parser(jsonString))
25
+ return parser.ParseValue();
26
+ }
27
+
28
+ public void Dispose()
29
+ {
30
+ this.json.Dispose();
31
+ this.json = (StringReader)null;
32
+ }
33
+
34
+ private Dictionary<string, object> ParseObject()
35
+ {
36
+ Dictionary<string, object> dictionary = new Dictionary<string, object>();
37
+ this.json.Read();
38
+ while (true)
39
+ {
40
+ Parser.TOKEN nextToken;
41
+ do
42
+ {
43
+ nextToken = this.NextToken;
44
+ switch (nextToken)
45
+ {
46
+ case Parser.TOKEN.NONE:
47
+ goto label_3;
48
+ case Parser.TOKEN.CURLY_OPEN:
49
+ goto label_5;
50
+ case Parser.TOKEN.CURLY_CLOSE:
51
+ goto label_4;
52
+ default:
53
+ continue;
54
+ }
55
+ }
56
+ while (nextToken == Parser.TOKEN.COMMA);
57
+ label_5:
58
+ string index = this.ParseString();
59
+ if (index != null)
60
+ {
61
+ if (this.NextToken == Parser.TOKEN.COLON)
62
+ {
63
+ this.json.Read();
64
+ dictionary[index] = this.ParseValue();
65
+ }
66
+ else
67
+ goto label_8;
68
+ }
69
+ else
70
+ goto label_6;
71
+ }
72
+ label_3:
73
+ return (Dictionary<string, object>)null;
74
+ label_4:
75
+ return dictionary;
76
+ label_6:
77
+ return (Dictionary<string, object>)null;
78
+ label_8:
79
+ return (Dictionary<string, object>)null;
80
+ }
81
+
82
+ private List<object> ParseArray()
83
+ {
84
+ List<object> objectList = new List<object>();
85
+ this.json.Read();
86
+ bool flag = true;
87
+ while (flag)
88
+ {
89
+ var nextToken = this.NextToken;
90
+ switch (nextToken)
91
+ {
92
+ case Parser.TOKEN.NONE:
93
+ return (List<object>)null;
94
+ case Parser.TOKEN.SQUARED_CLOSE:
95
+ flag = false;
96
+ continue;
97
+ case Parser.TOKEN.COMMA:
98
+ continue;
99
+ default:
100
+ object byToken = this.ParseByToken(nextToken);
101
+ objectList.Add(byToken);
102
+ continue;
103
+ }
104
+ }
105
+ return objectList;
106
+ }
107
+
108
+ private object ParseValue()
109
+ {
110
+ return this.ParseByToken(this.NextToken);
111
+ }
112
+
113
+ private object ParseByToken(Parser.TOKEN token)
114
+ {
115
+ switch (token)
116
+ {
117
+ case Parser.TOKEN.CURLY_OPEN:
118
+ return (object)this.ParseObject();
119
+ case Parser.TOKEN.SQUARED_OPEN:
120
+ return (object)this.ParseArray();
121
+ case Parser.TOKEN.STRING:
122
+ return (object)this.ParseString();
123
+ case Parser.TOKEN.NUMBER:
124
+ return this.ParseNumber();
125
+ case Parser.TOKEN.TRUE:
126
+ return (object)true;
127
+ case Parser.TOKEN.FALSE:
128
+ return (object)false;
129
+ case Parser.TOKEN.NULL:
130
+ return (object)null;
131
+ default:
132
+ return (object)null;
133
+ }
134
+ }
135
+
136
+ private string ParseString()
137
+ {
138
+ StringBuilder stringBuilder1 = new StringBuilder();
139
+ this.json.Read();
140
+ bool flag = true;
141
+ while (flag)
142
+ {
143
+ if (this.json.Peek() == -1)
144
+ break;
145
+ char nextChar1 = this.NextChar;
146
+ switch (nextChar1)
147
+ {
148
+ case '"':
149
+ flag = false;
150
+ continue;
151
+ case '\\':
152
+ if (this.json.Peek() == -1)
153
+ {
154
+ flag = false;
155
+ continue;
156
+ }
157
+ char nextChar2 = this.NextChar;
158
+ switch (nextChar2)
159
+ {
160
+ case '"':
161
+ case '/':
162
+ case '\\':
163
+ stringBuilder1.Append(nextChar2);
164
+ continue;
165
+ case 'b':
166
+ stringBuilder1.Append('\b');
167
+ continue;
168
+ case 'f':
169
+ stringBuilder1.Append('\f');
170
+ continue;
171
+ case 'n':
172
+ stringBuilder1.Append('\n');
173
+ continue;
174
+ case 'r':
175
+ stringBuilder1.Append('\r');
176
+ continue;
177
+ case 't':
178
+ stringBuilder1.Append('\t');
179
+ continue;
180
+ case 'u':
181
+ StringBuilder stringBuilder2 = new StringBuilder();
182
+ for (int index = 0; index < 4; ++index)
183
+ stringBuilder2.Append(this.NextChar);
184
+ stringBuilder1.Append((char)Convert.ToInt32(stringBuilder2.ToString(), 16));
185
+ continue;
186
+ default:
187
+ continue;
188
+ }
189
+ default:
190
+ stringBuilder1.Append(nextChar1);
191
+ continue;
192
+ }
193
+ }
194
+ return stringBuilder1.ToString();
195
+ }
196
+
197
+ private object ParseNumber()
198
+ {
199
+ double result;
200
+ double.TryParse(this.NextWord, NumberStyles.Any, (IFormatProvider)CultureInfo.InvariantCulture, out result);
201
+ return (object)result;
202
+ }
203
+
204
+ private void EatWhitespace()
205
+ {
206
+ while (" \t\n\r".IndexOf(this.PeekChar) != -1)
207
+ {
208
+ this.json.Read();
209
+ if (this.json.Peek() == -1)
210
+ break;
211
+ }
212
+ }
213
+
214
+ private char PeekChar
215
+ {
216
+ get
217
+ {
218
+ return Convert.ToChar(this.json.Peek());
219
+ }
220
+ }
221
+
222
+ private char NextChar
223
+ {
224
+ get
225
+ {
226
+ return Convert.ToChar(this.json.Read());
227
+ }
228
+ }
229
+
230
+ private string NextWord
231
+ {
232
+ get
233
+ {
234
+ StringBuilder stringBuilder = new StringBuilder();
235
+ while (" \t\n\r{}[],:\"".IndexOf(this.PeekChar) == -1)
236
+ {
237
+ stringBuilder.Append(this.NextChar);
238
+ if (this.json.Peek() == -1)
239
+ break;
240
+ }
241
+ return stringBuilder.ToString();
242
+ }
243
+ }
244
+
245
+ private Parser.TOKEN NextToken
246
+ {
247
+ get
248
+ {
249
+ this.EatWhitespace();
250
+ if (this.json.Peek() == -1)
251
+ return Parser.TOKEN.NONE;
252
+ switch (this.PeekChar)
253
+ {
254
+ case '"':
255
+ return Parser.TOKEN.STRING;
256
+ case ',':
257
+ this.json.Read();
258
+ return Parser.TOKEN.COMMA;
259
+ case '-':
260
+ case '0':
261
+ case '1':
262
+ case '2':
263
+ case '3':
264
+ case '4':
265
+ case '5':
266
+ case '6':
267
+ case '7':
268
+ case '8':
269
+ case '9':
270
+ case 'I':
271
+ case 'N':
272
+ return Parser.TOKEN.NUMBER;
273
+ case ':':
274
+ return Parser.TOKEN.COLON;
275
+ case '[':
276
+ return Parser.TOKEN.SQUARED_OPEN;
277
+ case ']':
278
+ this.json.Read();
279
+ return Parser.TOKEN.SQUARED_CLOSE;
280
+ case '{':
281
+ return Parser.TOKEN.CURLY_OPEN;
282
+ case '}':
283
+ this.json.Read();
284
+ return Parser.TOKEN.CURLY_CLOSE;
285
+ default:
286
+ switch (this.NextWord)
287
+ {
288
+ case "false":
289
+ return Parser.TOKEN.FALSE;
290
+ case "true":
291
+ return Parser.TOKEN.TRUE;
292
+ case "null":
293
+ return Parser.TOKEN.NULL;
294
+ default:
295
+ return Parser.TOKEN.NONE;
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ private enum TOKEN
302
+ {
303
+ NONE,
304
+ CURLY_OPEN,
305
+ CURLY_CLOSE,
306
+ SQUARED_OPEN,
307
+ SQUARED_CLOSE,
308
+ COLON,
309
+ COMMA,
310
+ STRING,
311
+ NUMBER,
312
+ TRUE,
313
+ FALSE,
314
+ NULL,
315
+ }
316
+ }
317
+
318
+ public class Serializer
319
+ {
320
+ private StringBuilder builder;
321
+
322
+ private Serializer()
323
+ {
324
+ this.builder = new StringBuilder();
325
+ }
326
+
327
+ public static string Serialize(object obj)
328
+ {
329
+ var serializer = new Serializer();
330
+ serializer.SerializeValue(obj);
331
+ return serializer.builder.ToString();
332
+ }
333
+
334
+ private void SerializeValue(object value)
335
+ {
336
+ //if (value is IGSData)
337
+ // value = (object)((IGSData)value).BaseData;
338
+ if (value == null)
339
+ this.builder.Append("null");
340
+ else if (value is string str)
341
+ this.SerializeString(str);
342
+ else if (value is bool)
343
+ this.builder.Append(value.ToString().ToLower());
344
+ else if (value is IList anArray)
345
+ this.SerializeArray(anArray);
346
+ else if (value is IDictionary dictionary)
347
+ this.SerializeObject(dictionary);
348
+ else if (value is char)
349
+ this.SerializeString(value.ToString());
350
+ else
351
+ this.SerializeOther(value);
352
+ }
353
+
354
+ private void SerializeObject(IDictionary obj)
355
+ {
356
+ bool flag = true;
357
+ this.builder.Append('{');
358
+ foreach (object key in (IEnumerable)obj.Keys)
359
+ {
360
+ if (!flag)
361
+ this.builder.Append(',');
362
+ this.SerializeString(key.ToString());
363
+ this.builder.Append(':');
364
+ this.SerializeValue(obj[key]);
365
+ flag = false;
366
+ }
367
+ this.builder.Append('}');
368
+ }
369
+
370
+ private void SerializeArray(IList anArray)
371
+ {
372
+ this.builder.Append('[');
373
+ bool flag = true;
374
+ foreach (object an in (IEnumerable)anArray)
375
+ {
376
+ if (!flag)
377
+ this.builder.Append(',');
378
+ this.SerializeValue(an);
379
+ flag = false;
380
+ }
381
+ this.builder.Append(']');
382
+ }
383
+
384
+ private void SerializeString(string str)
385
+ {
386
+ this.builder.Append('"');
387
+ foreach (char ch in str.ToCharArray())
388
+ {
389
+ switch (ch)
390
+ {
391
+ case '\b':
392
+ this.builder.Append("\\b");
393
+ break;
394
+ case '\t':
395
+ this.builder.Append("\\t");
396
+ break;
397
+ case '\n':
398
+ this.builder.Append("\\n");
399
+ break;
400
+ case '\f':
401
+ this.builder.Append("\\f");
402
+ break;
403
+ case '\r':
404
+ this.builder.Append("\\r");
405
+ break;
406
+ case '"':
407
+ this.builder.Append("\\\"");
408
+ break;
409
+ case '\\':
410
+ this.builder.Append("\\\\");
411
+ break;
412
+ default:
413
+ int int32 = Convert.ToInt32(ch);
414
+ if (int32 >= 32 && int32 <= 126)
415
+ {
416
+ this.builder.Append(ch);
417
+ break;
418
+ }
419
+ this.builder.Append("\\u" + Convert.ToString(int32, 16).PadLeft(4, '0'));
420
+ break;
421
+ }
422
+ }
423
+ this.builder.Append('"');
424
+ }
425
+
426
+ private void SerializeOther(object value)
427
+ {
428
+ switch (value)
429
+ {
430
+ case float _:
431
+ case int _:
432
+ case uint _:
433
+ case long _:
434
+ case double _:
435
+ case sbyte _:
436
+ case byte _:
437
+ case short _:
438
+ case ushort _:
439
+ case ulong _:
440
+ case Decimal _:
441
+ this.builder.AppendFormat((IFormatProvider)CultureInfo.InvariantCulture, "{0}", value);
442
+ break;
443
+ default:
444
+ this.SerializeString(value.ToString());
445
+ break;
446
+ }
447
+ }
448
+
449
+ }
450
+
451
+ }