1 Star 0 Fork 46

qiuchangjie / moba协议

forked from liyonghelpme / moba协议 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
GenUtilFile.py 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
liyonghelpme 提交于 2016-07-09 22:41 . init commit
#coding:utf8
#生成每个Message 对应的GetMsg 的代码
UtilTemplate = '''
using UnityEngine;
using System.Collections.Generic;
using Google.ProtocolBuffers;
namespace MyLib {
public partial class Util {
public delegate IMessageLite MsgDelegate(ByteString buf);
%s
static Dictionary<string, MsgDelegate> msgMap = new Dictionary<string, MsgDelegate>(){
%s
};
public static IMessageLite GetMsg(int moduleId, int messageId, ByteString buf) {
//var module = SaveGame.saveGame.getModuleName(moduleId);
var msg = SaveGame.saveGame.getMethodName(moduleId, messageId);
Debug.LogWarning ("modulename "+moduleId+" "+messageId+" msg "+msg);
return msgMap[msg](buf);
}
}
}
'''
delegateTemplate = '''
static IMessageLite Get%s(ByteString buf) {
var retMsg = MyLib.%s.ParseFrom(buf);
return retMsg;
}
'''
initTemplate = '''
{"%s", Get%s},
'''
'''
msgList = [msgName, msgName]
'''
def GenUtil(msgList):
funcList = ''
initList = ''
for m in msgList:
#print 'gen module', m
for s in m:
if s != 'id':
funcList += delegateTemplate % (s, s)
initList += initTemplate % (s, s)
#print funcList
#print initList
ret = UtilTemplate % (funcList.encode('utf8'), initList.encode('utf8'))
print 'write Util2.cs '
temp = chr(0xef)+chr(0xbb)+chr(0xbf)+ret
f = open('Util2.cs', 'w')
f.write(temp)
f.close()
1
https://gitee.com/qiuchangjie/mobaXieYi.git
git@gitee.com:qiuchangjie/mobaXieYi.git
qiuchangjie
mobaXieYi
moba协议
moba

搜索帮助