diff options
author | Ole Troan <ot@cisco.com> | 2018-11-13 12:36:56 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2018-11-29 07:39:22 +0000 |
commit | 53fffa1db7cb04982db8977acd61b808ef60d5a8 (patch) | |
tree | 7f8c8b25b51d722cc6353c028ddad4e0ad6fcd31 /src/vpp-api/python/vpp_papi | |
parent | 4f10db317382832068d67b5d19be4a696d80c19a (diff) |
API: Add support for type aliases
Previously all types are compound. This adds support for aliases,
so one can do things like:
typedef u32 interface_index;
or
typedef u8 ip4_address[4];
Change-Id: I0455cad0123fc88acb491d2a3ea2725426bdb246
Signed-off-by: Ole Troan <ot@cisco.com>
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi')
-rw-r--r-- | src/vpp-api/python/vpp_papi/vpp_papi.py | 11 | ||||
-rw-r--r-- | src/vpp-api/python/vpp_papi/vpp_serializer.py | 14 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py index ca4b955fd07..bd2682f5b8f 100644 --- a/src/vpp-api/python/vpp_papi/vpp_papi.py +++ b/src/vpp-api/python/vpp_papi/vpp_papi.py @@ -27,7 +27,7 @@ import fnmatch import weakref import atexit from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType, BaseTypes -from . vpp_serializer import VPPMessage, vpp_get_type +from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias from . vpp_format import VPPFormat if sys.version[0] == '2': @@ -102,13 +102,15 @@ class VPP(object): for t in api['types']: t[0] = 'vl_api_' + t[0] + '_t' types[t[0]] = {'type': 'type', 'data': t} + for t, v in api['aliases'].items(): + types['vl_api_' + t + '_t'] = {'type': 'alias', 'data': v} i = 0 while True: unresolved = {} for k, v in types.items(): t = v['data'] - if not vpp_get_type(t[0]): + if not vpp_get_type(k): if v['type'] == 'enum': try: VPPEnumType(t[0], t[1:]) @@ -124,6 +126,11 @@ class VPP(object): VPPType(t[0], t[1:]) except ValueError: unresolved[k] = v + elif v['type'] == 'alias': + try: + VPPTypeAlias(k, t) + except ValueError: + unresolved[k] = v if len(unresolved) == 0: break if i > 3: diff --git a/src/vpp-api/python/vpp_papi/vpp_serializer.py b/src/vpp-api/python/vpp_papi/vpp_serializer.py index bd0f73803da..a001cca565a 100644 --- a/src/vpp-api/python/vpp_papi/vpp_serializer.py +++ b/src/vpp-api/python/vpp_papi/vpp_serializer.py @@ -79,7 +79,7 @@ class FixedList_u8(object): self.packer = BaseTypes(field_type, num) self.size = self.packer.size - def pack(self, list, kwargs): + def pack(self, list, kwargs = None): """Packs a fixed length bytestring. Left-pads with zeros if input data is too short.""" if not list: @@ -277,6 +277,18 @@ class VPPUnionType(object): return self.tuple._make(r), maxsize +def VPPTypeAlias(name, msgdef): + t = vpp_get_type(msgdef['type']) + if not t: + raise ValueError() + if 'length' in msgdef: + if msgdef['length'] == 0: + raise ValueError() + types[name] = FixedList(name, msgdef['type'], msgdef['length']) + else: + types[name] = t + + class VPPType(object): # Set everything up to be able to pack / unpack def __init__(self, name, msgdef): |