You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
2.4 KiB

using System;
using System.IO;
namespace ProtoCSStruct
{
/// <summary>
/// 本工具的作用是根据proto协议描述(有修改,增加了stringlength,repeatedcount这2个限定项)生成c#结构体消息数据
/// 目的是为了协议解包打包提高效率,官方的protobuf库解包,打包会生成大量对象,对游戏服务器来说,随着承载量的提高,
/// 消息包数量过大将会频繁的触发gc,造成严重的STW(stop the world)问题,虽然每次0代gc比较快,但几个服务器累积起来将会
/// 严重的拖慢消息包处理速度,玩家直接的感受就是网络卡,服务器响应慢
/// </summary>
class Program
{
static void Main(string[] args)
{
try
{
InputParams ip = new InputParams();
ip.Parse(args);
//测试模式
if (ip.TestOnly)
{
ProtoCSStructTest.TestMain.Run();
Console.Read();
return;
}
foreach (var pathfile in ip.ProtoFiles)
{
string filename = Path.GetFileName(pathfile);
string filewithoutext = Path.GetFileNameWithoutExtension(pathfile);
string outfilename = filewithoutext + "_struct.cs";
string enumOutFileName = filewithoutext + "_enum.cs";
string classOutFileName = filewithoutext + "_class.cs";
ProtoFileParser fileParse = new ProtoFileParser();
ProtoDescriptor pd = fileParse.Parse(pathfile, ip.NameSpace, ip.CSharpOutDir
, ip.CSharpOutDir + "/" + outfilename
, ip.CSharpOutDir + "/" + enumOutFileName
, ip.CSharpOutDir + "/" + classOutFileName
, ip.GenClassConfig);
}
CSharpStructWriter writer = new CSharpStructWriter();
writer.WriteCSStructFile();
}
catch (ProtoParseException ex)
{
//解析错误
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
//运行错误
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}
}