mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交帧同步案例
This commit is contained in:
41
JNFrame/Assets/Plugins/JNGame/Network/Util/NDataUtil.cs
Normal file
41
JNFrame/Assets/Plugins/JNGame/Network/Util/NDataUtil.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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[] hId = ToUtil.IntToByte4(param.HId);
|
||||
byte[] id = ToUtil.IntToByte4(param.ID);
|
||||
byte[] data = Array.Empty<byte>();
|
||||
if(param.Data != null)
|
||||
data = param.Data.ToByteArray();
|
||||
|
||||
return id.Concat(hId).Concat(data).ToArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b05544adb2f44b4af8f86b2bc66a035
|
||||
timeCreated: 1706004790
|
Reference in New Issue
Block a user