44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
|
using System.IO;
|
||
|
using NetworkFramework.Shared;
|
||
|
|
||
|
namespace CLre_server.API.Synergy
|
||
|
{
|
||
|
public struct SerializedCLreMessage: ISerializedNetData
|
||
|
{
|
||
|
public uint Id;
|
||
|
public byte[] Data;
|
||
|
|
||
|
public byte[] Serialize()
|
||
|
{
|
||
|
using (MemoryStream stream = new MemoryStream())
|
||
|
{
|
||
|
using (BinaryWriter writer = new BinaryWriter(stream))
|
||
|
{
|
||
|
writer.Write(Id);
|
||
|
writer.Write(Data.Length);
|
||
|
foreach (byte b in Data)
|
||
|
{
|
||
|
writer.Write(b);
|
||
|
}
|
||
|
return stream.ToArray();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Deserialize(byte[] data)
|
||
|
{
|
||
|
using (MemoryStream stream = new MemoryStream(data))
|
||
|
{
|
||
|
using (BinaryReader reader = new BinaryReader(stream))
|
||
|
{
|
||
|
Id = reader.ReadUInt32();
|
||
|
Data = new byte[reader.ReadInt32()];
|
||
|
for (int i = 0; i < Data.Length; i++)
|
||
|
{
|
||
|
Data[i] = reader.ReadByte();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|