local skynet = require "skynet" local cjson = require "cjson" local logger = require "logger" local trace = logger.trace local cjson_decode = cjson.decode local cjson_encode = cjson.encode local Sproto = {} Sproto.encode = function (name, args, session) local list = { type = name, session = session, content = args or {} } local ret = cjson_encode(list) trace("======= encode =======:%s", ret) return ret end Sproto.decode = function(msg, sz) local str = nil if(sz) then str = skynet.tostring(msg, sz) -- skynet.trash(msg,sz) else str = msg end trace("======= decode =======:%s", str) local ret = cjson_decode(str) local list = {} local function fun(args) if args then list.type = ret.type.."_rsp" list.session = ret.session list.content = args end local temp = cjson_encode(list) trace("c2s args pace:%s", temp) return temp end -- if ret.session then return "REQUEST", ret.type, ret.content, fun -- else -- return "REQUEST", ret.type, ret.content, nil -- end end return Sproto