mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +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.
|
# 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…
Add table
Reference in a new issue