UNPKG

mydog

Version:

a framework of typescript game server

32 lines (31 loc) 914 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default_encodeDecode = exports.init = void 0; let app; function init(_app) { app = _app; } exports.init = init; exports.default_encodeDecode = { "protoDecode": function (data) { return { "cmd": data.readUInt16BE(1), "msg": data.slice(3) }; }, "msgDecode": function (cmd, msg) { return JSON.parse(msg.toString()); }, "protoEncode": function (cmd, msg) { let msgBuf = app.msgEncode(cmd, msg); let buf = Buffer.allocUnsafe(msgBuf.length + 7); buf.writeUInt32BE(msgBuf.length + 3, 0); buf.writeUInt8(1 /* define.Server_To_Client.msg */, 4); buf.writeUInt16BE(cmd, 5); msgBuf.copy(buf, 7); return buf; }, "msgEncode": function (cmd, msg) { return Buffer.from(JSON.stringify(msg)); } };