HaoYueNet/Simple/SimpleClient/Network/NetBase.cs

27 lines
570 B
C#
Raw Normal View History

using Google.Protobuf;
2021-12-10 23:38:40 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleClient
{
public static class NetBase
{
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
}
}
}