NoSugarNet/NoSugarNet.ClientCore/Common/ProtoBufHelper.cs
2024-01-19 21:35:05 +08:00

21 lines
476 B
C#

using Google.Protobuf;
namespace NoSugarNet.ClientCore.Common
{
public static class ProtoBufHelper
{
public static byte[] Serizlize(IMessage msg)
{
return msg.ToByteArray();
}
public static T DeSerizlize<T>(byte[] bytes)
{
var msgType = typeof(T);
object msg = Activator.CreateInstance(msgType);
((IMessage)msg).MergeFrom(bytes);
return (T)msg;
}
}
}