Browse Source

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
pr-2587
lisa neigut 6 years ago
committed by Rusty Russell
parent
commit
0443b464ad
  1. 19
      tools/generate-wire.py

19
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}

Loading…
Cancel
Save