X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp-api%2Fvapi%2Fvapi_json_parser.py;fp=src%2Fvpp-api%2Fvapi%2Fvapi_json_parser.py;h=c06cb8cf77be230411d2fb7389a99c5f2267aafc;hb=03e1d559f912513e1bc2ffc615b7833471afc790;hp=00c234fc0148b816f4a7c5748d54befe376cbfa8;hpb=56777b9409c9e0be2ca86504aae95ad6472a78ea;p=vpp.git diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py index 00c234fc014..c06cb8cf77b 100644 --- a/src/vpp-api/vapi/vapi_json_parser.py +++ b/src/vpp-api/vapi/vapi_json_parser.py @@ -197,12 +197,18 @@ class Message(object): "array `%s' doesn't have reference to member " "containing the actual length" % (name, field[1]) ) - if field[0] == "string" and field[2] > 0: - field_type = json_parser.lookup_type_like_id("u8") + if field[0] == "string" and field[2] == 0: + field_type = json_parser.lookup_type_like_id("vl_api_string_t") + p = field_class(field_name=field[1], field_type=field_type) + else: + if field[0] == "string" and field[2] > 0: + field_type = json_parser.lookup_type_like_id("u8") - p = field_class( - field_name=field[1], field_type=field_type, array_len=field[2] - ) + p = field_class( + field_name=field[1], + field_type=field_type, + array_len=field[2], + ) elif l == 4: nelem_field = None for f in fields: @@ -255,13 +261,31 @@ class StructType(Type, Struct): p = field_class(field_name=field[1], field_type=field_type) elif len(field) == 3: if field[2] == 0: - raise ParseError( - "While parsing type `%s': array `%s' has " - "variable length" % (name, field[1]) + if name == "vl_api_string_t": + p = None + for f in fields: + if f.name == "length": + nelem_field = f + p = field_class( + field_name=field[1], + field_type=field_type, + array_len=field[2], + nelem_field=nelem_field, + ) + break + if p is None: + raise ParseError( + "While parsing type `%s': missing `length'" % name + ) + else: + raise ParseError( + "While parsing type `%s': array `%s' has " + "variable length" % (name, field[1]) + ) + else: + p = field_class( + field_name=field[1], field_type=field_type, array_len=field[2] ) - p = field_class( - field_name=field[1], field_type=field_type, array_len=field[2] - ) elif len(field) == 4: nelem_field = None for f in fields: @@ -344,7 +368,13 @@ class JsonParser(object): ] } - self.types["string"] = simple_type_class("vl_api_string_t") + self.types["string"] = simple_type_class("u8") + self.types["vl_api_string_t"] = struct_type_class( + ["vl_api_string_t", ["u32", "length"], ["u8", "buf", 0]], + self, + field_class, + logger, + ) self.replies = set() self.events = set() self.streams = set()