Просмотр исходного кода

Initialize the which oneof variable.

Bart Hertog 6 лет назад
Родитель
Сommit
6b6107b9ff
2 измененных файлов с 6 добавлено и 1 удалено
  1. 4 1
      generator/Header_Template.h
  2. 2 0
      generator/protoc-gen-eams.py

+ 4 - 1
generator/Header_Template.h

@@ -226,9 +226,12 @@ class {{ msg.name }} final: public ::EmbeddedProto::MessageInterface
         {% if field.of_type_enum %}
         {{field.variable_name}}({{field.default_value}}){{"," if not loop.last}}
         {% else %}
-        {{field.variable_name}}(){{"," if not loop.last}}
+        {{field.variable_name}}(){{"," if not loop.last}}{{"," if loop.last and msg.has_oneofs}}
         {% endif %}
     {% endfor %}
+    {% for oneof in msg.oneofs() %}
+        {{oneof.which_oneof}}(){{"," if not loop.last}}
+    {% endfor %}
     {
 
     };

+ 2 - 0
generator/protoc-gen-eams.py

@@ -132,6 +132,8 @@ class MessageTemplateParameters:
     def __init__(self, msg_proto):
         self.name = msg_proto.name
         self.msg_proto = msg_proto
+        self.has_fields = len(self.msg_proto.field) > 0
+        self.has_oneofs = len(self.msg_proto.oneof_decl) > 0
         self.templates = []
 
         #TODO this creates a bug if a oneof field is also a repeated_field.