PluralKit/Myriad/Serialization/PermissionSetJsonConverter.cs

24 lines
694 B
C#
Raw Normal View History

2021-08-27 15:03:47 +00:00
using System;
2020-12-22 12:15:26 +00:00
using System.Text.Json;
using System.Text.Json.Serialization;
using Myriad.Types;
namespace Myriad.Serialization
{
public class PermissionSetJsonConverter: JsonConverter<PermissionSet>
{
public override PermissionSet Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var str = reader.GetString();
if (str == null) return default;
2021-08-27 15:03:47 +00:00
return (PermissionSet)ulong.Parse(str);
2020-12-22 12:15:26 +00:00
}
public override void Write(Utf8JsonWriter writer, PermissionSet value, JsonSerializerOptions options)
{
2021-08-27 15:03:47 +00:00
writer.WriteStringValue(((ulong)value).ToString());
2020-12-22 12:15:26 +00:00
}
}
}