using System; using System.Text.Json; namespace StellaOps.Scanner.EntryTrace; internal static class EntryTraceCacheSerializer { public const string CurrentVersion = "entrytrace.v1"; public static byte[] Serialize(EntryTraceCacheEnvelope envelope) { if (envelope is null) { throw new ArgumentNullException(nameof(envelope)); } return JsonSerializer.SerializeToUtf8Bytes(envelope); } public static EntryTraceCacheEnvelope Deserialize(byte[] payload) { if (payload is null || payload.Length == 0) { throw new ArgumentException("Payload cannot be empty.", nameof(payload)); } var envelope = JsonSerializer.Deserialize(payload); if (envelope is null) { throw new InvalidOperationException("Failed to deserialize entry trace cache envelope."); } return envelope; } }