|
@@ -21,10 +21,11 @@ namespace ProtoDataBuff
|
|
|
[Serializable]
|
|
|
public struct sSocketData
|
|
|
{
|
|
|
- public byte[] _data;
|
|
|
+ public Int32 PackLen;
|
|
|
+ public UInt32 TS;
|
|
|
public eProtocalCommand _protocallType;
|
|
|
- public int _buffLength;
|
|
|
- public int _dataLength;
|
|
|
+ public byte[] _data;
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 网络结构转数据
|
|
|
/// </summary>
|
|
@@ -32,17 +33,18 @@ namespace ProtoDataBuff
|
|
|
/// <returns></returns>
|
|
|
public byte[] ToBytes()
|
|
|
{
|
|
|
- byte[] _tmpBuff = new byte[_buffLength];
|
|
|
- byte[] _tmpBuffLength = BitConverter.GetBytes(_buffLength);
|
|
|
+ byte[] _tmpBuff = new byte[PackLen];
|
|
|
+ byte[] _tmpBuffLength = BitConverter.GetBytes(PackLen);
|
|
|
byte[] _tmpDataType = BitConverter.GetBytes((UInt16)_protocallType);
|
|
|
|
|
|
Array.Copy(_tmpBuffLength, 0, _tmpBuff, 0, Constants.HEAD_DATA_LEN);//缓存总长度
|
|
|
Array.Copy(_tmpDataType, 0, _tmpBuff, Constants.HEAD_DATA_LEN, Constants.HEAD_TYPE_LEN);//协议类型
|
|
|
- Array.Copy(_data, 0, _tmpBuff, Constants.HEAD_LEN, _dataLength);//协议数据
|
|
|
+ Array.Copy(_data, 0, _tmpBuff, Constants.HEAD_LEN, DataLen());//协议数据
|
|
|
|
|
|
return _tmpBuff;
|
|
|
}
|
|
|
|
|
|
+ public int DataLen() => _data.Length;
|
|
|
/// <summary>
|
|
|
/// 数据转网络结构
|
|
|
/// </summary>
|
|
@@ -52,8 +54,8 @@ namespace ProtoDataBuff
|
|
|
public static sSocketData FromBytes(eProtocalCommand _protocalType, byte[] _data)
|
|
|
{
|
|
|
sSocketData tmpSocketData = new();
|
|
|
- tmpSocketData._buffLength = Constants.HEAD_LEN + _data.Length;
|
|
|
- tmpSocketData._dataLength = _data.Length;
|
|
|
+ tmpSocketData.PackLen = Constants.HEAD_LEN + _data.Length;
|
|
|
+ // tmpSocketData._dataLength = _data.Length;
|
|
|
tmpSocketData._protocallType = _protocalType;
|
|
|
tmpSocketData._data = _data;
|
|
|
return tmpSocketData;
|
|
@@ -148,8 +150,8 @@ namespace ProtoDataBuff
|
|
|
|
|
|
if (_buffLength > 0 && _curBuffPosition >= _buffLength)
|
|
|
{
|
|
|
- _tmpSocketData._buffLength = _buffLength;
|
|
|
- _tmpSocketData._dataLength = _dataLength;
|
|
|
+ _tmpSocketData.PackLen = _buffLength;
|
|
|
+ //_tmpSocketData._dataLength = _dataLength;
|
|
|
_tmpSocketData._protocallType = (eProtocalCommand)_protocalType;
|
|
|
_tmpSocketData._data = new byte[_dataLength];
|
|
|
Array.Copy(_buff, Constants.HEAD_LEN, _tmpSocketData._data, 0, _dataLength);
|