# GenProtoMap **Repository Path**: night-tc/genprotomap ## Basic Information - **Project Name**: GenProtoMap - **Description**: genprotomap 是一个用于生成 proto 消息号映射文件的工具,支持生成 Golang 和 Lua 两种版本的映射文件。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-05-17 - **Last Updated**: 2025-12-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # genprotomap 工具 ## 简介 `genprotomap` 是一个用于生成 `proto` 消息号映射文件的工具,支持生成 Golang 和 Lua 两种版本的映射文件。 ## 功能 1. **解析 `.proto` 文件**:从指定目录中读取 `.proto` 文件并解析消息定义。 2. **生成 Golang 映射文件**:根据解析结果生成包含消息号的 Golang 文件。 3. **生成 Lua 映射文件**:根据解析结果生成包含消息号的 Lua 文件。 ## 使用方法 ### 参数说明 工具通过命令行参数接收输入,参数定义如下: | 参数名 | 类型 | 说明 | 默认值 | |----------|--------|--------------------------------|-----------------------| | `dir` | string | `.proto` 文件所在目录 | `./bin/protofile` | | `gofile` | string | 输出 Golang 映射文件路径 | 空字符串(不生成) | | `luafile`| string | 输出 Lua 映射文件路径 | 空字符串(不生成) | ### 示例 1. **生成 Golang 和 Lua 映射文件** ```bash ./genprotomap -dir=./protofiles -gofile=./output/proto_map.go -luafile=./output/proto_map.lua ``` - `-dir` 指定 `.proto` 文件所在目录。 - `-gofile` 指定生成的 Golang 映射文件路径。 - `-luafile` 指定生成的 Lua 映射文件路径。 2. **仅生成 Golang 映射文件** ```bash ./genprotomap -dir=./protofiles -gofile=./output/proto_map.go ``` 3. **仅生成 Lua 映射文件** ```bash ./genprotomap -dir=./protofiles -luafile=./output/proto_map.lua ``` ## 输出文件格式 ### Golang 映射文件 生成的 Golang 文件包含以下内容: - 消息号常量定义。 - 消息类型注册逻辑。 示例: ```go // Code generated by genprotomap.exe. DO NOT EDIT. package example import ( msgdef "gitee.com/night-tc/gobige/msgdef" ) type MsgIDEnum = uint16 const ( ExampleMsgID MsgIDEnum = 1 // 示例消息 ) func init() { msgdef.GetTypeMgr().RegisterType("ExampleMsg", ExampleMsgID, &ExampleMsg{}) } ``` ### Lua 映射文件 生成的 Lua 文件包含以下内容: - 消息号枚举定义。 示例: ```lua ---@enum (partial) ProtoID local ProtoID = { NONE = 0, ---示例消息 ExampleMsg = 1, } return ProtoID ``` ## 注意事项 1. 确保 `.proto` 文件格式正确,且包含消息定义。 2. 如果指定的输出目录不存在,工具会自动创建。 3. 需要安装 `goimports`(用于格式化 Golang 文件)和 `luafmt`(可选,用于格式化 Lua 文件)。