public virtual bool ProcessPacket(byte[] buffer, int offset, int count) //处理分完包后的数据,把命令和数据分开,并对命令进行解析 { if (count < sizeof(int)) { return(false); } int commandLen = BitConverter.ToInt32(buffer, offset); //取出命令长度 string tmpStr = Encoding.UTF8.GetString(buffer, offset + sizeof(int), commandLen); if (!m_incomingDataParser.DecodeProtocolText(tmpStr)) //解析命令 { return(false); } return(ProcessCommand(buffer, offset + sizeof(int) + commandLen, count - sizeof(int) - commandLen)); //处理命令 }
//处理分包后的数据,对命令和数据分开,并对数据进行解析 public virtual bool ProcessPacket(byte[] buffer, int offset, int count) { if (count < sizeof(int)) { return(false); } int commandLength = BitConverter.ToInt32(buffer, offset); string commandStr = Encoding.UTF8.GetString(buffer, offset + sizeof(int), commandLength); //解析命令 if (!m_incomingDataParser.DecodeProtocolText(commandStr)) { return(false); } return(ProcessCommand(buffer, offset + sizeof(int) + commandLength, count - sizeof(int) - commandLength)); }
/// <summary> /// 处理分完包后的数据,把命令和数据分开,并对命令进行解析 /// </summary> /// <param name="buffer"></param> /// <param name="offset"></param> /// <param name="count"></param> /// <returns></returns> public virtual bool ProcessPacket(byte[] buffer, int offset, int count) { if (count < sizeof(int)) { return(false); } int commandLen = BitConverter.ToInt32(buffer, offset); //取出命令长度 //分包完成后,把内存数组是UTF-8编码转换为Unicode,即为C#的string,后续的处理就都可以基于string进行处理,比较方便 string tmpStr = Encoding.UTF8.GetString(buffer, offset + sizeof(int), commandLen); bool blnDecode = m_incomingDataParser.DecodeProtocolText(tmpStr); if (!blnDecode) //解析命令 { return(false); } //处理命令,针对不同的命令进行处理 return(ProcessCommand(buffer, offset + sizeof(int) + commandLen, count - sizeof(int) - commandLen)); }