mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
feat: store shard status in Redis
This commit is contained in:
parent
22faa47d00
commit
0419ced0d2
18 changed files with 602 additions and 183 deletions
22
PluralKit.Core/Utils/ProtobufUtils.cs
Normal file
22
PluralKit.Core/Utils/ProtobufUtils.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using Google.Protobuf;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public static class Proto
|
||||
{
|
||||
private static Dictionary<string, MessageParser> _parser = new();
|
||||
|
||||
public static byte[] Marshal(this IMessage message) => message.ToByteArray();
|
||||
|
||||
public static T Unmarshal<T>(this byte[] message) where T : IMessage<T>, new()
|
||||
{
|
||||
var type = typeof(T).ToString();
|
||||
if (_parser.ContainsKey(type))
|
||||
return (T)_parser[type].ParseFrom(message);
|
||||
else
|
||||
{
|
||||
_parser.Add(type, new MessageParser<T>(() => new T()));
|
||||
return Unmarshal<T>(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue