Sproto CSharp集成步骤

云风sproto:https://github.com/cloudwu/sproto
周边工具:https://github.com/cloudwu/sproto/wiki
lvzixun的CSharp版本实现:https://github.com/lvzixun/sproto-Csharp

1:proto文件

只支持string,integer,boolen这三种基本类型。具体格式参见云风git

2:proto文件生成对应C#代码

需要使用工具:sprotodump(https://github.com/lvzixun/sprotodump)
相关命令为:

usage: lua sprotodump.lua <option> <sproto_file1 sproto_file2 ...> [[<out_option> <outfile>] ...] [namespace_option]

    option: 
        -cs              dump to cSharp code file
        -spb             dump to binary spb  file
        -go              dump to go code file
        -md              dump to markdown file
        
    out_option:
        -d <dircetory>               dump to speciffic dircetory
        -o <file>                    dump to speciffic file
        -p <package name>            set package name(only cSharp code use)

    namespace_option:
        -namespace       add namespace to type and protocol

为了能编译sprotodump lua代码,我这边下载了SciTE作为lua的IDE环境来执行lua程序:https://github.com/rjpcomputing/luaforwindows/releases

安装最新版本后,cmd中输入lua,弹出如下内容,即说明IDE环境安装成功
Sproto CSharp集成步骤
若cmd输入lua报错没有该命令,则说明系统环境变量没有添加lua目录。可以手动加入。
Sproto CSharp集成步骤

这样我们cd到sprotodump的目录下,输入命令即可导出C#代码。
为了方便我们还可以整个批处理文件,更加方便快捷。

补充

上述sprotodump我的lua5.1环境下会报错:nesting of [[…]] is deprecated near ‘[’
解决方法为:sprotodump.lua文件中README=[[XXXXXX]],中间加上=号
Sproto CSharp集成步骤
参考文档:https://yq.aliyun.com/ziliao/513897