1
2
3
4
5
6
7
..
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
local m = dofile"lib/marshal.lua"
local car_t = m.g.struct {
brand = m.t.str;
year = m.t.u16;
}
local pack, unpack = m.transcoder {
version = m.t.u16;
................................................................................
cars = {
{brand = 'dodge', year = 2596};
{brand = 'subaru', year = 321};
};
}
if m.wrong(s) then print(s.exp) os.exit(1) end
local str = 'serialized:'
for i=1,#s do
str = str ..' '.. string.format("%x",string.byte(str, i))
end
print(str)
local v = unpack(s)
local function dump(o)
if type(o) == "table" then
local str = ''
for k,p in pairs(o) do
str = str .. (k .. ' = {' .. dump(p) ..'}\n')
end
return str
else
return tostring(o)
end
end
print(dump(v))
|
>
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
|
1
2
3
4
5
6
7
8
..
36
37
38
39
40
41
42
43
44
45
46
47
|
dofile'test/common.lua'
local m = dofile"lib/marshal.lua"
local car_t = m.g.struct {
brand = m.t.str;
year = m.t.u16;
}
local pack, unpack = m.transcoder {
version = m.t.u16;
................................................................................
cars = {
{brand = 'dodge', year = 2596};
{brand = 'subaru', year = 321};
};
}
if m.wrong(s) then print(s.exp) os.exit(1) end
print(hexdump(s))
local v = unpack(s)
print(dump(v))
|