using System; using Confluent.Kafka; using Google.Protobuf; namespace ASC.Common.Caching { public class ProtobufSerializer : ISerializer where T : IMessage, new() { public byte[] Serialize(T data, SerializationContext context) => data.ToByteArray(); } public class ProtobufDeserializer : IDeserializer where T : IMessage, new() { private readonly MessageParser parser; public ProtobufDeserializer() { parser = new MessageParser(() => new T()); } public T Deserialize(ReadOnlySpan data, bool isNull, SerializationContext context) => parser.ParseFrom(data.ToArray()); } }