forked from cloudwu/sproto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
62 lines (54 loc) · 943 Bytes
/
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
local parser = require "sprotoparser"
local core = require "sproto.core"
local print_r = require "print_r"
local sp = parser.parse [[
.Person {
name 0 : string
id 1 : integer
email 2 : string
.PhoneNumber {
number 0 : string
type 1 : integer
}
phone 3 : *PhoneNumber
}
.AddressBook {
person 0 : *Person(id)
others 1 : *Person
}
]]
sp = core.newproto(sp)
core.dumpproto(sp)
local st = core.querytype(sp, "AddressBook")
local ab = {
person = {
[10000] = {
name = "Alice",
id = 10000,
phone = {
{ number = "123456789" , type = 1 },
{ number = "87654321" , type = 2 },
}
},
[20000] = {
name = "Bob",
id = 20000,
phone = {
{ number = "01234567890" , type = 3 },
}
}
},
others = {
{
name = "Carol",
id = 30000,
phone = {
{ number = "9876543210" },
}
},
}
}
collectgarbage "stop"
local code = core.encode(st, ab)
local addr = core.decode(st, code)
print_r(addr)