feat(batch15): complete group 1 msgblock/consumerfilestore

This commit is contained in:
Joseph Doherty
2026-02-28 17:03:31 -05:00
parent 5367c3f34d
commit f36bc3111b
8 changed files with 813 additions and 10 deletions

View File

@@ -0,0 +1,54 @@
using System.Text.Json;
namespace ZB.MOM.NatsNet.Server;
/// <summary>
/// String/JSON helpers for store enums that mirror Go enum methods.
/// </summary>
public static class StoreEnumExtensions
{
public static string String(this StoreCipher cipher)
=> cipher switch
{
StoreCipher.ChaCha => "ChaCha20-Poly1305",
StoreCipher.Aes => "AES-GCM",
StoreCipher.NoCipher => "None",
_ => "Unknown StoreCipher",
};
public static string String(this StoreCompression alg)
=> alg switch
{
StoreCompression.NoCompression => "None",
StoreCompression.S2Compression => "S2",
_ => "Unknown StoreCompression",
};
public static byte[] MarshalJSON(this StoreCompression alg)
=> alg switch
{
StoreCompression.NoCompression => JsonSerializer.SerializeToUtf8Bytes("none"),
StoreCompression.S2Compression => JsonSerializer.SerializeToUtf8Bytes("s2"),
_ => throw new InvalidOperationException("unknown compression algorithm"),
};
public static void UnmarshalJSON(this ref StoreCompression alg, ReadOnlySpan<byte> b)
{
var parsed = JsonSerializer.Deserialize<string>(b);
if (parsed == null)
throw new InvalidDataException("compression value must be a JSON string");
alg = parsed switch
{
"none" => StoreCompression.NoCompression,
"s2" => StoreCompression.S2Compression,
_ => throw new InvalidOperationException("unknown compression algorithm"),
};
}
public static void UnmarshalJSON(this ref StoreCompression alg, byte[] b)
{
ArgumentNullException.ThrowIfNull(b);
UnmarshalJSON(ref alg, b.AsSpan());
}
}