forked from cloudwu/sproto
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtestall.lua
54 lines (46 loc) · 780 Bytes
/
testall.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
local parser = require "sprotoparser"
local core = require "sproto.core"
local print_r = require "print_r"
local sp = parser.parse [[
.foobar {
.nest {
a 1 : string
b 3 : boolean
c 5 : integer
}
a 0 : string
b 1 : integer
c 2 : boolean
d 3 : nest
e 4 : *string
f 5 : *integer
g 6 : *boolean
h 7 : *foobar
}
]]
sp = core.newproto(sp)
core.dumpproto(sp)
local st = core.querytype(sp, "foobar")
local obj = {
a = "hello",
b = 1000000,
c = true,
d = {
a = "world",
-- skip b
c = -1,
},
e = { "ABC", "def" },
f = { -3, -2, -1, 0 , 1, 2},
g = { true, false, true },
h = {
{ b = 100 },
{},
{ b = -100, c= false },
{ b = 0, e = { "test" } },
},
}
local code = core.encode(st, obj)
parser.dump(code)
obj = core.decode(st, code)
print_r(obj)