Skip to content

Commit

Permalink
Merge pull request #86 from microavia/v1_fix_cpp17_empty
Browse files Browse the repository at this point in the history
V1 fix cpp17 empty structs
  • Loading branch information
Roman- committed Apr 17, 2024
2 parents 9f062d0 + 592c57d commit a84a182
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions messgen/cpp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;")

Expand Down Expand Up @@ -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;")

Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit a84a182

Please sign in to comment.