@@ -136,14 +136,10 @@ def __init__(self, message, name, size, comments, prevname, includes):
136
136
self .optional = False
137
137
self .is_tlv = False
138
138
139
- # field name appended with '+' means this field contains a tlv
140
- if name .endswith ('+' ):
139
+ if name .endswith ('_tlv' ):
141
140
self .is_tlv = True
142
- self .name = name [:- 1 ]
143
141
if self .name not in tlv_fields :
144
- tlv_includes , tlv_messages = parse_tlv_file (self .name )
145
- includes += tlv_includes
146
- tlv_fields [self .name ] = tlv_messages
142
+ tlv_fields [self .name ] = []
147
143
148
144
# ? means optional field (not supported for arrays)
149
145
if size .startswith ('?' ):
@@ -977,68 +973,6 @@ def find_message_with_option(messages, optional_messages, name, option):
977
973
return m
978
974
979
975
980
- def get_directory_prefix ():
981
- # FIXME: use prefix of filename
982
- return "wire/"
983
-
984
-
985
- def get_tlv_filename (field_name ):
986
- return 'gen_{}_csv' .format (field_name )
987
-
988
-
989
- def parse_tlv_file (tlv_field_name ):
990
- tlv_includes = []
991
- tlv_messages = []
992
- tlv_comments = []
993
- tlv_prevfield = None
994
- with open (get_directory_prefix () + get_tlv_filename (tlv_field_name )) as f :
995
- for line in f :
996
- # #include gets inserted into header
997
- if line .startswith ('#include ' ):
998
- tlv_includes .append (line )
999
- continue
1000
-
1001
- by_comments = line .rstrip ().split ('#' )
1002
-
1003
- # Emit a comment if they included one
1004
- if by_comments [1 :]:
1005
- tlv_comments .append (' ' .join (by_comments [1 :]))
1006
-
1007
- parts = by_comments [0 ].split (',' )
1008
- if parts == ['' ]:
1009
- continue
1010
-
1011
- if len (parts ) == 2 :
1012
- # eg commit_sig,132
1013
- tlv_msg = Message (parts [0 ], Enumtype ("TLV_" + parts [0 ].upper (), parts [1 ]), tlv_comments , True )
1014
- tlv_messages .append (tlv_msg )
1015
-
1016
- tlv_comments = []
1017
- tlv_prevfield = None
1018
- else :
1019
- if len (parts ) == 4 :
1020
- # eg commit_sig,0,channel-id,8 OR
1021
- # commit_sig,0,channel-id,u64
1022
- m = find_message (tlv_messages , parts [0 ])
1023
- if m is None :
1024
- raise ValueError ('Unknown message {}' .format (parts [0 ]))
1025
- elif len (parts ) == 5 :
1026
- # eg.
1027
- # channel_reestablish,48,your_last_per_commitment_secret,32,option209
1028
- m = find_message_with_option (tlv_messages , messages_with_option , parts [0 ], parts [4 ])
1029
- else :
1030
- raise ValueError ('Line {} malformed' .format (line .rstrip ()))
1031
-
1032
- f = Field (m .name , parts [2 ], parts [3 ], tlv_comments , tlv_prevfield , includes )
1033
- m .addField (f )
1034
- # If it used prevfield as lenvar, keep that for next
1035
- # time (multiple fields can use the same lenvar).
1036
- if not f .lenvar :
1037
- tlv_prevfield = parts [2 ]
1038
- tlv_comments = []
1039
- return tlv_includes , tlv_messages
1040
-
1041
-
1042
976
parser = argparse .ArgumentParser (description = 'Generate C from CSV' )
1043
977
parser .add_argument ('--header' , action = 'store_true' , help = "Create wire header" )
1044
978
parser .add_argument ('--bolt' , action = 'store_true' , help = "Generate wire-format for BOLT" )
@@ -1073,9 +1007,18 @@ def parse_tlv_file(tlv_field_name):
1073
1007
if parts == ['' ]:
1074
1008
continue
1075
1009
1076
- if len (parts ) == 2 :
1077
- # eg commit_sig,132
1078
- messages .append (Message (parts [0 ], Enumtype ("WIRE_" + parts [0 ].upper (), parts [1 ]), comments , False ))
1010
+ is_tlv_msg = len (parts ) == 3
1011
+ if len (parts ) == 2 or is_tlv_msg :
1012
+ # eg: commit_sig,132,(_tlv)
1013
+ message = Message (parts [0 ],
1014
+ Enumtype ("WIRE_" + parts [0 ].upper (), parts [1 ]),
1015
+ comments ,
1016
+ is_tlv_msg )
1017
+
1018
+ messages .append (message )
1019
+ if is_tlv_msg :
1020
+ tlv_fields [parts [2 ]].append (message )
1021
+
1079
1022
comments = []
1080
1023
prevfield = None
1081
1024
else :
@@ -1265,8 +1208,8 @@ def build_tlv_structs(tlv_fields):
1265
1208
towire_decls += build_tlv_towires (tlv_fields )
1266
1209
fromwire_decls += build_tlv_fromwires (tlv_fields )
1267
1210
1268
- towire_decls += [m .print_towire (options .header , '' ) for m in messages + messages_with_option ]
1269
- fromwire_decls += [m .print_fromwire (options .header , '' ) for m in messages + messages_with_option ]
1211
+ towire_decls += [m .print_towire (options .header , '' ) for m in toplevel_messages + messages_with_option ]
1212
+ fromwire_decls += [m .print_fromwire (options .header , '' ) for m in toplevel_messages + messages_with_option ]
1270
1213
decls = fromwire_decls + towire_decls
1271
1214
1272
1215
print (template .format (
0 commit comments