HaoYueNet/Simple/ClientCore/Common/ProtoBufHelper.cs

21 lines
465 B
C#
Raw Normal View History

using Google.Protobuf;
2021-12-10 23:38:40 +08:00
2023-05-25 18:04:01 +08:00
namespace ClientCore.Common
2021-12-10 23:38:40 +08:00
{
2023-05-25 18:04:01 +08:00
public static class ProtoBufHelper
2021-12-10 23:38:40 +08:00
{
public static byte[] Serizlize(IMessage msg)
2021-12-10 23:38:40 +08:00
{
return msg.ToByteArray();
2021-12-10 23:38:40 +08:00
}
public static T DeSerizlize<T>(byte[] bytes)
2021-12-10 23:38:40 +08:00
{
var msgType = typeof(T);
object msg = Activator.CreateInstance(msgType);
((IMessage)msg).MergeFrom(bytes);
return (T)msg;
2021-12-10 23:38:40 +08:00
}
}
}