Lua中的节俭示例

时间:2015-05-28 10:21:26

标签: lua thrift

在哪里可以找到如何在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)

1 个答案:

答案 0 :(得分:0)

这是一个有效的例子:

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)