-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Run, extract SplitsController, use source generator
- Loading branch information
Showing
16 changed files
with
511 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using SpeedTool.Splits; | ||
using SpeedTool.Timer; | ||
|
||
namespace SpeedTool.JSON; | ||
|
||
public sealed class TimeCollectionConverter : JsonConverter<TimeCollection> | ||
{ | ||
public override TimeCollection Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType != JsonTokenType.StartArray) | ||
{ | ||
throw new JsonException($"Invalid object"); | ||
} | ||
|
||
TimeCollection tc = new(); | ||
|
||
for(int i = 0; i < (int)TimingMethod.Last; i++) | ||
{ | ||
reader.Read(); | ||
if(reader.TokenType != JsonTokenType.Number) | ||
throw new JsonException("Expected number"); | ||
|
||
tc[(TimingMethod)i] = new TimeSpan(reader.GetInt64()); | ||
} | ||
|
||
while (reader.TokenType != JsonTokenType.EndArray) | ||
{ | ||
reader.Read(); | ||
} | ||
|
||
return tc; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, TimeCollection value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteStartArray(); | ||
|
||
for(int i = 0; i < (int)TimingMethod.Last; i++) | ||
writer.WriteNumberValue(value[(TimingMethod)i].Ticks); | ||
|
||
writer.WriteEndArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.