pyln-proto: write out length of arrays of subtypes to wire

We weren't writing out the length of a nested subtype's
dynamicarraylenght, now we do. The trick is to iterate through the
fields on a subtype (since the length field is added separately)
and to also iterate down through the otherfield values as we 'descend'
This commit is contained in:
niftynei
2021-03-24 16:36:32 -05:00
committed by Rusty Russell
parent 6db6ba6c03
commit 5142dc81f6
3 changed files with 45 additions and 8 deletions

View File

@@ -297,10 +297,17 @@ other types. Since 'msgtype' is almost identical, it inherits from this too.
def write(self, io_out: BufferedIOBase, v: Dict[str, Any], otherfields: Dict[str, Any]) -> None:
self._raise_if_badvals(v)
for fname, val in v.items():
field = self.find_field(fname)
assert field
field.fieldtype.write(io_out, val, otherfields)
for f in self.fields:
if f.name in v:
val = v[f.name]
else:
if f.option is not None:
raise ValueError("Missing field {} {}".format(f.name, otherfields))
val = None
if self.name in otherfields:
otherfields = otherfields[self.name]
f.fieldtype.write(io_out, val, otherfields)
def read(self, io_in: BufferedIOBase, otherfields: Dict[str, Any]) -> Optional[Dict[str, Any]]:
vals = {}