mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
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>
This commit is contained in:
parent
217df2d2e8
commit
aa23a2a93f
1 changed files with 14 additions and 7 deletions
|
@ -137,6 +137,14 @@ class Field(object):
|
|||
# Not a number; must be a type.
|
||||
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):
|
||||
return self.name.startswith('pad')
|
||||
|
||||
|
@ -235,6 +243,8 @@ class Message(object):
|
|||
if field.is_variable_size():
|
||||
self.checkLenField(field)
|
||||
self.has_variable_fields = True
|
||||
elif field.basetype() in varlen_structs:
|
||||
self.has_variable_fields = True
|
||||
self.fields.append(field)
|
||||
|
||||
def print_fromwire_array(self, subcalls, basetype, f, name, num_elems):
|
||||
|
@ -272,11 +282,7 @@ class Message(object):
|
|||
|
||||
subcalls = []
|
||||
for f in self.fields:
|
||||
basetype=f.fieldtype.name
|
||||
if f.fieldtype.name.startswith('struct '):
|
||||
basetype=f.fieldtype.name[7:]
|
||||
elif f.fieldtype.name.startswith('enum '):
|
||||
basetype=f.fieldtype.name[5:]
|
||||
basetype=f.basetype()
|
||||
|
||||
for c in f.comments:
|
||||
subcalls.append('\t/*{} */'.format(c))
|
||||
|
@ -304,8 +310,9 @@ class Message(object):
|
|||
.format(f.name, basetype))
|
||||
else:
|
||||
subcalls.append("\t//4th case {name}".format(name=f.name))
|
||||
subcalls.append('\tfromwire_{}(&cursor, plen, {});'
|
||||
.format(basetype, f.name))
|
||||
ctx = "ctx, " if basetype in varlen_structs else ""
|
||||
subcalls.append('\tfromwire_{}({}&cursor, plen, {});'
|
||||
.format(basetype, ctx, f.name))
|
||||
|
||||
return template.format(
|
||||
name=self.name,
|
||||
|
|
Loading…
Add table
Reference in a new issue