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) { return 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) { return parser.ParseFrom(data.ToArray()); } } public static class GuidExtension { public static ByteString ToByteString(this Guid id) { return ByteString.CopyFrom(id.ToByteArray()); } public static Guid FromByteString(this ByteString id) { return new Guid(id.ToByteArray()); } } }