diff options
author | Klement Sekera <klement@klementsekera.com> | 2023-08-06 19:33:16 +0200 |
---|---|---|
committer | Ole Tr�an <otroan@employees.org> | 2023-08-18 06:09:41 +0000 |
commit | 03e1d559f912513e1bc2ffc615b7833471afc790 (patch) | |
tree | e1338544f64a0b16932583944dc2f50528209bfe /src/vpp-api/vapi/vapi_json_parser.py | |
parent | 56777b9409c9e0be2ca86504aae95ad6472a78ea (diff) |
vapi: improve vl_api_string_t handling
Define vl_api_string_t to correspond with vlibapi/api_types.h
Fix allocation and size calculation routine generation.
Type: improvement
Change-Id: I6b0a3eb3459d75d326e67bfb76dac8125e480afa
Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
Diffstat (limited to 'src/vpp-api/vapi/vapi_json_parser.py')
-rw-r--r-- | src/vpp-api/vapi/vapi_json_parser.py | 54 |
1 files changed, 42 insertions, 12 deletions
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() |