OC-misc/partition/partition.lua

24 lines
444 B
Lua

local partition = {}
local eformat = "c20c4>I4>I4"
function partition.parse(s)
local rt = {}
for i = 1, s:len(), 32 do
local n, t, start, length = string.unpack(eformat, s, i)
n = n:gsub("\0", "")
if n ~= "" then
rt[#rt+1] = {n,t,start,length}
end
end
return rt
end
function partition.generate(pt)
local ps = ""
for k,v in ipairs(pt) do
ps = ps .. string.pack(eformat, table.unpack(v))
end
return ps
end
return partition