ProtocolRequestBase IReceiveFilter <ProtocolRequestBase> .Filter(byte[] readBuffer, int offset, int length, bool toBeCopied, out int rest) { #if KCP rest = 0; session.pushData(readBuffer); // ProtocolRequestBase msg = new ProtocolRequestBase(); return(null); #else int readOffset = offset - m_OffsetDelta; //分割消息 int msgLength = (int)readBuffer[readOffset] << 8; msgLength += (int)readBuffer[readOffset + 1]; msgLength += 2; rest = length + m_ParsedLength - msgLength; if (rest < 0) { m_ParsedLength += length; m_OffsetDelta = m_ParsedLength; rest = 0; Debug.Log("不完整的消息 " + length + " msgLength " + msgLength); var expectedOffset = offset + length; var newOffset = m_OrigOffset + m_OffsetDelta; if (newOffset < expectedOffset) { Buffer.BlockCopy(readBuffer, offset - m_ParsedLength + length, readBuffer, m_OrigOffset, m_ParsedLength); } return(null); } try { ByteArray ba = new ByteArray(); for (int i = readOffset; i < readOffset + msgLength; i++) { ba.Add(readBuffer[i]); } InternalReset(); return(Analysis(ba)); } catch (Exception e) { Debug.LogError(e.ToString()); return(null); } #endif }