forked from cloudwu/sproto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lua
66 lines (57 loc) · 1.01 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
local sproto = require "sproto"
local core = require "sproto.core"
local print_r = require "print_r"
local sp = sproto.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
}
]]
-- core.dumpproto only for debug use
core.dumpproto(sp.__cobj)
local def = sp:default "Person"
print("default table for Person")
print_r(def)
print("--------------")
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 = sp:encode("AddressBook", ab)
local addr = sp:decode("AddressBook", code)
print_r(addr)