12 def walk_counters(s, pathset):
15 r2 = {'name': e.name, 'elements': e.block}
32 d.append({'enumtype': e.enumtype})
40 d = {'reply': e.reply}
44 d['stream_msg'] = e.stream_message
46 d['events'] = e.events
51 def walk_defs(s, is_message=False):
57 if b.type == 'Option':
61 d.append([b.fieldtype, b.fieldname, b.limit])
63 d.append([b.fieldtype, b.fieldname])
64 elif b.type == 'Array':
66 d.append([b.fieldtype, b.fieldname,
67 b.length, b.lengthfield])
69 d.append([b.fieldtype, b.fieldname, b.length])
70 elif b.type == 'Union':
73 raise ValueError("Error in processing array type %s" % b)
75 if is_message and t.crc:
77 c['crc'] = "{0:#0{1}x}".format(t.crc, 10)
87 def run(args, filename, s):
90 j['types'] = (walk_defs([o for o in s['types']
91 if o.__class__.__name__ == 'Typedef']))
92 j['messages'] = walk_defs(s['Define'], True)
93 j['unions'] = (walk_defs([o for o in s['types']
94 if o.__class__.__name__ == 'Union']))
95 j['enums'] = (walk_enums([o for o in s['types']
96 if o.__class__.__name__ == 'Enum']))
97 j['services'] = walk_services(s['Service'])
98 j['options'] = s['Option']
99 j['aliases'] = {o.name:o.alias for o in s['types'] if o.__class__.__name__ == 'Using'}
100 j['vl_api_version'] = hex(s['file_crc'])
101 j['imports'] = walk_imports(i for i in s['Import'])
102 j['counters'], j['paths'] = walk_counters(s['Counters'], s['Paths'])
103 return json.dumps(j, indent=4, separators=(',', ': '))