Thrift在Lua中的示例

在 lua 中如何加载 Thrift 文件的示例在哪里可以找到?

到目前为止,我的代码如下。我无法弄清楚如何创建内存缓冲区。在 TMemoryBuffer:new() 处失败。

local fullpath = FullPath("ConfigData.bin")
local infile = io.open(fullpath, "rb")
local buffer = infile:read("*all")

local transport1 = TMemoryBuffer:new()
transport1:resetBuffer(buffer)
local transport = TFramedTransportFactory:getTransport(transport1) 
local protocol = TBinaryProtocolFactory:getProtocol(transport)
flux.assert(protocol)
Data:read(protocol)
点赞
用户2184601
用户2184601

下面是一个工作示例:

local fullpath = FullPath("ConfigData.bin")            // 获取完整路径
local infile = io.open(fullpath, "rb")                 // 打开二进制文件
local buffer = infile:read("*all")                     // 读取文件全部内容

TMemoryBuffer:resetBuffer(buffer)                      // 重置缓存
local protocol = TBinaryProtocolFactory:getProtocol(TMemoryBuffer)  // 获取协议
Data:read(protocol)                                   // 读取数据
2015-05-28 21:27:37