VPPAPIGEN: Add union and enum support and IP4/IP6 address type.
[vpp.git] / src / tools / vppapigen / JSON.py
index d1f47eb..2991bec 100644 (file)
@@ -15,14 +15,14 @@ def walk_enums(s):
 
 
 def walk_services(s):
-    r = []
+    r = {}
     for e in s:
         d = {'reply': e.reply}
         if e.stream:
             d['stream'] = True
         if e.events:
             d['events'] = e.events
-        r.append({e.caller: d})
+        r[e.caller] = d
     return r
 
 
@@ -40,6 +40,8 @@ def walk_defs(s):
                     f = [b.fieldtype, b.fieldname, b.length, b.lengthfield]
                 else:
                     f = [b.fieldtype, b.fieldname, b.length]
+            elif b.type == 'Union':
+                print('UNION')
             else:
                 raise ValueError("Error in processing array type %s" % b)
             d.append(f)
@@ -58,9 +60,10 @@ def walk_defs(s):
 def run(filename, s, file_crc):
     j = {}
 
-    j['types'] = walk_defs(s['typedefs'])
-    j['messages'] = walk_defs(s['defines'])
-    j['enums'] = walk_enums(s['enums'])
-    j['services'] = walk_services(s['services'])
+    j['types'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Typedef'])
+    j['messages'] = walk_defs(s['Define'])
+    j['unions'] = walk_defs([o for o in s['types'] if o.__class__.__name__ == 'Union'])
+    j['enums'] = walk_enums([o for o in s['types'] if o.__class__.__name__ == 'Enum'])
+    j['services'] = walk_services(s['Service'])
     j['vl_api_version'] = hex(file_crc)
     return json.dumps(j, indent=4, separators=(',', ': '))