public virtual IMessage Decode(byte[] bytes) { header.Clear(); header.Decode(bytes, 0); switch (header.GetMessageType()) { case MessageType.Keyboard: keyboard.Clear(); keyboard.Decode(bytes, 0); return(keyboard); case MessageType.Rocker: rocker.Clear(); rocker.Decode(bytes, 0); return(rocker); case MessageType.Gyro: gyro.Clear(); gyro.Decode(bytes, 0); return(gyro); } return(null); }
/// <summary> /// 内部解析 /// </summary> private void OnKcpRead(KChannel channel, byte[] bytes) { //处理连接 if (!this.IsConnected) { //兼容1.3.1旧版本时,改用SimulationRecvConnected //OnConnectedSuccess(); } else { //解析数据 header.Clear(); header.Decode(bytes, 0); if (header.GetMessageType() != MessageType.Msg) { int ts = (SystemTime.LowClientNow() - header.TimeStamp) / 2; Log.Debug("当前延迟:" + ts); if (ts < 0) { ts = 10; } timeStampList.Add((uint)ts); } OnReadEventHandler?.Invoke(bytes); } }