{"id":27169973,"url":"https://github.com/xiyoo0812/luapb","last_synced_at":"2026-04-28T11:01:55.845Z","repository":{"id":283268956,"uuid":"945427704","full_name":"xiyoo0812/luapb","owner":"xiyoo0812","description":"一个使用C++编写的面向lua的protobuf编码解码库！","archived":false,"fork":false,"pushed_at":"2025-09-05T06:18:52.000Z","size":78,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-05T08:25:57.208Z","etag":null,"topics":["cpp17","lua","protobuf"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xiyoo0812.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-09T11:58:18.000Z","updated_at":"2025-09-05T06:18:55.000Z","dependencies_parsed_at":"2025-04-08T02:34:26.692Z","dependency_job_id":"e94ccdef-beca-4cdd-8325-a9ebe9d9e24d","html_url":"https://github.com/xiyoo0812/luapb","commit_stats":null,"previous_names":["xiyoo0812/luapb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/xiyoo0812/luapb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Fluapb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Fluapb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Fluapb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Fluapb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xiyoo0812","download_url":"https://codeload.github.com/xiyoo0812/luapb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiyoo0812%2Fluapb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32377599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T09:24:15.638Z","status":"ssl_error","status_checked_at":"2026-04-28T09:24:15.071Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp17","lua","protobuf"],"created_at":"2025-04-09T07:18:49.201Z","updated_at":"2026-04-28T11:01:55.839Z","avatar_url":"https://github.com/xiyoo0812.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# luapb\n一个使用C++编写的面向lua的protobuf编码解码库！\n\n# 依赖\n- [lua](https://github.com/xiyoo0812/lua.git)5.3以上\n- [luakit](https://github.com/xiyoo0812/luakit.git)一个luabind库\n- 项目路径如下\u003cbr\u003e\n  |--proj \u003cbr\u003e\n  \u0026emsp;|--lua \u003cbr\u003e\n  \u0026emsp;|--luapb \u003cbr\u003e\n  \u0026emsp;|--luakit\n\n# 编译\n- msvc: 准备好lua依赖库并放到指定位置，将proj文件加到sln后编译。\n- linux: 准备好lua依赖库并放到指定位置，执行make -f luapb.mak\n\n# 其他\n- 仅支持lua5.3以上版本，proto3协议\n- 性能：lua-protobuf性能对比，测试不是很充分，仅做参考，release/O2编译\n  | 平台 | 库  | 编译选项 | 1W次编解码    | 10W次编解码 | 100W次编解码\n  |----------|-----------|-----------|-----------|--------|-----|\n  | Win11(vs2022)| luapb | -O2 | 75ms   | 752ms   | 7544msi\n  | Win11(vs2022)| lua-protobuf | -O2  | 163ms   | 1485ms   | 14744ms\n  | Debian11(GCC9)| luapb | -O2 | 85ms   | 840ms   | 8441ms\n  | Debian11(GCC9)| lua-protobuf | -O2  | 144ms   | 1466ms   | 14563ms\n\n# 用法\n\n```protobuf\n//protobuf定义\n\n// NCmdId\nenum NCmdId\n{\n    NID_QUANTA_ZERO                     = 0;\n    NID_HEARTBEAT_REQ                   = 1001;\n    NID_HEARTBEAT_RES                   = 1002;\n}\n\nmessage child_message\n{\n    uint32 id                       = 1;        // id\n    string name                     = 2;        // name\n    map\u003cstring, string\u003e values      = 3;\n}\n\nmessage test_message\n{\n    uint32 id                       = 1;        // id\n    child_message child             = 2;\n    repeated int32 custom2          = 3;\n    map\u003cstring, string\u003e custom      = 4;\n    repeated child_message childs   = 5;\n    map\u003cstring, child_message\u003e kvs  = 6;\n    oneof custom3 {\n        string str                  = 8;\n        int32 num                   = 9;\n    }\n}\n```\n```lua\nrequire(\"luapb\")\nlocal log_debug     = logger.debug\nlocal pb_enum_id    = protobuf.enum\nlocal pbdecode      = protobuf.decode\nlocal pbencode      = protobuf.encode\n\n--从文件加载protobuf二进制描述文件\nprotobuf.loadfile(\"xxx.pb\")\n\n--从字符串加载protobuf二进制描述文件\nlocal f = io.open(\"xxx.pb\", \"rb\")\nlocal data = f:read(\"*a\")\nprotobuf.load(data)\nf:close()\n\n--查询所有枚举\nfor _, name in pairs(protobuf.enums()) do\n    log_debug(\"enum: {}\", name)\nend\n\n--查询枚举值\nlocal enumval = pb_enum_id(\"ncmd_cs.NCmdID\", \"NID_HEARTBEAT_REQ\")\nlog_debug(\"enumval: {}\", enumval)\n\n--查询所有message信息\nfor full_name, name in pairs(protobuf.messages()) do\n    log_debug(\"message: {}=\u003e{}\", full_name, name)\nend\n\n--测试数据\nlocal tpb_data = {\n    id=1001014162,\n    child = {id=1, name=\"hot\", values = {one=\"xiluo\", two=\"wergins\"} },\n    childs = {\n        {id=2, name=\"laker\", values = {one=\"doncici\", two=\"james\"} },\n        {id=3, name=\"gsa\", values = {one=\"curry\", two=\"green\"} },\n    },\n    kvs = {\n        king = {id=4, name=\"king\", values = {one=\"drozan\", two=\"foxs\"} },\n        capper = {id=5, name=\"capper\", values = {one=\"harden\", two=\"lenarde\"} },\n    },\n    custom={role_id=\"107216333761938434\",name=\"aaa\", gender = \"2\", model = \"3\"},\n    custom2={1, 2, 3, 888, 666},\n    str= \"oneof str\",\n    num= 10,\n}\n\n--message编码解码\nlocal tpb_str = pbencode(\"ncmd_cs.test_message\", tpb_data)\nlog_debug(\"pb encode: {}\", #tpb_str)\nlocal tdata = pbdecode(\"ncmd_cs.test_message\", tpb_str)\nlog_debug(\"pb decode:{}\", tdata)\n\n--清理pb描述\nprotobuf.clear()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiyoo0812%2Fluapb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxiyoo0812%2Fluapb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiyoo0812%2Fluapb/lists"}