中文使用说明:https://zhuanlan.zhihu.com/p/26014103
This project offers a simple C library for basic protobuf wire format encode/decode, it splits to several modules:
- pb.decoder: a wire format decode module.
- pb.buffer: a buffer implement that use to encode basic types into protobuf's wire format. It also can be used to support streaming decode protobuf data.
- pb.conv: a module to convert between integers in protobuf.
- pb.io: a module to support binary mode read/write to stdin/stdout.
It also has a high level Lua module to direct decode protobuf data to Lua table, or encode Lua table to protobuf data. It uses pb_typeinfo.lua to understand protobuf's compiled descriptor file format.
To support new protobuf type, you can use pb.load()/pb.loadfile() to load a compiled protobuf schema file, generated by Google protobuf's protoc compiler. You can also directly load a DescriptorProto message with pb.loadproto().
To reuse the loaded stuff, you can use pb.dump() to save loaded data to a file. It's just a regular Lua module. After require() it, use pb.merge() to include it into protobuf type database.
The detailed documentations are work-in-progress. But use it is very simple, just try pb.decode(data, type) function or pb.encode(buff, type).