当前位置: 首页 > news >正文

刷存在感,Excel转Protobuf/Json通用配置文件

使用场景

最近工作流中有将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,idle
10002名称02false1apply:aa.ogg,walk:bb.oggrun,attack,idle

enmu

枚举的变量赋值必须从0开始,受限于protobuf的限制

#enmuRarityType
#desc罕见程度
#var#desc#value
Basic基础0
Common普通1
Rare稀有2
Epic史诗3
Legendary传说4
Fixed固定5

config

#config是加在#message上方的表示,后面表格的内容为当前的配置名称

#configcollect
#messageCollect
#typelist#Card
#varCardList
#desc列表

type

基本类型同protobuf的基本类型,比如int32、string等,list、map参考上方的message示例。如果是引用其他的类型结构,直接添加对应的类型名称即可, 具体的数据读取对应类型定义下方填写的数据,参考上方的config示例。

工具实现

https://github.com/coding2233/Excel2Config
需要安装.net6或者以上的环境,工具在windows下可以直接调用Excel2Config执行,linux/mac环境,可以调用dotnet Excel2Config.dll --help

Excel2Config–help
–helpShow this text.
–versionShow version info. 0.1.0.
–excel_path=The path to the excel file or folder.
–recursive,-RTraverse all the subfolders of the excel folder.
–output_path=Setting the output directory. If it is not set, it is the folder path of excel.
–to_jsonConvert to a json configuration file.
–to_protobuf=Convert to a protobuf configuration file. Input parameter proto
–protoc=Set the path to the protoc execution file.Environment variables are used by default protoc.
–shell=Set the path to the shell execution file.Environment variables are used by default sh.
–protoc_cmd=By default, the output file path of proto is set, and other protoc commands that need to be executed are added.

使用示例

Excel2Config --excel_path=Excel/ --to_json --to_protobuf=all --protoc_cmd="--csharp_out=Excel/" --shell="C:\\Program Files\\Git\\bin\\bash.exe" --protoc="D:\\protoc.exe"

Excel配置

请添加图片描述请添加图片描述请添加图片描述

导出文件

请添加图片描述请添加图片描述

夹带私货

  • 虽然支持json导出,但是还是推荐导出protobuf作为配置使用,json只是作为可视化参考
  • 有json可以利用其他工具转成,yaml等配置文件
  • 这里利用shell环境去调用protoc的命令,即使在windows下也需要设置shell环境,开发都安装了git-bash环境,所以这里的shell环境也不是啥大问题。windows下的路径确实有点恶心。

ToDo

  • 需要支持配置大文件的分割,并使用同一个结构脚本
http://www.lryc.cn/news/293752.html

相关文章:

  • docker 开放tcp连接供idea等其他外部工具开放使用
  • 虚拟机(VMware)ubuntu16.04 直接连接网口设备 USRP 吊舱
  • 告别繁杂的状态管理:Zustand 的简洁之道
  • CentOS磁盘扩容
  • 【数据分享】1929-2023年全球站点的逐日降雪深度数据(Shp\Excel\免费获取)
  • golang网络编程day4
  • 为什么pgsql(内关联查询或者with字句时)会导致索引失效
  • 小程序 自定义组件和生命周期
  • asp.net 404页面配置、 asp.net MVC 配置404页面、iis 配置404页面,指定404错误页面,设置404错误页面
  • Docker存储空间清理
  • React16源码: React中NewContext的源码实现
  • 【Linux】【Shell】常用压缩和解压缩命令(超详细)
  • 【Java程序设计】【C00232】基于Springboot的抗疫物资管理系统(有论文)
  • 2023年全球软件开发大会(QCon上海站2023):核心内容与学习收获(附大会核心PPT下载)
  • 【Linux】Ext2 文件系统
  • studyNote-linux-shell-find-examples
  • 使用 Python 进行自然语言处理第 3 部分:使用 Python 进行文本预处理
  • Python新春烟花盛宴
  • 【QT+QGIS跨平台编译】之二十:【xerces+Qt跨平台编译】(一套代码、一套框架,跨平台编译)
  • 18.通过telepresence调试部署在Kubernetes上的微服务
  • QT 范例阅读:系统托盘 The System Tray Icon example
  • OpenAI Gym 高级教程——深度强化学习库的高级用法
  • K8sGPT 会彻底改变你对 Kubernetes 的认知
  • 计组学习笔记2024/2/4
  • 25种Google的搜索技巧
  • 769933-15-5,Biotin aniline,可以合成多种有机化合物和聚合物
  • 回归预测 | Matlab实现POA-CNN-LSTM-Attention鹈鹕算法优化卷积长短期记忆网络注意力多变量回归预测(SE注意力机制)
  • B站视频在电商中的应用:如何利用item_get_video API提高转化率
  • 【Linux】统信服务器操作系统V20 1060a-AMD64 Vmware安装
  • c++类继承