private void HandleRPCMessage(RPCMessage rpcmsg) { Debuger.Log("Connection[{0}]-> {1}({2})", m_conn.id, rpcmsg.name, rpcmsg.args); var helper = GetMethodHelper(rpcmsg.name); if (helper != null) { object[] args = rpcmsg.args; var raw_args = rpcmsg.raw_args; var paramInfo = helper.method.GetParameters(); if (raw_args.Count == paramInfo.Length) { for (int i = 0; i < raw_args.Count; i++) { if (raw_args[i].type == RPCArgType.PBObject) { m_RecvBuff.DecodeProtoMsg(raw_args[i].raw_value, null, paramInfo[i].ParameterType); } else { args[i] = raw_args[i].value; } } m_currInvokingName = rpcmsg.name; try { helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null); } catch (Exception e) { Debuger.LogError("RPC调用出错:{0}\n{1}", e.Message, e.StackTrace); } m_currInvokingName = null; } else { Debuger.LogWarning("参数数量不一致!"); } } else { Debuger.LogWarning("RPC不存在!"); } }
private void HandleRPCMessage(ISession session, RPCMessage rpcmsg) { RPCMethodHelper helper = GetMethodHelper(rpcmsg.name); if (helper != null) { object[] args = new object[rpcmsg.raw_args.Count + 1]; var raw_args = rpcmsg.raw_args; var paramInfo = helper.method.GetParameters(); args[0] = session; if (args.Length == paramInfo.Length) { for (int i = 0; i < raw_args.Count; i++) { if (raw_args[i].type == RPCArgType.PBObject) { args[i + 1] = m_RecvBuff.DecodeProtoMsg(raw_args[i].raw_value, null, paramInfo[i + 1].ParameterType); } else { args[i + 1] = raw_args[i].value; } } m_currInvokingName = rpcmsg.name; m_currInvokingSession = session; try { helper.method.Invoke(helper.listener, BindingFlags.NonPublic, null, args, null); } catch (Exception e) { Debuger.LogError("RPC调用出错:{0}\n{1}", e.Message, e.StackTrace); } m_currInvokingName = null; m_currInvokingSession = null; } else { Debuger.LogWarning("参数数量不一致!"); } } else { Debuger.LogWarning("RPC不存在!"); } }
public static void ToObject <T>(byte[] bytes, T obj) { lock (DefaultReader) { DefaultReader.Reset(); DefaultReader._Write(bytes, 0, (uint)bytes.Length); DefaultReader.DecodeProtoMsg(obj); } }