forked from Thriftpy/thriftpy2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddressbook.py
173 lines (138 loc) · 4.13 KB
/
addressbook.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# -*- coding: utf-8 -*-
"""This file is a demo for what the dynamically generated code would be like.
"""
from thriftpy2.thrift import (
TPayload,
TException,
TType,
)
from container import MixItem
DEFAULT_LIST_SIZE = 10
class PhoneType(object):
MOBILE = 0
HOME = 1
WORK = 2
class PhoneNumber(TPayload):
thrift_spec = {
1: (TType.I32, "type", PhoneType, False),
2: (TType.STRING, "number", False),
3: (TType.STRUCT, "mix_item", MixItem, False),
}
default_spec = [("type", None), ("number", None), ("mix_item", None)]
class Person(TPayload):
thrift_spec = {
1: (TType.STRING, "name", False),
2: (TType.LIST, "phones", (TType.STRUCT, PhoneNumber)),
4: (TType.I32, "created_at", False),
}
default_spec = [("name", None), ("phones", None), ("created_at", None)]
class AddressBook(TPayload):
thrift_spec = {
1: (TType.MAP, "people",
(TType.STRING, (TType.STRUCT, Person)))
}
default_spec = [("people", None)]
class PersonNotExistsError(TException):
thrift_spec = {
1: (TType.STRING, "message", False)
}
default_spec = [("message", None)]
class AddressBookService(object):
thrift_services = [
"ping",
"hello",
"add",
"remove",
"get",
"book",
"get_phonenumbers",
"get_phones",
"sleep",
]
class ping_args(TPayload):
thrift_spec = {}
default_spec = []
class ping_result(TPayload):
thrift_spec = {}
default_spec = []
class hello_args(TPayload):
thrift_spec = {
1: (TType.STRING, "name"),
}
default_spec = [("name", None)]
class hello_result(TPayload):
thrift_spec = {
0: (TType.STRING, "success"),
}
default_spec = [("success", None)]
class add_args(TPayload):
thrift_spec = {
1: (TType.STRUCT, "person", Person),
}
default_spec = [("person", None)]
class add_result(TPayload):
thrift_spec = {
0: (TType.BOOL, "success"),
}
default_spec = [("success", None)]
class remove_args(TPayload):
thrift_spec = {
1: (TType.STRING, "name"),
}
default_spec = [("name", None)]
class remove_result(TPayload):
thrift_spec = {
0: (TType.BOOL, "success"),
1: (TType.STRUCT, "not_exists", PersonNotExistsError)
}
default_spec = [("success", None), ("not_exists", None)]
class get_args(TPayload):
thrift_spec = {
1: (TType.STRING, "name"),
}
default_spec = [("name", None)]
class get_result(TPayload):
thrift_spec = {
0: (TType.STRUCT, "success", Person),
1: (TType.STRUCT, "not_exists", PersonNotExistsError)
}
default_spec = [("success", None), ("not_exists", None)]
class book_args(TPayload):
thrift_spec = {}
default_spec = []
class book_result(TPayload):
thrift_spec = {
0: (TType.STRUCT, "success", AddressBook),
}
default_spec = [("success", None)]
class get_phonenumbers_args(TPayload):
thrift_spec = {
1: (TType.STRING, "name"),
2: (TType.I32, "count"),
}
default_spec = [("name", None), ("count", None)]
class get_phonenumbers_result(TPayload):
thrift_spec = {
0: (TType.LIST, "success", (TType.STRUCT)),
}
default_spec = [("success", None)]
class get_phones_args(TPayload):
thrift_spec = {
1: (TType.STRING, "name"),
}
default_spec = [("name", None)]
class get_phones_result(TPayload):
thrift_spec = {
0: (TType.MAP, "success", (TType.I32, TType.STRING)),
}
default_spec = [("success", None)]
class sleep_args(TPayload):
thrift_spec = {
1: (TType.I16, "ms"),
}
default_spec = []
class sleep_result(TPayload):
thrift_spec = {
0: (TType.BOOL, "success"),
}
default_spec = [("success", None)]