MCPcopy Create free account
hub / github.com/e2wugui/zeze / DecodeAndDispatch

Method DecodeAndDispatch

cxx/ToLua.cpp:229–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

227 }
228
229 bool ToLua::DecodeAndDispatch(Service* service, long long sessionId, int moduleId, int protocolId, Zeze::ByteBuffer& _os_)
230 {
231 if (Lua.GetGlobal("ZezeDispatchProtocol") != LuaHelper::LuaType::Function) // push func onto stack
232 {
233 Lua.Pop(1);
234 return false;
235 }
236 // 现在不支持 Rpc.但是代码没有检查。
237 // 生成的时候报错。
238 Lua.CreateTable(0, 16);
239
240 Lua.PushString("Service");
241 Lua.PushObject(service);
242 Lua.SetTable(-3);
243
244 Lua.PushString("SessionId");
245 Lua.PushInteger(sessionId);
246 Lua.SetTable(-3);
247
248 Lua.PushString("ModuleId");
249 Lua.PushInteger(moduleId);
250 Lua.SetTable(-3);
251
252 Lua.PushString("ProtcolId");
253 Lua.PushInteger(protocolId);
254 Lua.SetTable(-3);
255
256 long long typeId = (long long)moduleId << 32 | (unsigned int)protocolId;
257 Lua.PushString("TypeId");
258 Lua.PushInteger(typeId);
259 Lua.SetTable(-3);
260
261 ProtocolMetasMap::iterator pit = ProtocolMetas.find(typeId);
262 if (pit == ProtocolMetas.end())
263 throw std::exception("protocol not found in meta for typeid=" + typeId);
264
265 if (pit->second.IsRpc)
266 {
267 bool IsRequest = _os_.ReadBool();
268 long long sid = _os_.ReadLong();
269 long long resultCode = _os_.ReadLong();
270 long long argumentBeanTypeId;
271 const char* argument;
272 if (IsRequest)
273 {
274 argumentBeanTypeId = pit->second.ArgumentBeanTypeId;
275 argument = "Argument";
276 }
277 else
278 {
279 argumentBeanTypeId = pit->second.ResultBeanTypeId;
280 argument = "Result";
281 }
282 Lua.PushString("IsRpc");
283 Lua.PushBoolean(true);
284 Lua.SetTable(-3);
285 Lua.PushString("IsRequest");
286 Lua.PushBoolean(IsRequest);

Callers 1

DecodeProtocolMethod · 0.45

Calls 15

GetGlobalMethod · 0.80
PopMethod · 0.80
PushStringMethod · 0.80
PushObjectMethod · 0.80
SetTableMethod · 0.80
PushIntegerMethod · 0.80
PushBooleanMethod · 0.80
IsNilMethod · 0.80
ToBooleanMethod · 0.80
findMethod · 0.65
ReadBoolMethod · 0.65
ReadLongMethod · 0.65

Tested by

no test coverage detected