From aaa8779bc0a113c303fc27f247dfba10dd06ab4e Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 1 Jun 2020 16:18:50 +0200 Subject: [PATCH] wiregen: Add enums for TLV types so we can call them by their name Suggested-by: Lisa Neigut <@niftynei> Signed-off-by: Christian Decker <@cdecker> --- tools/gen/header_template | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/gen/header_template b/tools/gen/header_template index e606bf474..ea03b9bee 100644 --- a/tools/gen/header_template +++ b/tools/gen/header_template @@ -119,6 +119,18 @@ bool ${tlv.name}_is_valid(const struct ${tlv.struct_name()} *record, #define TLVS_${tlv.name.upper()}_ARRAY_SIZE ${len(tlv.messages)} extern const struct tlv_record_type tlvs_${tlv.name}[]; +<%! + def upper(text): + return text.upper() +%> + +/* Define an enum with the constants */ +enum ${tlv.name}_types { +% for msg in tlv.ordered_msgs(): + ${msg.struct_name()|upper} = ${msg.number}, +% endfor +}; + % endif % endfor % if options.expose_subtypes and bool(subtypes):