From dc96f067d1c6f3019068900a36beb7219e3e3182 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Wed, 20 Jul 2022 16:41:45 +0200 Subject: [PATCH 08/12] generate_packets.py: move packet_name() generation into PacketsDefinition See osdn#45173 Signed-off-by: Alina Lenk --- common/generate_packets.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index a10499ebb6..29998126f4 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -2413,33 +2413,33 @@ void delta_stats_reset(void) { ) return intro + body + extro - -# Returns a code fragment which is the implementation of the -# packet_name() function. -def get_packet_name(packets: PacketsDefinition) -> str: - intro = """\ + @property + def code_packet_name(self) -> str: + """Code fragment implementing the packet_name() function""" + intro = """\ const char *packet_name(enum packet_type type) { static const char *const names[PACKET_LAST] = { """ - body="" - for _, packet, skipped in packets.iter_by_number(): - body += """\ + body = "" + for _, packet, skipped in self.iter_by_number(): + body += """\ "unknown", """ * skipped - body += """\ + body += """\ "%s", """ % packet.type - extro = """\ + extro = """\ }; return (type < PACKET_LAST ? names[type] : "unknown"); } """ - return intro+body+extro + return intro + body + extro + # Returns a code fragment which is the implementation of the # packet_has_game_info_flag() function. @@ -2742,7 +2742,7 @@ static int stats_total_sent; output_c.write(packets.code_delta_stats_report) output_c.write(packets.code_delta_stats_reset) - output_c.write(get_packet_name(packets)) + output_c.write(packets.code_packet_name) output_c.write(get_packet_has_game_info_flag(packets)) # write hash, cmp, send, receive -- 2.34.1