山东省建设执业资格注册管理中心网站,网站建设期任务及总结,百度推广自己做网站吗,安装网站出现dir使用场景
最近工作流中有将Excel转Protobuf作为配置文件的技术方案。具体实现是先定一个proto文件#xff0c;再在一个对应excel表中定义对应字段#xff0c;由策划在excel进行更改。proto文件可以生成对应语言的脚本#xff0c;然后将excel转成对应protobuf的binary。
我…使用场景
最近工作流中有将Excel转Protobuf作为配置文件的技术方案。具体实现是先定一个proto文件再在一个对应excel表中定义对应字段由策划在excel进行更改。proto文件可以生成对应语言的脚本然后将excel转成对应protobuf的binary。
我的想法就是优化掉自定义proto文件的步骤根据约束在excel中定义数据类型在导出数据前自动导出对应的proto文件以及生成对应的脚本文件。
Excel定义约束
Excel已定义的关键词以下的所有的配置都可以放在任何sheet里面
关键词描述#message同protobuf message#enum同protobuf enum#package同protobuf package#config标识当前message导出为config#desc描述/注释#type数据类型, 基本同Protobuf类型有自定义#var变量名称#value枚举的变量
message
基本的Message结构如下,RarityType参考下方的枚举定义,支持map和list,list同protobuf repeated
#messageCard#typeint32stringboolRarityTypemap#string:string#sep,list#string#sep,#varidnamehideraitysoundsanimations#desc唯一标识名称隐藏罕见程度音效动画10001名称01false2apply:aa.ogg,walk:bb.oggrun,attack,idle10002名称02false1apply:aa.ogg,walk:bb.oggrun,attack,idle
enmu
枚举的变量赋值必须从0开始,受限于protobuf的限制
#enmuRarityType#desc罕见程度#var#desc#valueBasic基础0Common普通1Rare稀有2Epic史诗3Legendary传说4Fixed固定5
config
#config是加在#message上方的表示后面表格的内容为当前的配置名称
#configcollect#messageCollect#typelist#Card#varCardList#desc列表
type
基本类型同protobuf的基本类型比如int32、string等list、map参考上方的message示例。如果是引用其他的类型结构直接添加对应的类型名称即可 具体的数据读取对应类型定义下方填写的数据参考上方的config示例。
工具实现
都需要安装.net6或者以上的环境工具在windows下可以直接调用Excel2Config执行linux/mac环境可以调用dotnet Excel2Config.dll --help
Excel2Config–help–helpShow this text.–versionShow version info. 0.1.0.–excel_pathThe path to the excel file or folder.–recursive,-RTraverse all the subfolders of the excel folder.–output_pathSetting the output directory. If it is not set, it is the folder path of excel.–to_jsonConvert to a json configuration file.–to_protobufConvert to a protobuf configuration file. Input parameter proto–protocSet the path to the protoc execution file.Environment variables are used by default protoc.–shellSet the path to the shell execution file.Environment variables are used by default sh.–protoc_cmdBy default, the output file path of proto is set, and other protoc commands that need to be executed are added.
使用示例
Excel2Config --excel_pathExcel/ --to_json --to_protobufall --protoc_cmd--csharp_outExcel/ --shellC:\\Program Files\\Git\\bin\\bash.exe --protocD:\\protoc.exeExcel配置 导出文件 夹带私货
虽然支持json导出但是还是推荐导出protobuf作为配置使用json只是作为可视化参考有json可以利用其他工具转成,yaml等配置文件这里利用shell环境去调用protoc的命令即使在windows下也需要设置shell环境,开发都安装了git-bash环境所以这里的shell环境也不是啥大问题。windows下的路径确实有点恶心。
ToDo
需要支持配置大文件的分割并使用同一个结构脚本