mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-10-09 00:26:11 +00:00
提交新概念 Tile从服务器
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace Plugins.JNGame.Util
|
||||
{
|
||||
@@ -15,5 +18,25 @@ namespace Plugins.JNGame.Util
|
||||
BitConverter.GetBytes(value).CopyTo(result, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] ObjectToBytes<T>(T data)
|
||||
{
|
||||
var formatter = new BinaryFormatter();
|
||||
using var mStream = new MemoryStream();
|
||||
formatter.Serialize(mStream, data);
|
||||
mStream.Flush();
|
||||
return mStream.GetBuffer();
|
||||
}
|
||||
|
||||
public static T BytesToObject<T>(byte[] data)
|
||||
{
|
||||
var formatter = new BinaryFormatter();
|
||||
using var mStream = new MemoryStream();
|
||||
mStream.Write(data, 0, data.Length);
|
||||
mStream.Flush();
|
||||
mStream.Seek(0, SeekOrigin.Begin);
|
||||
return (T)formatter.Deserialize(mStream);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user