NoSugarNet/NoSugarNet.ClientCore.Standard2/Common/ProtoBufHelper.cs

22 lines
490 B
C#
Raw Normal View History

2024-04-15 15:16:10 +08:00
using Google.Protobuf;
using System;
2024-10-18 16:47:32 +08:00
namespace NoSugarNet.ClientCore.Common
2024-04-15 15:16:10 +08:00
{
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;
}
}
}