Timothy Schenk
40b2896fa3
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 26s
Build, Package and Push Images / sbom-scan (push) Successful in 35s
Build, Package and Push Images / sonarqube (push) Successful in 1m24s
Build, Package and Push Images / container-build (push) Successful in 1m24s
Build, Package and Push Images / container-sbom-scan (push) Successful in 33s
39 lines
1,000 B
C#
39 lines
1,000 B
C#
// // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
|
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Wonderking.Utils;
|
|
|
|
public class ByteArrayConverter : JsonConverter<byte[]>
|
|
{
|
|
public override byte[] Read(
|
|
ref Utf8JsonReader reader,
|
|
Type typeToConvert,
|
|
JsonSerializerOptions options)
|
|
{
|
|
var hexData = reader.GetString();
|
|
if (hexData != null)
|
|
{
|
|
return hexData.Split('-').Select(b => Convert.ToByte(b, 16)).ToArray();
|
|
}
|
|
|
|
throw new JsonException("Hex string is null.");
|
|
}
|
|
|
|
public override void Write(
|
|
Utf8JsonWriter writer,
|
|
byte[]? value,
|
|
JsonSerializerOptions options)
|
|
{
|
|
if (value == null)
|
|
{
|
|
writer.WriteNullValue();
|
|
}
|
|
else
|
|
{
|
|
var hexData = BitConverter.ToString(value).Replace("-", string.Empty);
|
|
writer.WriteStringValue(hexData);
|
|
}
|
|
}
|
|
}
|