ScanMountGoat / ArcExplorer

A cross-platform file browser and extractor for Smash Ultimate's data.arc file.
MIT License
32 stars 2 forks source link

Use System.Text.Json for settings #47

Closed ScanMountGoat closed 3 years ago

ScanMountGoat commented 3 years ago

In theory, this should improve performance and memory usage on startup.

ScanMountGoat commented 3 years ago
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace JsonConsole
{
    class Program
    {
        enum MyEnum
        {
            One,
            Two,
            Three
        }
        class MyData
        {
            public string Name { get; set; } = "ABC";
            public int Value { get; set; } = 3;
            public MyEnum Variant { get; set; } = MyEnum.Two;
        }
        static void Main(string[] args)
        {
            var options = new JsonSerializerOptions { Converters = { new JsonStringEnumConverter() } };
            var json = JsonSerializer.Serialize(new MyData(), options);
            // This should be faster.
            //JsonSerializer.SerializeToUtf8Bytes
            Console.WriteLine(json);

            var data = JsonSerializer.Deserialize<MyData>(json, options);
            // This should be faster.
            //JsonSerializer.Deserialize<MyData>(System.IO.File.ReadAllBytes("path.txt"));
            Console.WriteLine($"{data.Name} {data.Value} {data.Variant}");
        }
    }
}