summaryrefslogtreecommitdiffstats
path: root/vppapigen
diff options
context:
space:
mode:
authorGabriel Ganne <gabriel.ganne@qosmos.com>2016-09-19 14:05:15 +0200
committerOle Trøan <otroan@employees.org>2016-09-21 18:36:28 +0000
commitce64b8e5b247149887caf77fd139d2a6880acbe6 (patch)
tree46cbdbd9c66d3f38f7fb98603936fe033892b74d /vppapigen
parent0bfe5d8c792abcdbcf27bfcc7b7b353fba04aee2 (diff)
vpp python api - fix vla pack generation
This fixes commit 1732fc1ab851c454a74efda47a383f48691d545a. Change-Id: I3d9f1384c20d2ca22eaf2aae553455789b934b6e Signed-off-by: Gabriel Ganne <gabriel.ganne@qosmos.com>
Diffstat (limited to 'vppapigen')
-rwxr-xr-xvppapigen/pyvppapigen.py35
1 files changed, 15 insertions, 20 deletions
diff --git a/vppapigen/pyvppapigen.py b/vppapigen/pyvppapigen.py
index c215d15bc5d..7fde21c5ce9 100755
--- a/vppapigen/pyvppapigen.py
+++ b/vppapigen/pyvppapigen.py
@@ -118,14 +118,9 @@ def api_table_print(name, i):
print('api_name_to_id["' + msg_id_in + '"] =', i)
print('')
+
def encode_print(name, id, t):
- total = 0
args = get_args(t)
- pack = '>'
- for i, f in enumerate(t):
- p, elements, size = get_pack(f)
- pack += p
- total += size
if name.find('_dump') > 0:
multipart = True
@@ -146,22 +141,22 @@ def encode_print(name, id, t):
if multipart == True:
print(u" results_more_set(context)")
- 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:]) + "))")
+ # only the last field can be a variable-length-array
+ # it can either be 0, or a string
+ # first, deal with all the other fields
+ pack = '>' + ''.join([get_pack(f)[0] for f in t[:-1]])
+
+ # now see if the last field is a vla
+ if len(t[-1]) >= 3 and t[-1][2] == '0':
+ print(u" vpp_api.write(pack('" + pack + "', base + " +
+ id + ", 0, context, " + ', '.join(args[3:-1]) + ") + "
+ + args[-1] + ")")
+ else:
+ pack += get_pack(t[-1])[0]
+ print(u" vpp_api.write(pack('" + pack + "', base + " + id +
+ ", 0, context, " + ', '.join(args[3:]) + "))")
if multipart == True:
print(