lua用pbc解析protobuf 不支持message嵌套

问题:

protobuf.encode解析后的table 嵌套的message未解析
eg:
1
2
3
4
5
6
7
table = {
id: 2,
message = {
1: "proto.test", --message名
2: "**********", --二进制文件
}
}

解决办法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
local function checkTable( tab )
for k,v in pairs(tab) do
if type(v) == "table" then
if table.len(v) == 2 and v[1] ~= nil and v[2] ~= nil then
tab[k] = fullDecode(v[1],v[2])
else
tab[k] = checkTable(v)
end
end
end
return tab
end

function fullDecode(typename,buffer)
local tab = protobuf.decode(typename,buffer)
checkTable(tab)
return tab
end

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!