using MessagePack;
using MessagePack.Formatters;
namespace MariesWonderland.MasterMemory;
///
/// MessagePack resolver used exclusively to deserialize the binary database header
/// (Dictionary<string, (int, int)> mapping table names to data offsets).
///
internal sealed class HeaderFormatterResolver : IFormatterResolver
{
public static readonly IFormatterResolver Instance = new HeaderFormatterResolver();
/// Pre-configured options using this resolver (no compression for header).
public static readonly MessagePackSerializerOptions StandardOptions =
MessagePackSerializerOptions.Standard.WithResolver(Instance);
private HeaderFormatterResolver() { }
///
public IMessagePackFormatter? GetFormatter()
{
if (typeof(T) == typeof(Dictionary))
return (IMessagePackFormatter)(object)new DictionaryFormatter();
if (typeof(T) == typeof(string))
return (IMessagePackFormatter)(object)NullableStringFormatter.Instance;
if (typeof(T) == typeof((int, int)))
return (IMessagePackFormatter)(object)new IntIntValueTupleFormatter();
if (typeof(T) == typeof(int))
return (IMessagePackFormatter)(object)Int32Formatter.Instance;
return null;
}
}