wabbajack/Wabbajack.DTOs/JsonConverters/PHashConverter.cs

22 lines
655 B
C#
Raw Normal View History

2021-09-27 12:42:46 +00:00
using System;
using System.Buffers.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Wabbajack.DTOs.Texture;
2021-10-23 16:51:17 +00:00
namespace Wabbajack.DTOs.JsonConverters;
public class PHashConverter : JsonConverter<PHash>
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
public override PHash Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
2021-09-27 12:42:46 +00:00
{
2021-10-23 16:51:17 +00:00
var data = new byte[40];
Base64.DecodeFromUtf8(reader.ValueSpan, data, out var _, out var _);
return new PHash(data);
}
2021-09-27 12:42:46 +00:00
2021-10-23 16:51:17 +00:00
public override void Write(Utf8JsonWriter writer, PHash value, JsonSerializerOptions options)
{
writer.WriteBase64StringValue(value.Data);
2021-09-27 12:42:46 +00:00
}
}