# FastProtocolBufForLua **Repository Path**: liyonghelpme/FastProtocolBufForLua ## Basic Information - **Project Name**: FastProtocolBufForLua - **Description**: 高性能Lua pb 编码 解码库 - **Primary Language**: Lua - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 2 - **Created**: 2016-11-19 - **Last Updated**: 2023-04-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #FastProtocolBufForLua 支持protobuf 2 版本 高性能的 Lua Protocl buffers 解析 编码 库 专为游戏打造 通过python 脚本 生成Lua代码 Lua程序中通过引入该库实现 对 protocol buffers 的处理 #使用样例 使用python 2.7 和 lua 5.1 python GenLuaPB.py ``` --解析 local f = io.open("test3.bin", "rb") local t = f:read("*all") local msg = {} SetIndex(msg, Person) msg:Parse(CreateBuffer(t)) DumpPB(msg) --编码 序列化 local buf = msg:Serialize() local ret = buf:Finish() local f1 = io.open("out3.bin", "wb") f1:write(ret) f1:close() ``` lua test1.lua #benchmark 对照库地址: https://git.oschina.net/liyonghelpme/protoc_gen_lua.git 10万次 编码 和解析 与 protoc-gen-lua 比较 解码 test3.bin: 本库 1.65s pgl库 2.67s 编码: 本库 1.94s pgl库:2.38s #文件结构 pb.c lua扩展 用于实现varint的encode 和 decode Makefile 编译pb.c GenLuaPB.py 生成协议 对应的 lua文件 Buffer.lua pb 解析和生成的 基础缓冲区 test.proto test1.proto 用于测试的协议 Person.lua Phone.lua 测试协议生成的 对应的pb解析lua文件 #使用方法 书写 proto 文件 使用GenLuaPB.py 生成 协议lua文件 模仿test.lua test1.lua 中的方式 使用生成的Lua文件 对协议进行解析 和 序列化 #proto 文件格式要求 每个字段一行 不支持字段中括号配置 不支持枚举变量 不支持message 嵌套定义 #不支持 不支持 [packed=true] pb version 3