导入

protobuf.load(string)

读取编译完成后的protobuffer字符串

protobuf.loadfile(filename)

读取编译完成后的protobuffer文件

protobuf.encode(struct, table)

protobuf.decode(struct, string)

string按照字符串定义的格式进行反序列化.

protobuf.tohex(string)

string数据进行16进制格式打印.

protobuf.clear(struct)

清除struct定义的结构体.

使用进行编译protoc Person.pb -o Person.lua后得到文件Person.lua.

运行script/test_protobuf.lua中的示例代码查看效果:

输出结果: