From 1732fc1ab851c454a74efda47a383f48691d545a Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 30 Aug 2016 21:03:51 +0200 Subject: Python API: Re-adding rudimentary variable length array pack support. Fixed bug in message-id mapping with non-consequtive APIs. Change-Id: Icd6073e4655f7ce5432816861ae58915e5b336af Signed-off-by: Ole Troan --- vppapigen/pyvppapigen.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'vppapigen') diff --git a/vppapigen/pyvppapigen.py b/vppapigen/pyvppapigen.py index e216169d..c215d15b 100755 --- a/vppapigen/pyvppapigen.py +++ b/vppapigen/pyvppapigen.py @@ -68,7 +68,7 @@ def get_pack(f): bytecount = 0 pack = '' elements = 1 - if len(f) is 3 or len(f) is 4: # TODO: add support for variable length arrays (VPP-162) + if len(f) is 3 or len(f) is 4: size = type_size[f[0]] bytecount += size * int(f[2]) # Check if we have a zero length array @@ -146,14 +146,26 @@ def encode_print(name, id, t): if multipart == True: print(u" results_more_set(context)") - ### TODO deal with zeroarray!!! - #if zeroarray == True: - # print(u" vpp_api.write(pack('" + pack + "', " + id + ", 0, context, " + ', '.join(args[3:-1]) + ") + " + args[-1] + ")") - #else: - print(u" vpp_api.write(pack('" + pack + "', base + " + id + ", 0, context, " + ', '.join(args[3:]) + "))") + pack = '>' + start = 0 + end = 0 + offset = 0 + t = list(t) + i = 0 + + while t: + t, i, pack, offset, array = get_normal_pack(t, i, pack, offset) + if array: + print(u" vpp_api.write(pack('" + pack + "', base + " + + id + ", 0, context, " + ', '.join(args[3:-1]) + ") + " + + args[-1] + ")") + else: + print(u" vpp_api.write(pack('" + pack + "', base + " + id + + ", 0, context, " + ', '.join(args[3:]) + "))") if multipart == True: - print(u" vpp_api.write(pack('>HII', VL_API_CONTROL_PING, 0, context))") + print( + u" vpp_api.write(pack('>HII', VL_API_CONTROL_PING, 0, context))") print(''' if not async: -- cgit 1.2.3-korg