using Google.Protobuf; namespace PluralKit.Core; public static class Proto { private static Dictionary _parser = new(); public static byte[] Marshal(this IMessage message) => message.ToByteArray(); public static T Unmarshal(this byte[] message) where T : IMessage, new() { var type = typeof(T).ToString(); if (_parser.ContainsKey(type)) return (T)_parser[type].ParseFrom(message); else { _parser.Add(type, new MessageParser(() => new T())); return Unmarshal(message); } } }