mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
using System;
|
|||
|
using System.Linq;
|
|||
|
using System.Reflection;
|
|||
|
using Google.Protobuf;
|
|||
|
using Plugins.JNGame.Network.Entity;
|
|||
|
using Plugins.JNGame.Util;
|
|||
|
|
|||
|
namespace Plugins.JNGame.Network.Util
|
|||
|
{
|
|||
|
// 网络数据工具类 [请求Id*4,处理Id*4,...参数数据*N]
|
|||
|
public static class NDataUtil
|
|||
|
{
|
|||
|
|
|||
|
// 解析
|
|||
|
public static JNetParam Parse(byte[] data)
|
|||
|
{
|
|||
|
|
|||
|
return JNetParam.Build(
|
|||
|
ToUtil.Byte4ToInt(data.Skip(0).Take(4).ToArray()),
|
|||
|
ToUtil.Byte4ToInt(data.Skip(4).Take(4).ToArray()))
|
|||
|
.SetByte(data.Skip(8).Take(data.Length - 8).ToArray());
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
// 编码
|
|||
|
public static byte[] Encrypt(JNetParam param)
|
|||
|
{
|
|||
|
|
|||
|
byte[] id = ToUtil.IntToByte4(param.ID);
|
|||
|
byte[] hId = ToUtil.IntToByte4(param.HId);
|
|||
|
byte[] data = Array.Empty<byte>();
|
|||
|
if(param.Data != null)
|
|||
|
data = param.Data.ToByteArray();
|
|||
|
|
|||
|
byte[] datas = new byte[hId.Length+id.Length+data.Length];
|
|||
|
Array.Copy(id, 0, datas, 0, id.Length);
|
|||
|
Array.Copy(hId, 0, datas, id.Length, hId.Length);
|
|||
|
Array.Copy(data, 0, datas, id.Length + hId.Length, data.Length);
|
|||
|
return datas;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|