You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
namespace EntrustSettle.EventBus
|
|
|
|
|
{
|
|
|
|
|
public class Protobuf
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Protobuf 反序列化
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static T Deserialize<T>(ReadOnlySpan<byte> data)
|
|
|
|
|
{
|
|
|
|
|
Stream stream = new MemoryStream(data.ToArray());
|
|
|
|
|
var info = ProtoBuf.Serializer.Deserialize<T>(stream);
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过Protobuf 转字节
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static byte[] Serialize<T>(T data)
|
|
|
|
|
{
|
|
|
|
|
byte[] datas;
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
ProtoBuf.Serializer.Serialize(stream, data);
|
|
|
|
|
datas = stream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
return datas;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|