using MessagePack; using MessagePack.Formatters; namespace GameCult.Caching; // An unset reference (the empty key) is "" on the wire in every position, map keys included (other runtimes refuse nil // map keys), and default(CultRecordRef) in memory. Nil, written by 1.0.58 stores, reads as unset and saves as "". public sealed class CultRecordRefFormatter : IMessagePackFormatter> { public void Serialize(ref MessagePackWriter writer, CultRecordRef value, MessagePackSerializerOptions options) => writer.Write(value.Key.Value); public CultRecordRef Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { var key = reader.TryReadNil() ? null : reader.ReadString(); return string.IsNullOrEmpty(key) ? default : new CultRecordRef(new CultRecordKey(key!)); } }