From 0443b464ad8732b702c7007d0298d90505a5c003 Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Tue, 9 Apr 2019 15:03:46 -0700 Subject: [PATCH] wire gen: add in correct printing for arrays of subtypes subtypes don't use the fance type registration that other 'set structs' do, see devtools/printwire.c --- tools/generate-wire.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tools/generate-wire.py b/tools/generate-wire.py index 0014f7540..33fce9700 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -705,6 +705,8 @@ class Message(object): elif f.is_array(): self.print_printwire_array(subcalls, basetype, f, f.num_elems, ref) self.add_truncate_check(subcalls, truncate_check_ref) + elif f.fieldtype.is_subtype(): + Subtype._inner_print_printwire_array(subcalls, basetype, f, f.lenvar, ref) elif f.is_variable_size(): self.print_printwire_array(subcalls, basetype, f, f.lenvar, ref) self.add_truncate_check(subcalls, truncate_check_ref) @@ -982,6 +984,23 @@ class Subtype(Message): subcalls=str(subcalls) ) + def print_printwire_array(self, subcalls, basetype, f, num_elems, ref): + return Subtype._inner_print_printwire_array(subcalls, basetype, f, num_elems, '') + + @staticmethod + def _inner_print_printwire_array(subcalls, basetype, f, num_elems, ref): + if f.has_array_helper(): + subcalls.append('printwire_{}_array(tal_fmt(NULL, "%s.{}", fieldname), {}cursor, {}plen, {});' + .format(basetype, f.name, ref, ref, num_elems)) + else: + subcalls.append('printf("[");') + subcalls.append('for (size_t i = 0; i < {}; i++) {{' + .format(num_elems)) + subcalls.append('printwire_{}(tal_fmt(NULL, "%s.{}", fieldname), {}cursor, {}plen);' + .format(basetype, f.name, ref, ref)) + subcalls.append('}') + subcalls.append('printf("]");') + tlv_message_towire_stub = """static void towire_{tlv_name}_{name}(u8 **p, struct tlv_msg_{name} *{name}) {{ {field_decls}