[425] | 1 | using System;
|
---|
| 2 | using UnityEngine;
|
---|
[402] | 3 | using Utf8Json;
|
---|
| 4 |
|
---|
| 5 | namespace 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 |
|
---|
[408] | 11 | public static void WritePositionObject (ref JsonWriter _writer, Vector3i _position) {
|
---|
[402] | 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 | }
|
---|
[425] | 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 | }
|
---|
[426] | 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 | }
|
---|
[402] | 70 | }
|
---|
| 71 | }
|
---|