diff options
author | Michal Cmarada <mcmarada@cisco.com> | 2018-12-06 10:17:39 +0100 |
---|---|---|
committer | Ole Trøan <otroan@employees.org> | 2018-12-06 14:04:44 +0000 |
commit | 1f0dd7a0664bc217b7d69773574ac7eae3813bd7 (patch) | |
tree | 475e9d1900babd0241b3060aa0ac389132d553c5 /extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py | |
parent | ad69c1fddc4f3d1054cb527e550dfa1698355244 (diff) |
Update japi to support type aliases
Change-Id: I6d6068d641d4c91e5c5b52eefb898affc5c0d2c0
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py')
-rwxr-xr-x | extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py b/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py index 3c2db15d176..16099689880 100755 --- a/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py +++ b/extras/japi/java/jvpp/gen/jvppgen/jvpp_model.py @@ -17,6 +17,8 @@ import json import pprint from collections import OrderedDict +import binascii + BASE_PACKAGE = "io.fd.vpp.jvpp" @@ -303,6 +305,11 @@ def is_control_ping_reply(msg): return msg.name == u'control_ping_reply' +def crc(block): + s = str(block).encode() + return binascii.crc32(s) & 0xffffffff + + class JVppModel(object): def __init__(self, logger, json_api_files, plugin_name): self.logger = logger @@ -333,8 +340,43 @@ class JVppModel(object): self._parse_types(types) + def _parse_aliases(self, types): + for alias_name in self._aliases: + alias = self._aliases[alias_name] + alias_type = {"type": "type"} + java_name_lower = _underscore_to_camelcase_lower(alias_name) + vpp_type = alias["type"] + crc_value = '0x%08x' % crc(alias_name) + if "length" in alias: + length = alias["length"] + alias_type["data"] = [ + alias_name, + [ + vpp_type, + java_name_lower, + length + ], + { + "crc": crc_value + } + ] + else: + alias_type["data"] = [ + alias_name, + [ + vpp_type, + java_name_lower + ], + { + "crc": crc_value + } + ] + + types[alias_name] = alias_type + def _parse_types(self, types): self._parse_simple_types() + self._parse_aliases(types) i = 0 while True: unresolved = {} @@ -484,9 +526,6 @@ class JVppModel(object): def _parse_field(self, field, fields): type_name = _extract_type_name(field[0]) - if type_name in self._aliases and type_name not in self._types_by_name: - aliased_type = self._types_by_name.get(self._aliases.get(type_name).get("type")) - self._types_by_name[type_name] = aliased_type if type_name in self._types_by_name: if len(field) > 2: @@ -524,6 +563,7 @@ class JVppModel(object): self.messages = self._messages_by_name.values() + _ARRAY_SUFFIX = '[]' |