Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TimeSpanConverter.cs
Go to the documentation of this file.
3
5
6internal sealed class TimeSpanConverter : JsonConverter<TimeSpan>
7{
9 {
10 if (reader.TokenType != JsonTokenType.String)
11 {
13 }
14 bool stringHasEscaping = reader._stringHasEscaping;
15 int num = (stringHasEscaping ? 156 : 26);
17 if (reader.HasValueSequence)
18 {
19 ReadOnlySequence<byte> source = reader.ValueSequence;
20 long length = source.Length;
22 {
24 }
27 readOnlySpan = destination.Slice(0, (int)length);
28 }
29 else
30 {
31 readOnlySpan = reader.ValueSpan;
32 if (!JsonHelpers.IsInRangeInclusive(readOnlySpan.Length, 8, num))
33 {
35 }
36 }
38 {
39 int idx = readOnlySpan.IndexOf<byte>(92);
43 }
44 byte b = readOnlySpan[0];
45 if (!JsonHelpers.IsDigit(b) && b != 45)
46 {
48 }
50 {
51 return value;
52 }
54 }
55
57 {
59 int bytesWritten;
61 writer.WriteStringValue(destination.Slice(0, bytesWritten));
62 }
63}
static bool TryFormat(bool value, Span< byte > destination, out int bytesWritten, StandardFormat format=default(StandardFormat))
static bool TryParse(ReadOnlySpan< byte > source, out bool value, out int bytesConsumed, char standardFormat='\0')
static bool IsInRangeInclusive(uint value, uint lowerBound, uint upperBound)
static bool IsDigit(byte value)
static void Unescape(ReadOnlySpan< byte > source, Span< byte > destination, int idx, out int written)
override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
static FormatException GetFormatException()
static InvalidOperationException GetInvalidOperationException_ExpectedString(JsonTokenType tokenType)
void CopyTo(Span< T > destination)
Definition Span.cs:224