Search code examples
luathrift

Thrift Example in Lua


Where can I find an example of how to load a Thrift file in lua?

My code so far is below. I can't figure out how to create memory buffer. It fails at 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)

Solution

  • Here is a working example:

    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)