| 40 | } |
| 41 | |
| 42 | void ToLua::SendProtocol(Socket* socket) |
| 43 | { |
| 44 | if (!Lua.IsTable(-1)) |
| 45 | throw std::exception("SendProtocol param is not a table."); |
| 46 | |
| 47 | Lua.GetField(-1, "ModuleId"); |
| 48 | int ModuleId = (int)Lua.ToInteger(-1); |
| 49 | Lua.Pop(1); |
| 50 | Lua.GetField(-1, "ProtocolId"); |
| 51 | int ProtocolId = (int)Lua.ToInteger(-1); |
| 52 | Lua.Pop(1); |
| 53 | |
| 54 | Lua.GetField(-1, "ResultCode"); |
| 55 | long long resultCode = Lua.ToInteger(-1); |
| 56 | Lua.Pop(1); |
| 57 | |
| 58 | long long typeId = (long long)ModuleId << 32 | (unsigned int)ProtocolId; |
| 59 | ProtocolMetasMap::iterator pit = ProtocolMetas.find(typeId); |
| 60 | if (pit == ProtocolMetas.end()) |
| 61 | throw std::exception("protocol not found in meta for typeid=" + typeId); |
| 62 | |
| 63 | if (pit->second.IsRpc) |
| 64 | { |
| 65 | Lua.GetField(-1, "IsRequest"); |
| 66 | bool isRequest = Lua.ToBoolean(-1); |
| 67 | Lua.Pop(1); |
| 68 | Lua.GetField(-1, "Sid"); |
| 69 | long long sid = Lua.ToInteger(-1); |
| 70 | Lua.Pop(1); |
| 71 | Lua.GetField(-1, "Timeout"); |
| 72 | int timeout = (int)Lua.ToInteger(-1); |
| 73 | Lua.Pop(1); |
| 74 | |
| 75 | long long argumentBeanTypeId = 0; |
| 76 | const char* argumentName = NULL; |
| 77 | |
| 78 | if (isRequest) |
| 79 | { |
| 80 | argumentBeanTypeId = pit->second.ArgumentBeanTypeId; |
| 81 | argumentName = "Argument"; |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | argumentBeanTypeId = pit->second.ResultBeanTypeId; |
| 86 | argumentName = "Result"; |
| 87 | } |
| 88 | |
| 89 | // see Rpc.Encode |
| 90 | Zeze::ByteBuffer bb(1024); |
| 91 | bb.WriteInt4(ModuleId); |
| 92 | bb.WriteInt4(ProtocolId); |
| 93 | int outstate = bb.BeginWriteWithSize4(); |
| 94 | bb.WriteBool(isRequest); |
| 95 | bb.WriteLong(sid); |
| 96 | bb.WriteLong(resultCode); |
| 97 | Lua.GetField(-1, argumentName); |
| 98 | EncodeBean(bb, argumentBeanTypeId); |
| 99 | Lua.Pop(1); |
no test coverage detected