using MessagePack;
using MessagePack.Formatters;
namespace GameCult.Caching;
///
/// Serializes typed CultCache record references as their persisted key strings.
///
public sealed class CultRecordRefFormatter : IMessagePackFormatter>
{
///
/// Writes a typed record reference to MessagePack.
///
public void Serialize(ref MessagePackWriter writer, CultRecordRef value, MessagePackSerializerOptions options)
{
options.Resolver.GetFormatterWithVerify().Serialize(ref writer, value.Key.Value, options);
}
///
/// Reads a typed record reference from MessagePack.
///
public CultRecordRef Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
var key = options.Resolver.GetFormatterWithVerify().Deserialize(ref reader, options) ?? string.Empty;
return new CultRecordRef(new CultRecordKey(key));
}
}