HaoYueNet/Simple/SimpleClient/Network/NetBase.cs

34 lines
792 B
C#
Raw Normal View History

2021-12-10 23:38:40 +08:00
using ProtoBuf;
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<T>(T MsgObj)
{
using (MemoryStream ms = new MemoryStream())
{
Serializer.Serialize<T>(ms, MsgObj);
byte[] data1 = ms.ToArray();
return data1;
}
}
//反序列化
public static T DeSerizlize<T>(byte[] MsgObj)
{
using (MemoryStream ms = new MemoryStream(MsgObj))
{
var ds_obj = Serializer.Deserialize<T>(ms);
return ds_obj;
}
}
}
}