API: Use string type instead of u8.
[vpp.git] / src / tools / vppapigen / vppapigen_c.py
index f0fb008..e189b02 100644 (file)
@@ -3,7 +3,8 @@ import datetime
 import os
 import time
 
-datestring = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
+datestring = datetime.datetime.utcfromtimestamp(
+    int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
 input_filename = 'inputfil'
 top_boilerplate = '''\
 /*
@@ -94,6 +95,13 @@ def duplicate_wrapper_tail():
     return '#endif\n\n'
 
 
+def api2c(fieldtype):
+    mappingtable = {'string': 'vl_api_string_t', }
+    if fieldtype in mappingtable:
+        return mappingtable[fieldtype]
+    return fieldtype
+
+
 def typedefs(objs, aliases, filename):
     name = filename.replace('.', '_')
     output = '''\
@@ -130,12 +138,12 @@ def typedefs(objs, aliases, filename):
                 output += "typedef VL_API_PACKED(struct _vl_api_%s {\n" % o.name
             for b in o.block:
                 if b.type == 'Field':
-                    output += "    %s %s;\n" % (b.fieldtype, b.fieldname)
+                    output += "    %s %s;\n" % (api2c(b.fieldtype), b.fieldname)
                 elif b.type == 'Array':
                     if b.lengthfield:
-                        output += "    %s %s[0];\n" % (b.fieldtype, b.fieldname)
+                        output += "    %s %s[0];\n" % (api2c(b.fieldtype), b.fieldname)
                     else:
-                        output += "    %s %s[%s];\n" % (b.fieldtype, b.fieldname,
+                        output += "    %s %s[%s];\n" % (api2c(b.fieldtype), b.fieldname,
                                                         b.length)
                 else:
                     raise ValueError("Error in processing array type %s" % b)