-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.lua
executable file
·77 lines (73 loc) · 2.06 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local protobuf = require('protobuf')
local function contains(t1, t2)
for k, v in pairs(t1) do
if type(v) == 'table' then
if type(t2[k]) == 'table' then
if not contains(v, t2[k]) then
return false
end
else
return false
end
elseif v ~= t2[k] then
return false
end
end
return true
end
local input = {
dbl = 3.0,
rdbl = {3.0, 5.0},
mdbl = {[42] = 3.0},
flt = 3.0,
rflt = {3.0, 5.0},
mflt = {[42] = 3.0},
int = -2147483648,
rint = {2147483647, -2147483648},
mint = {[2147483647] = -2147483648},
sint = 2147483647,
rsint = {2147483647, -2147483648},
msint = {[2147483647] = -2147483648},
sfint = 0,
rsfint = {2147483647, -2147483648},
msfint = {[2147483647] = -2147483648},
long = -9223372036854775808,
rlong = {9223372036854775807, -9223372036854775808},
mlong = {[9223372036854775807] = -9223372036854775808},
slong = 9223372036854775807,
rslong = {9223372036854775807, -9223372036854775808},
mslong = {[9223372036854775807] = -9223372036854775808},
sflong = 0,
rsflong = {9223372036854775807, -9223372036854775808},
msflong = {[9223372036854775807] = -9223372036854775808},
uint = 4294967295,
ruint = {0, 4294967295},
muint = {[0] = 4294967295},
ufint = 0,
rufint = {0, 4294967295},
mufint = {[0] = 4294967295},
ulong = 9223372036854775807,
rulong = {0, 9223372036854775807},
mulong = {[0] = 9223372036854775807},
uflong = 0,
ruflong = {0, 9223372036854775807},
muflong = {[0] = 9223372036854775807},
str = 'a',
rstr = {'a', 'b'},
mstr = {['a'] = 'b'},
bin = 'x',
rbin = {'x', 'y'},
mbin = {[1] = 'y'},
enm = 'B',
renm = {'A', 'C', 'B'},
menm = {[3] = 'C', [4] = 'B', [5] = 'A'},
--enm = 1,
--renm = {0, 2, 1},
--menm = {[3] = 2, [4] = 1, [5] = 0},
nst = {val = 42},
rnst = {{val = 42}, {val = 43}},
mnst = {[5] = {val = 42}, [7] = {val = 43}}
}
local binary = protobuf.encode('test.Test', input)
local output = protobuf.decode('test.Test', binary)
print(contains(input, output) and contains(output, input) and 'SUCCESS' or 'FAILURE')