-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFD.py
More file actions
executable file
·80 lines (66 loc) · 1.92 KB
/
FD.py
File metadata and controls
executable file
·80 lines (66 loc) · 1.92 KB
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
#!/usr/bin/python
# vim:tw=120
from google.protobuf.descriptor import FieldDescriptor
global type_map, label_map
type_map={}
label_map={}
## @file FD.py
# build dictionaries with value:name pairs for constants in a field object.
## @var type_map
# 1 : 'DOUBLE',
# 2 : 'FLOAT',
# 3 : 'INT64',
# 4 : 'UINT64',
# 5 : 'INT32',
# 6 : 'FIXED64',
# 7 : 'FIXED32',
# 8 : 'BOOL',
# 9 : 'STRING',
# 10 : 'GROUP',
# 11 : 'MESSAGE',
# 12 : 'BYTES',
# 13 : 'UINT32',
# 14 : 'ENUM',
# 15 : 'SFIXED32',
# 16 : 'SFIXED64',
# 17 : 'SINT32',
# 18 : 'SINT64'
## @var label_map
# 1 : 'OPTIONAL',
# 2 : 'REQUIRED',
# 3 : 'REPEATED'
## create the mappings.
def create_value_map(object,prefix):
M={}
types = [(getattr(object,m),m[len(prefix):]) for m in dir(object) \
if not callable(getattr(object,m)) and m.startswith(prefix)]
for key,value in types:
M[key]=value
globals()[value]=key
return M
def init():
global type_map, label_map
type_map=create_value_map(FieldDescriptor,"TYPE_")
label_map=create_value_map(FieldDescriptor,"LABEL_")
## @page FD_interactive FD interactive session using idle, the python ide.
#<pre>
#>>> import FD
#>>> FD.init()
#>>> dir(FD)
#['BOOL', 'BYTES', 'DOUBLE', 'ENUM', 'FIXED32', 'FIXED64', 'FLOAT', 'FieldDescriptor', 'GROUP', 'INT32', 'INT64',
#'MESSAGE', 'OPTIONAL', 'REPEATED', 'REQUIRED', 'SFIXED32', 'SFIXED64', 'SINT32', 'SINT64', 'STRING', 'UINT32', 'UINT64',
#'__builtins__', '__doc__', '__file__', '__name__', '__package__', 'create_value_map', 'init', 'label_map', 'type_map']
#>>> FD.BOOL
#8
#>>> FD.type_map
#{1: 'DOUBLE', 2: 'FLOAT', 3: 'INT64', 4: 'UINT64', 5: 'INT32', 6: 'FIXED64', 7: 'FIXED32', 8: 'BOOL', 9: 'STRING', 10:
#'GROUP', 11: 'MESSAGE', 12: 'BYTES', 13: 'UINT32', 14: 'ENUM', 15: 'SFIXED32', 16: 'SFIXED64', 17: 'SINT32', 18:
#'SINT64'}
#>>> FD.REPEATED
#3
#
#</pre>
if __name__ == '__main__':
init()
print "type_map", type_map
print "label_map", label_map