From 592c57d1376fb7dddd9bd1d42b5149718ff0923b Mon Sep 17 00:00:00 2001 From: Roman Strakhov Date: Wed, 17 Apr 2024 17:41:48 +0400 Subject: [PATCH] fix empty structs for cpp<20 --- messgen/cpp_generator.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/messgen/cpp_generator.py b/messgen/cpp_generator.py index d2f3c6f..3183678 100644 --- a/messgen/cpp_generator.py +++ b/messgen/cpp_generator.py @@ -261,8 +261,6 @@ def _generate_type_struct(self, type_name): field_name = field["name"] field_type_def = self._protocols.get_type(curr_proto_name, field["type"]) code_ser.extend(self._serialize_field(field_name, field_type_def)) - else: - raise RuntimeError("Empty group in struct %s" % type_name) code_ser.append("") code_ser.append("return _size;") @@ -293,8 +291,6 @@ def _generate_type_struct(self, type_name): field_name = field["name"] field_type_def = self._protocols.get_type(curr_proto_name, field["type"]) code_deser.extend(self._deserialize_field(field_name, field_type_def)) - else: - raise RuntimeError("Empty group in struct %s" % type_name) code_deser.append("") code_deser.append("return _size;") @@ -345,11 +341,14 @@ def _generate_type_struct(self, type_name): if self._get_cpp_standard() < 20: # Operator == code_eq = [] - field_name = fields[0]["name"] - code_eq.append("return l.%s == r.%s" % (field_name, field_name)) - for field in fields[1:]: - field_name = field["name"] - code_eq.append(" and l.%s == r.%s" % (field_name, field_name)) + if len(fields) > 0: + field_name = fields[0]["name"] + code_eq.append("return l.%s == r.%s" % (field_name, field_name)) + for field in fields[1:]: + field_name = field["name"] + code_eq.append(" and l.%s == r.%s" % (field_name, field_name)) + else: + code_eq.append("return true") code_eq[-1] += ";" code.extend([