mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 07:34:24 +01:00
subtype: update parser to understand non-'$' csv output
the original version of the subtype generator emitted '$' to designate that a field was a subtype; now it's got a different format: funding_type,8,num_inputs,2 funding_type,10,input_info,num_inputs*input_info this patch updates our generator to understand this new format
This commit is contained in:
committed by
Rusty Russell
parent
803b161d7e
commit
a385d1de4c
@@ -179,18 +179,11 @@ class Field(object):
|
|||||||
|
|
||||||
# Bolts use just a number: Guess type based on size.
|
# Bolts use just a number: Guess type based on size.
|
||||||
if options.bolt:
|
if options.bolt:
|
||||||
if size.startswith('$'): # this is a subtype
|
|
||||||
self.fieldtype = FieldType('struct {}'.format(name))
|
|
||||||
self.is_subtype = True
|
|
||||||
if size[1:] == prevname:
|
|
||||||
self.lenvar = size[1:]
|
|
||||||
else:
|
|
||||||
raise ValueError('Expected size field for subtype field {}'.format(name))
|
|
||||||
else:
|
|
||||||
if size == 'var_int':
|
if size == 'var_int':
|
||||||
base_size = 8
|
base_size = 8
|
||||||
self.fieldtype = FieldType(size)
|
self.fieldtype = FieldType(size)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
base_size = int(size)
|
base_size = int(size)
|
||||||
self.fieldtype = Field._guess_type(message, self.name, base_size)
|
self.fieldtype = Field._guess_type(message, self.name, base_size)
|
||||||
# There are some arrays which we have to guess, based on sizes.
|
# There are some arrays which we have to guess, based on sizes.
|
||||||
@@ -202,6 +195,10 @@ class Field(object):
|
|||||||
self.name,
|
self.name,
|
||||||
tsize))
|
tsize))
|
||||||
self.num_elems = int(base_size / tsize)
|
self.num_elems = int(base_size / tsize)
|
||||||
|
except ValueError: # for subtypes
|
||||||
|
self.fieldtype = FieldType('struct {}'.format(name))
|
||||||
|
self.is_subtype = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Real typename.
|
# Real typename.
|
||||||
self.fieldtype = FieldType(size)
|
self.fieldtype = FieldType(size)
|
||||||
@@ -1237,9 +1234,9 @@ for line in fileinput.input(options.files):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
is_tlv_msg = len(parts) == 3
|
is_tlv_msg = len(parts) == 3
|
||||||
if len(parts) == 2 or is_tlv_msg:
|
if len(parts) == 1 or len(parts) == 2 or is_tlv_msg:
|
||||||
# eg: commit_sig,132,(_tlv)
|
# eg: commit_sig,132,(_tlv)
|
||||||
if parts[1] == '$': # this is a subtype
|
if len(parts) == 1: # this is a subtype, it has no type number.
|
||||||
subtypes.append(Subtype(parts[0], comments))
|
subtypes.append(Subtype(parts[0], comments))
|
||||||
else:
|
else:
|
||||||
if is_tlv_msg:
|
if is_tlv_msg:
|
||||||
@@ -1483,10 +1480,16 @@ else:
|
|||||||
towire_decls += build_tlv_towires(tlv_fields)
|
towire_decls += build_tlv_towires(tlv_fields)
|
||||||
fromwire_decls += build_tlv_fromwires(tlv_fields)
|
fromwire_decls += build_tlv_fromwires(tlv_fields)
|
||||||
|
|
||||||
if not options.header or options.header and options.subtypes:
|
if not options.header or (options.header and options.subtypes):
|
||||||
|
subtype_towires = []
|
||||||
|
subtype_fromwires = []
|
||||||
for subtype in subtypes:
|
for subtype in subtypes:
|
||||||
towire_decls.append(subtype.print_towire())
|
subtype_towires.append(subtype.print_towire())
|
||||||
fromwire_decls.append(subtype.print_fromwire())
|
subtype_fromwires.append(subtype.print_fromwire())
|
||||||
|
subtype_towires.reverse()
|
||||||
|
subtype_fromwires.reverse()
|
||||||
|
towire_decls += subtype_towires
|
||||||
|
fromwire_decls += subtype_fromwires
|
||||||
|
|
||||||
towire_decls += [m.print_towire(options.header) for m in toplevel_messages + messages_with_option]
|
towire_decls += [m.print_towire(options.header) for m in toplevel_messages + messages_with_option]
|
||||||
fromwire_decls += [m.print_fromwire(options.header) for m in toplevel_messages + messages_with_option]
|
fromwire_decls += [m.print_fromwire(options.header) for m in toplevel_messages + messages_with_option]
|
||||||
|
|||||||
Reference in New Issue
Block a user