X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp-api%2Fvapi%2Fvapi_json_parser.py;h=3c9bff10824f59d23166d70e60e927c059098df6;hb=51e59688359ddac32ed58f3add3ea9ac358c9132;hp=4e62720d37e3800d5faf66bf3f8087e1556354e7;hpb=958b750ceaf6c20466bc4e5605da39b4490847d9;p=vpp.git diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py index 4e62720d37e..3c9bff10824 100644 --- a/src/vpp-api/vapi/vapi_json_parser.py +++ b/src/vpp-api/vapi/vapi_json_parser.py @@ -50,6 +50,9 @@ class Type(object): def __init__(self, name): self.name = name + def __str__(self): + return self.name + class SimpleType (Type): @@ -85,6 +88,9 @@ class Struct(object): self.fields = fields self.field_names = [n.name for n in self.fields] + def __str__(self): + return "[%s]" % "], [".join([str(f) for f in self.fields]) + class Message(object): @@ -123,7 +129,14 @@ class Message(object): if field_type in typedict: field_type = typedict[field_type] else: - field_type = typedict[remove_magic(field_type)] + mundane_field_type = remove_magic(field_type) + if mundane_field_type in typedict: + field_type = typedict[mundane_field_type] + else: + raise ParseError( + "While parsing message `%s': could not find " + "type by magic name `%s' nor by mundane name " + "`%s'" % (name, field_type, mundane_field_type)) if len(field) == 2: if self.header is not None and\ self.header.has_field(field[1]): @@ -182,15 +195,27 @@ class StructType (Type, Struct): if len(field) == 1 and 'crc' in field: self.crc = field['crc'] continue - elif len(field) == 2: + field_type = field[0] + if field_type in typedict: + field_type = typedict[field_type] + else: + mundane_field_type = remove_magic(field_type) + if mundane_field_type in typedict: + field_type = typedict[mundane_field_type] + else: + raise ParseError( + "While parsing message `%s': could not find " + "type by magic name `%s' nor by mundane name " + "`%s'" % (name, field_type, mundane_field_type)) + if len(field) == 2: p = field_class(field_name=field[1], - field_type=typedict[field[0]]) + 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])) p = field_class(field_name=field[1], - field_type=typedict[field[0]], + field_type=field_type, array_len=field[2]) else: raise ParseError( @@ -200,6 +225,10 @@ class StructType (Type, Struct): Type.__init__(self, name) Struct.__init__(self, name, fields) + def __str__(self): + return "StructType(%s, %s)" % (Type.__str__(self), + Struct.__str__(self)) + def has_field(self, name): return name in self.field_names @@ -262,6 +291,7 @@ class JsonParser(object): continue self.types[type_.name] = type_ self.types_by_json[path][type_.name] = type_ + self.logger.debug("Parsed type: %s" % type_) for m in j['messages']: try: msg = self.message_class(self.logger, m, self.types,