public ApolloMessage UnpackResponseData(byte[] data, int realSize) { TalkerHead talkerHead = new TalkerHead(); int num = 0; TdrError.ErrorType errorType = talkerHead.unpackTLV(ref data, realSize, ref num); if (errorType != TdrError.ErrorType.TDR_NO_ERROR) { ADebug.LogError("UnpackResponseData head.unpack error:" + errorType); return(null); } TalkerCommand.CommandDomain bDomain = (TalkerCommand.CommandDomain)talkerHead.bDomain; TalkerCommand talkerCommand = null; CMD_FMT bCmdFmt = (CMD_FMT)talkerHead.bCmdFmt; if (bCmdFmt == CMD_FMT.CMD_FMT_INT) { if (talkerHead.stCommand != null) { talkerCommand = new TalkerCommand(bDomain, (uint)talkerHead.stCommand.iIntCmd); } } else if (bCmdFmt == CMD_FMT.CMD_FMT_NIL) { talkerCommand = new TalkerCommand(bDomain, TalkerCommand.CommandValueType.Raw); } else if (talkerHead.stCommand != null && talkerHead.stCommand.szStrCmd != null) { int num2 = 0; for (int i = 0; i < talkerHead.stCommand.szStrCmd.Length; i++) { num2 = i; if (talkerHead.stCommand.szStrCmd[i] == 0) { break; } } string @string = Encoding.get_UTF8().GetString(talkerHead.stCommand.szStrCmd, 0, num2); talkerCommand = new TalkerCommand(bDomain, @string); } if (talkerCommand == null) { ADebug.LogError("With command is null"); return(null); } ApolloMessage apolloMessage = null; TalkerMessageType messageType = ApolloMessage.GetMessageType((int)talkerHead.bFlag); if (messageType == TalkerMessageType.Response) { if (ApolloMessageManager.Instance.SeqMessageCollection.ContainsKey(talkerHead.dwAsync)) { apolloMessage = ApolloMessageManager.Instance.SeqMessageCollection[talkerHead.dwAsync]; } if (apolloMessage != null) { apolloMessage.AsyncFlag = talkerHead.dwAsync; if (apolloMessage.IsRequest && talkerHead.dwAsync != apolloMessage.SeqNum) { if (talkerHead.dwAsync != apolloMessage.SeqNum) { ADebug.Log(string.Format("UnpackResponseData error: if(head.dwSeqNum({0}) != seqNum({1})", talkerHead.dwAsync, apolloMessage.SeqNum)); } else { ADebug.Log(string.Concat(new object[] { "UnpackResponseData error compare result:", talkerCommand.Equals(apolloMessage.Command), " msg.command:", apolloMessage.Command, " cmd:", talkerCommand })); } return(null); } } } else { apolloMessage = this.Get(talkerCommand); if (apolloMessage != null) { ADebug.Log(string.Concat(new object[] { "cmd:", talkerCommand, " msg receipt handler:", apolloMessage.HandlerWithReceipt != null, " without receipt handler:", apolloMessage.HandlerWithoutReceipt != null })); } } if (apolloMessage == null) { ADebug.LogError(string.Concat(new object[] { "UnpackResponseData error: msg == null while seq:", talkerHead.dwAsync, " cmd:", talkerCommand, " type:", ApolloMessage.GetMessageType((int)talkerHead.bFlag) })); return(null); } ADebug.Log(string.Concat(new object[] { "UnpackResponseData msg.Command:", apolloMessage.Command, " type:", ApolloMessage.GetMessageType((int)talkerHead.bFlag) })); if (realSize < num) { ADebug.LogError(string.Format("realSize{0} < usedSize({1})", realSize, num)); return(null); } byte[] array = new byte[realSize - num]; Array.Copy(data, num, array, 0, array.Length); if (apolloMessage.RespType != null) { apolloMessage.Response = (Activator.CreateInstance(apolloMessage.RespType) as IUnpackable); if (apolloMessage.Response != null) { errorType = apolloMessage.Response.unpackTLV(ref array, array.Length, ref num); if (errorType != TdrError.ErrorType.TDR_NO_ERROR) { ADebug.Log("UnpackResponseData resp.unpack error:" + errorType); return(null); } return(apolloMessage); } } else { apolloMessage.RawData = array; } return(apolloMessage); }
public ApolloMessage UnpackResponseData(byte[] data, int realSize) { int num2; TalkerHead head = new TalkerHead(); int used = 0; TdrError.ErrorType type = head.unpackTLV(ref data, realSize, ref used); if (type != TdrError.ErrorType.TDR_NO_ERROR) { ADebug.LogError("UnpackResponseData head.unpack error:" + type); return(null); } TalkerCommand.CommandDomain bDomain = (TalkerCommand.CommandDomain)head.bDomain; TalkerCommand command = null; switch (((CMD_FMT)head.bCmdFmt)) { case CMD_FMT.CMD_FMT_INT: if (head.stCommand != null) { command = new TalkerCommand(bDomain, (uint)head.stCommand.iIntCmd); } goto Label_0103; case CMD_FMT.CMD_FMT_NIL: command = new TalkerCommand(bDomain, TalkerCommand.CommandValueType.Raw); goto Label_0103; default: if ((head.stCommand == null) || (head.stCommand.szStrCmd == null)) { goto Label_0103; } num2 = 0; for (int i = 0; i < head.stCommand.szStrCmd.Length; i++) { num2 = i; if (head.stCommand.szStrCmd[i] == 0) { break; } } break; } string str = Encoding.UTF8.GetString(head.stCommand.szStrCmd, 0, num2); command = new TalkerCommand(bDomain, str); Label_0103: if (command == null) { ADebug.LogError("With command is null"); return(null); } ApolloMessage message = null; if (ApolloMessage.GetMessageType(head.bFlag) == TalkerMessageType.Response) { if (Instance.SeqMessageCollection.ContainsKey(head.dwAsync)) { message = Instance.SeqMessageCollection[head.dwAsync]; } if (message != null) { message.AsyncFlag = head.dwAsync; if (message.IsRequest && (head.dwAsync != message.SeqNum)) { if (head.dwAsync != message.SeqNum) { ADebug.Log(string.Format("UnpackResponseData error: if(head.dwSeqNum({0}) != seqNum({1})", head.dwAsync, message.SeqNum)); } else { ADebug.Log(string.Concat(new object[] { "UnpackResponseData error compare result:", command.Equals(message.Command), " msg.command:", message.Command, " cmd:", command })); } return(null); } } } else { message = this.Get(command); if (message != null) { ADebug.Log(string.Concat(new object[] { "cmd:", command, " msg receipt handler:", message.HandlerWithReceipt != null, " without receipt handler:", message.HandlerWithoutReceipt != null })); } } if (message == null) { ADebug.LogError(string.Concat(new object[] { "UnpackResponseData error: msg == null while seq:", head.dwAsync, " cmd:", command, " type:", ApolloMessage.GetMessageType(head.bFlag) })); return(null); } ADebug.Log(string.Concat(new object[] { "UnpackResponseData msg.Command:", message.Command, " type:", ApolloMessage.GetMessageType(head.bFlag) })); if (realSize < used) { ADebug.LogError(string.Format("realSize{0} < usedSize({1})", realSize, used)); return(null); } byte[] destinationArray = new byte[realSize - used]; Array.Copy(data, used, destinationArray, 0, destinationArray.Length); if (message.RespType != null) { message.Response = Activator.CreateInstance(message.RespType) as IUnpackable; if (message.Response != null) { type = message.Response.unpackTLV(ref destinationArray, destinationArray.Length, ref used); if (type != TdrError.ErrorType.TDR_NO_ERROR) { ADebug.Log("UnpackResponseData resp.unpack error:" + type); return(null); } } return(message); } message.RawData = destinationArray; return(message); }