local function test_pack_tail_zero()
local pto = sprotoloader.load(1)
local function test(hs)
local s = hexstr2str(hs)
local p = pto.pack(s)
local up = pto.unpack(p)
log("test pack, s=%s p=%s up=%s", hexstr(s), hexstr(p), hexstr(up))
end
test("AB12")
test("AB120000")
test("AB12000000000000")
test("00")
test("000000000000000000")
end
[:0100000d] test pack, s=AB12 p=03AB12 up=AB12000000000000
[:0100000d] test pack, s=AB120000 p=03AB12 up=AB12000000000000
[:0100000d] test pack, s=AB12000000000000 p=03AB12 up=AB12000000000000
[:0100000d] test pack, s=00 p=00 up=0000000000000000
[:0100000d] test pack, s=000000000000000000 p=0000 up=00000000000000000000000000000000
查bug过程中抓包发现数据pack后再upack回来, 偶尔与原始数据不符的情况. 原因是pack算法中,未对结尾00做处理, unpack时强制补足00
结论:
Mark一下这个知识点,大家可能遇到. 可以直接close.