source: binary-improvements2/WebServer/src/WebAPI/JsonCommons.cs@ 426

Last change on this file since 426 was 426, checked in by alloc, 19 months ago

*Updated web permissions system
*Fixed webpermissions command
*Moved API "webmods" to "mods", also lists non-webmod mods

File size: 2.5 KB
Line 
1using System;
2using UnityEngine;
3using Utf8Json;
4
5namespace Webserver.WebAPI {
6 public static class JsonCommons {
7 private static readonly byte[] jsonKeyPositionX = JsonWriter.GetEncodedPropertyNameWithBeginObject ("x");
8 private static readonly byte[] jsonKeyPositionY = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("y");
9 private static readonly byte[] jsonKeyPositionZ = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("z");
10
11 public static void WritePositionObject (ref JsonWriter _writer, Vector3i _position) {
12 _writer.WriteRaw (jsonKeyPositionX);
13 _writer.WriteInt32 (_position.x);
14
15 _writer.WriteRaw (jsonKeyPositionY);
16 _writer.WriteInt32 (_position.y);
17
18 _writer.WriteRaw (jsonKeyPositionZ);
19 _writer.WriteInt32 (_position.z);
20
21 _writer.WriteEndObject ();
22 }
23
24 public static void WritePositionObject (ref JsonWriter _writer, Vector3 _position) {
25 _writer.WriteRaw (jsonKeyPositionX);
26 _writer.WriteSingle (_position.x);
27
28 _writer.WriteRaw (jsonKeyPositionY);
29 _writer.WriteSingle (_position.y);
30
31 _writer.WriteRaw (jsonKeyPositionZ);
32 _writer.WriteSingle (_position.z);
33
34 _writer.WriteEndObject ();
35 }
36
37 private static readonly byte[] jsonKeyCombinedString = JsonWriter.GetEncodedPropertyNameWithBeginObject ("combinedString");
38 private static readonly byte[] jsonKeyPlatformId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("platformId");
39 private static readonly byte[] jsonKeyUserId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("userId");
40
41 public static void WritePlatformUserIdentifier (ref JsonWriter _writer, PlatformUserIdentifierAbs _userIdentifier) {
42 if (_userIdentifier == null) {
43 _writer.WriteNull ();
44 return;
45 }
46
47 _writer.WriteRaw (jsonKeyCombinedString);
48 _writer.WriteString (_userIdentifier.CombinedString);
49
50 _writer.WriteRaw (jsonKeyPlatformId);
51 _writer.WriteString (_userIdentifier.PlatformIdentifierString);
52
53 _writer.WriteRaw (jsonKeyUserId);
54 _writer.WriteString (_userIdentifier.ReadablePlatformUserIdentifier);
55
56 _writer.WriteEndObject ();
57 }
58
59 public static void WriteDateTime (ref JsonWriter _writer, DateTime _dateTime) {
60 _writer.WriteString (_dateTime.ToString ("o"));
61 }
62
63 public static void WriteStringOrNull (ref JsonWriter _writer, string _string) {
64 if (_string == null) {
65 _writer.WriteNull ();
66 } else {
67 _writer.WriteString (_string);
68 }
69 }
70 }
71}
Note: See TracBrowser for help on using the repository browser.