using System; using System.IO; namespace EntrustSettle.EventBus { public class Protobuf { /// /// Protobuf 反序列化 /// public static T Deserialize(ReadOnlySpan data) { Stream stream = new MemoryStream(data.ToArray()); var info = ProtoBuf.Serializer.Deserialize(stream); return info; } /// /// 通过Protobuf 转字节 /// public static byte[] Serialize(T data) { byte[] datas; using (var stream = new MemoryStream()) { ProtoBuf.Serializer.Serialize(stream, data); datas = stream.ToArray(); } return datas; } } }