api: split vl_api_prefix into two
[vpp.git] / src / tools / vppapigen / vppapigen_json.py
index a4707c0..f67a3d6 100644 (file)
@@ -26,17 +26,23 @@ def walk_services(s):
     return r
 
 
-def walk_defs(s):
+def walk_defs(s, is_message=False):
     r = []
     for t in s:
         d = []
         d.append(t.name)
         for b in t.block:
+            if b.type == 'Option':
+                continue
             if b.type == 'Field':
-                d.append([b.fieldtype, b.fieldname])
+                if b.limit:
+                    d.append([b.fieldtype, b.fieldname, b.limit])
+                else:
+                    d.append([b.fieldtype, b.fieldname])
             elif b.type == 'Array':
                 if b.lengthfield:
-                    d.append([b.fieldtype, b.fieldname, b.length, b.lengthfield])
+                    d.append([b.fieldtype, b.fieldname,
+                              b.length, b.lengthfield])
                 else:
                     d.append([b.fieldtype, b.fieldname, b.length])
             elif b.type == 'Union':
@@ -44,7 +50,7 @@ def walk_defs(s):
             else:
                 raise ValueError("Error in processing array type %s" % b)
 
-        if t.crc:
+        if is_message and t.crc:
             c = {}
             c['crc'] = "{0:#0{1}x}".format(t.crc, 10)
             d.append(c)
@@ -52,18 +58,21 @@ def walk_defs(s):
         r.append(d)
     return r
 
-
 #
 # Plugin entry point
 #
-def run(filename, s, file_crc):
+def run(filename, s):
     j = {}
 
-    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['types'] = (walk_defs([o for o in s['types']
+                             if o.__class__.__name__ == 'Typedef']))
+    j['messages'] = walk_defs(s['Define'], True)
+    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['aliases'] = s['Alias']
-    j['vl_api_version'] = hex(file_crc)
+    j['options'] = s['Option']
+    j['aliases'] = {o.name:o.alias for o in s['types'] if o.__class__.__name__ == 'Using'}
+    j['vl_api_version'] = hex(s['file_crc'])
     return json.dumps(j, indent=4, separators=(',', ': '))