Browse Source

generate-wire.py: handle unmarshalling of a single varlen_struct

We previously only handled it in arrays.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
aa23a2a93f
  1. 21
      tools/generate-wire.py

21
tools/generate-wire.py

@ -137,6 +137,14 @@ class Field(object):
# Not a number; must be a type. # Not a number; must be a type.
self.fieldtype = FieldType(size) self.fieldtype = FieldType(size)
def basetype(self):
base=self.fieldtype.name
if base.startswith('struct '):
base=base[7:]
elif base.startswith('enum '):
base=base[5:]
return base
def is_padding(self): def is_padding(self):
return self.name.startswith('pad') return self.name.startswith('pad')
@ -235,6 +243,8 @@ class Message(object):
if field.is_variable_size(): if field.is_variable_size():
self.checkLenField(field) self.checkLenField(field)
self.has_variable_fields = True self.has_variable_fields = True
elif field.basetype() in varlen_structs:
self.has_variable_fields = True
self.fields.append(field) self.fields.append(field)
def print_fromwire_array(self, subcalls, basetype, f, name, num_elems): def print_fromwire_array(self, subcalls, basetype, f, name, num_elems):
@ -272,11 +282,7 @@ class Message(object):
subcalls = [] subcalls = []
for f in self.fields: for f in self.fields:
basetype=f.fieldtype.name basetype=f.basetype()
if f.fieldtype.name.startswith('struct '):
basetype=f.fieldtype.name[7:]
elif f.fieldtype.name.startswith('enum '):
basetype=f.fieldtype.name[5:]
for c in f.comments: for c in f.comments:
subcalls.append('\t/*{} */'.format(c)) subcalls.append('\t/*{} */'.format(c))
@ -304,8 +310,9 @@ class Message(object):
.format(f.name, basetype)) .format(f.name, basetype))
else: else:
subcalls.append("\t//4th case {name}".format(name=f.name)) subcalls.append("\t//4th case {name}".format(name=f.name))
subcalls.append('\tfromwire_{}(&cursor, plen, {});' ctx = "ctx, " if basetype in varlen_structs else ""
.format(basetype, f.name)) subcalls.append('\tfromwire_{}({}&cursor, plen, {});'
.format(basetype, ctx, f.name))
return template.format( return template.format(
name=self.name, name=self.name,

Loading…
Cancel
Save