2023-05-24 17:51:17 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2023-05-24 17:51:17 +08:00
|
|
|
|
public static byte[] Serizlize(IMessage msg)
|
2021-12-10 23:38:40 +08:00
|
|
|
|
{
|
2023-05-24 17:51:17 +08:00
|
|
|
|
return msg.ToByteArray();
|
2021-12-10 23:38:40 +08:00
|
|
|
|
}
|
2023-05-24 17:51:17 +08:00
|
|
|
|
|
|
|
|
|
public static T DeSerizlize<T>(byte[] bytes)
|
2021-12-10 23:38:40 +08:00
|
|
|
|
{
|
2023-05-24 17:51:17 +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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|