Jelajahi Sumber

Got the simple types tests working again.

Bart Hertog 5 tahun lalu
induk
melakukan
4e9fac60e9

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

@@ -66,7 +66,8 @@ def generate_code(request, respones):
     if not all_parameters_registered:
         raise Exception("Unable to register all template parameters")
 
-    filepath = os.path.dirname(os.path.abspath(__file__)) + "\\templates"
+    curr_location = os.path.dirname(os.path.abspath(__file__))
+    filepath =  os.path.join(curr_location, "templates")
     template_loader = jinja2.FileSystemLoader(searchpath=filepath)
     template_env = jinja2.Environment(loader=template_loader, trim_blocks=True, lstrip_blocks=True)
 

+ 86 - 17
generator/support/Field.py

@@ -85,6 +85,15 @@ class Field:
     def get_default_value(self):
         return ""
 
+    def get_name(self):
+        return self.name
+
+    def get_variable_name(self):
+        return self.variable_name
+
+    def get_variable_id_name(self):
+        return self.variable_id_name
+
     # Returns a list with a dictionaries for each template parameter this field had. The dictionary holds the parameter
     # name and its type.
     def get_template_parameters(self):
@@ -97,19 +106,25 @@ class Field:
     def register_template_parameters(self):
         return True
 
-    def render_get_set(self, jinja_environment):
-        r = "{% macro get_set(_field) %}" \
-            "inline void clear_{{_field.name}}() { {{_field.variable_full_name}}.clear(); }" \
-            "inline void set_{{_field.name}}(const {{_field.type}}& value) { {{_field.variable_full_name}} = value; }" \
-            "inline void set_{{_field.name}}(const {{_field.type}}&& value) { {{_field.variable_full_name}} = value; }" \
-            "inline {{_field.type}}& mutable_{{_field.name}}() { return {{_field.variable_full_name}}; }" \
-            "inline const {{_field.type}}& get_{{_field.name}}() const { return {{_field.variable_full_name}}; }" \
-            "inline {{_field.type}}::FIELD_TYPE {{_field.name}}() const { return {{_field.variable_full_name}}.get(); }" \
-            "{% endmacro %}" \
-            "{{ get_set(field) }}"
-
-        return r
-
+    def render(self, filename, jinja_environment):
+        template = jinja_environment.get_template(filename)
+        try:
+            rendered_str = template.render(field=self, environment=jinja_environment)
+
+        except jinja2.UndefinedError as e:
+            print("UndefinedError exception: " + str(e))
+        except jinja2.TemplateRuntimeError as e:
+            print("TemplateRuntimeError exception: " + str(e))
+        except jinja2.TemplateAssertionError as e:
+            print("TemplateAssertionError exception: " + str(e))
+        except jinja2.TemplateSyntaxError as e:
+            print("TemplateSyntaxError exception: " + str(e))
+        except jinja2.TemplateError as e:
+            print("TemplateError exception: " + str(e))
+        except Exception as e:
+            print("Template renderer exception: " + str(e))
+        else:
+            return rendered_str
 
 # -----------------------------------------------------------------------------
 
@@ -176,6 +191,15 @@ class FieldBasic(Field):
     def get_default_value(self):
         return self.type_to_default_value[self.descriptor.type]
 
+    def render_get_set(self, jinja_env):
+        return self.render("FieldBasic_GetSet.h", jinja_environment=jinja_env)
+
+    def render_serialize(self, jinja_env):
+        return self.render("FieldBasic_Serialize.h", jinja_environment=jinja_env)
+
+    def render_deserialize(self, jinja_env):
+        return self.render("FieldBasic_Deserialize.h", jinja_environment=jinja_env)
+
 # -----------------------------------------------------------------------------
 
 
@@ -206,6 +230,15 @@ class FieldString(Field):
         self.parent.scope.register_template_parameters(self)
         return True
 
+    def render_get_set(self, jinja_env):
+        return self.render("FieldString_GetSet.h", jinja_environment=jinja_env)
+
+    def render_serialize(self, jinja_env):
+        return self.render("FieldRepeated_Serialize.h", jinja_environment=jinja_env)
+
+    def render_deserialize(self, jinja_env):
+        return self.render("FieldBasic_Deserialize.h", jinja_environment=jinja_env)
+
 # -----------------------------------------------------------------------------
 
 
@@ -236,6 +269,15 @@ class FieldBytes(Field):
         self.parent.register_child_with_template(self)
         return True
 
+    def render_get_set(self, jinja_env):
+        return self.render("FieldBytes_Bytes.h", jinja_environment=jinja_env)
+
+    def render_serialize(self, jinja_env):
+        return self.render("FieldRepeated_Serialize.h", jinja_environment=jinja_env)
+
+    def render_deserialize(self, jinja_env):
+        return self.render("FieldBasic_Deserialize.h", jinja_environment=jinja_env)
+
 # -----------------------------------------------------------------------------
 
 
@@ -277,6 +319,15 @@ class FieldEnum(Field):
         if not found:
             raise Exception("Unable to match enum type for: " + self.name)
 
+    def render_get_set(self, jinja_env):
+        return self.render("FieldEnum_GetSet.h", jinja_environment=jinja_env)
+
+    def render_serialize(self, jinja_env):
+        return self.render("FieldEnum_Serialize.h", jinja_environment=jinja_env)
+
+    def render_deserialize(self, jinja_env):
+        return self.render("FieldEnum_Deserialize.h", jinja_environment=jinja_env)
+
 # -----------------------------------------------------------------------------
 
 
@@ -305,10 +356,11 @@ class FieldMessage(Field):
             type_name = type_name[:-2]
 
             tmpl_param = self.get_template_parameters()
-            type_name += "<"
-            for param in tmpl_param:
-                type_name += param["name"] + ", "
-            type_name = type_name[:-2] + ">"
+            if tmpl_param:
+                type_name += "<"
+                for param in tmpl_param:
+                    type_name += param["name"] + ", "
+                type_name = type_name[:-2] + ">"
 
         return type_name
 
@@ -356,6 +408,14 @@ class FieldMessage(Field):
     def get_reduced_scope(self):
         return self.get_scope()
 
+    def render_get_set(self, jinja_env):
+        return self.render("FieldMsg_GetSet.h", jinja_environment=jinja_env)
+
+    def render_serialize(self, jinja_env):
+        return self.render("FieldMsg_Serialize.h", jinja_environment=jinja_env)
+
+    def render_deserialize(self, jinja_env):
+        return self.render("FieldMsg_Deserialize.h", jinja_environment=jinja_env)
 
 # -----------------------------------------------------------------------------
 
@@ -393,3 +453,12 @@ class FieldRepeated(Field):
     def register_template_parameters(self):
         self.parent.register_child_with_template(self)
         return True
+
+    def render_get_set(self, jinja_env):
+        return self.render("FieldRepeated_GetSet.h", jinja_environment=jinja_env)
+
+    def render_serialize(self, jinja_env):
+        return self.render("FieldRepeated_Serialize.h", jinja_environment=jinja_env)
+
+    def render_deserialize(self, jinja_env):
+        return self.render("FieldBasic_Deserialize.h", jinja_environment=jinja_env)

+ 3 - 0
generator/support/TypeDefinitions.py

@@ -104,6 +104,9 @@ class TypeDefinition:
         self.scope = Scope(self.name, parent_scope)
         self.template_file = template_filename
 
+    def get_name(self):
+        return self.name
+
     def render(self, jinja_environment):
         template = jinja_environment.get_template(self.template_file)
         try:

+ 1 - 1
generator/templates/FieldBasic.h

@@ -1,4 +1,4 @@
-{#
+FieldBasic.h{#
 Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
 
 This file is part of Embedded Proto.

+ 44 - 0
generator/templates/FieldBasic_Deserialize.h

@@ -0,0 +1,44 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+if(::EmbeddedProto::WireFormatter::WireType::{{field.get_wire_type_str()}} == wire_type)
+{
+  return_value = {{field.get_variable_name()}}.deserialize(buffer);
+  {% if field.which_oneof is defined %}
+  if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+  {
+    {{field.which_oneof}} = id::{{field.get_variable_id_name()}};
+  }
+  {% endif %}
+}
+else
+{
+  // Wire type does not match field.
+  return_value = ::EmbeddedProto::Error::INVALID_WIRETYPE;
+}

+ 34 - 0
generator/templates/FieldBasic_GetSet.h

@@ -0,0 +1,34 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+inline void clear_{{field.get_name()}}() { {{field.get_variable_name()}}.clear(); }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}& value) { {{field.get_variable_name()}} = value; }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}&& value) { {{field.get_variable_name()}} = value; }
+inline {{field.get_type()}}& mutable_{{field.get_name()}}() { return {{field.get_variable_name()}}; }
+inline const {{field.get_type()}}& get_{{field.get_name()}}() const { return {{field.get_variable_name()}}; }

+ 33 - 0
generator/templates/FieldBasic_Serialize.h

@@ -0,0 +1,33 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+if(({{field.get_default_value()}} != {{field.get_variable_name()}}.get()) && (::EmbeddedProto::Error::NO_ERRORS == return_value))
+{
+  return_value = {{field.get_variable_name()}}.serialize_with_id(static_cast<uint32_t>(id::{{field.get_variable_id_name()}}), buffer);
+}

+ 34 - 0
generator/templates/FieldBytes_GetSet.h

@@ -0,0 +1,34 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+inline void clear_{{field.get_name()}}() { {{field.get_variable_name()}}.clear(); }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}& value) { {{field.get_variable_name()}} = value; }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}&& value) { {{field.get_variable_name()}} = value; }
+inline {{field.get_type()}}& mutable_{{field.get_name()}}() { return {{field.get_variable_name()}}; }
+inline const {{field.get_type()}}& get_{{field.get_name()}}() const { return {{field.get_variable_name()}}; }

+ 49 - 0
generator/templates/FieldEnum_Deserialize.h

@@ -0,0 +1,49 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+if(::EmbeddedProto::WireFormatter::WireType::{{field.get_wire_type_str()}} == wire_type)
+{
+  uint32_t value;
+  return_value = ::EmbeddedProto::WireFormatter::DeserializeVarint(buffer, value);
+  if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+  {
+    set_{{field.get_name()}}(static_cast<{{field.get_type()}}>(value));
+  }
+  {% if field.which_oneof is defined %}
+  if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+  {
+    {{field.which_oneof}} = id::{{field.get_variable_id_name()}};
+  }
+  {% endif %}
+}
+else
+{
+  // Wire type does not match field.
+  return_value = ::EmbeddedProto::Error::INVALID_WIRETYPE;
+}

+ 34 - 0
generator/templates/FieldEnum_GetSet.h

@@ -0,0 +1,34 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+inline void clear_{{field.get_name()}}() { {{field.get_variable_name()}} = {{field.get_default_value()}}; }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}& value) { {{field.get_variable_name()}} = value; }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}&& value) { {{field.get_variable_name()}} = value; }
+inline {{field.get_type()}}& mutable_{{field.get_name()}}() { return {{field.get_variable_name()}}; }
+inline const {{field.get_type()}}& get_{{field.get_name()}}() const { return {{field.get_variable_name()}}; }

+ 35 - 0
generator/templates/FieldEnum_Serialize.h

@@ -0,0 +1,35 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+if(({{field.get_default_value()}} != {{field.get_variable_name()}}) && (::EmbeddedProto::Error::NO_ERRORS == return_value))
+{
+  EmbeddedProto::uint32 value;
+  value.set(static_cast<uint32_t>({{field.get_variable_name()}}));
+  return_value = value.serialize_with_id(static_cast<uint32_t>(id::{{field.get_variable_id_name()}}), buffer);
+}

+ 50 - 0
generator/templates/FieldMsg_Deserialize.h

@@ -0,0 +1,50 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+if(::EmbeddedProto::WireFormatter::WireType::{{field.get_wire_type_str()}} == wire_type)
+{
+  uint32_t size;
+  return_value = ::EmbeddedProto::WireFormatter::DeserializeVarint(buffer, size);
+  ::EmbeddedProto::ReadBufferSection bufferSection(buffer, size);
+  if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+  {
+    return_value = mutable_{{field.get_name()}}().deserialize(bufferSection);
+  }
+  {% if field.which_oneof is defined %}
+  if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+  {
+    {{field.which_oneof}} = id::{{field.get_variable_id_name()}};
+  }
+  {% endif %}
+}
+else
+{
+  // Wire type does not match field.
+  return_value = ::EmbeddedProto::Error::INVALID_WIRETYPE;
+}

+ 34 - 0
generator/templates/FieldMsg_GetSet.h

@@ -0,0 +1,34 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+inline void clear_{{field.get_name()}}() { {{field.get_variable_name()}}.clear(); }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}& value) { {{field.get_variable_name()}} = value; }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}&& value) { {{field.get_variable_name()}} = value; }
+inline {{field.get_type()}}& mutable_{{field.get_name()}}() { return {{field.get_variable_name()}}; }
+inline const {{field.get_type()}}& get_{{field.get_name()}}() const { return {{field.get_variable_name()}}; }

+ 33 - 0
generator/templates/FieldMsg_Serialize.h

@@ -0,0 +1,33 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+{
+  return_value = {{field.get_variable_name()}}.serialize_with_id(static_cast<uint32_t>(id::{{field.get_variable_id_name()}}), buffer);
+}

+ 34 - 0
generator/templates/FieldRepeated_GetSet.h

@@ -0,0 +1,34 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+inline void clear_{{field.get_name()}}() { {{field.get_variable_name()}}.clear(); }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}& value) { {{field.get_variable_name()}} = value; }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}&& value) { {{field.get_variable_name()}} = value; }
+inline {{field.get_type()}}& mutable_{{field.get_name()}}() { return {{field.get_variable_name()}}; }
+inline const {{field.get_type()}}& get_{{field.get_name()}}() const { return {{field.get_variable_name()}}; }

+ 33 - 0
generator/templates/FieldRepeated_Serialize.h

@@ -0,0 +1,33 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+{
+  return_value = {{field.get_variable_name()}}.serialize_with_id(static_cast<uint32_t>(id::{{field.get_variable_id_name()}}), buffer);
+}

+ 34 - 0
generator/templates/FieldString_GetSet.h

@@ -0,0 +1,34 @@
+{#
+Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
+
+This file is part of Embedded Proto.
+
+Embedded Proto is open source software: you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published
+by the Free Software Foundation, version 3 of the license.
+
+Embedded Proto  is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
+
+For commercial and closed source application please visit:
+<https://EmbeddedProto.com/license/>.
+
+Embedded AMS B.V.
+Info:
+  info at EmbeddedProto dot com
+
+Postal address:
+  Johan Huizingalaan 763a
+  1066 VH, Amsterdam
+  the Netherlands
+#}
+inline void clear_{{field.get_name()}}() { {{field.get_variable_name()}}.clear(); }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}& value) { {{field.get_variable_name()}} = value; }
+inline void set_{{field.get_name()}}(const {{field.get_type()}}&& value) { {{field.get_variable_name()}} = value; }
+inline {{field.get_type()}}& mutable_{{field.get_name()}}() { return {{field.get_variable_name()}}; }
+inline const {{field.get_type()}}& get_{{field.get_name()}}() const { return {{field.get_variable_name()}}; }

+ 93 - 6
generator/templates/TypeDefMsg.h

@@ -31,13 +31,13 @@ Postal address:
 {% for tmpl_param in typedef.get_templates() %}
 {{"template<" if loop.first}}{{tmpl_param['type']}} {{tmpl_param['name']}}{{", " if not loop.last}}{{">" if loop.last}}
 {% endfor %}
-class {{ typedef.name }} final: public ::EmbeddedProto::MessageInterface
+class {{ typedef.get_name() }} final: public ::EmbeddedProto::MessageInterface
 {
   public:
-    {{ typedef.name }}(){% if (typedef.fields or typedef.oneofs) %} :
+    {{ typedef.get_name() }}(){% if (typedef.fields or typedef.oneofs) %} :
     {% endif %}
     {% for field in typedef.fields %}
-        {{field.variable_name}}({{field.get_default_value()}}){{"," if not loop.last}}{{"," if loop.last and typedef.oneofs}}
+        {{field.get_variable_name()}}({{field.get_default_value()}}){{"," if not loop.last}}{{"," if loop.last and typedef.oneofs}}
     {% endfor %}
     {% for oneof in typedef.oneofs %}
         {{oneof.which_oneof}}(id::NOT_SET){{"," if not loop.last}}
@@ -45,7 +45,7 @@ class {{ typedef.name }} final: public ::EmbeddedProto::MessageInterface
     {
 
     };
-    ~{{ typedef.name }}() override = default;
+    ~{{ typedef.get_name() }}() override = default;
 
     {% for enum in typedef.nested_enum_definitions %}
     {{ enum.render(environment)|indent(4) }}
@@ -66,7 +66,7 @@ class {{ typedef.name }} final: public ::EmbeddedProto::MessageInterface
     {{ typedef.name }}& operator=(const {{ typedef.name }}& rhs)
     {
       {% for field in typedef.fields %}
-      set_{{ field.name }}(rhs.get_{{ field.name }}());
+      set_{{ field.get_name() }}(rhs.get_{{ field.get_name() }}());
       {% endfor %}
       {% for oneof in typedef.oneofs %}
       {{ TypeOneof.assign(oneof)|indent(6) }}
@@ -77,11 +77,98 @@ class {{ typedef.name }} final: public ::EmbeddedProto::MessageInterface
 
     {% for field in typedef.fields %}
     {{ field.render_get_set(environment)|indent(4) }}
+
     {% endfor %}
 
+    ::EmbeddedProto::Error serialize(::EmbeddedProto::WriteBufferInterface& buffer) const final
+    {
+      ::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
+
+      {% for field in typedef.fields %}
+      {{ field.render_serialize(environment)|indent(6) }}
+
+      {% endfor %}
+      {% for oneof in typedef.oneofs %}
+      switch({{oneof.which_oneof}})
+      {
+        {% for field in oneof.fields() %}
+        case id::{{field.variable_id_name}}:
+          {{ field_serialize_macro(field)|indent(12) }}
+          break;
+
+        {% endfor %}
+        default:
+          break;
+      }
+
+      {% endfor %}
+      return return_value;
+    };
+
+    ::EmbeddedProto::Error deserialize(::EmbeddedProto::ReadBufferInterface& buffer) final
+    {
+      ::EmbeddedProto::Error return_value = ::EmbeddedProto::Error::NO_ERRORS;
+      ::EmbeddedProto::WireFormatter::WireType wire_type;
+      uint32_t id_number = 0;
+
+      ::EmbeddedProto::Error tag_value = ::EmbeddedProto::WireFormatter::DeserializeTag(buffer, wire_type, id_number);
+      while((::EmbeddedProto::Error::NO_ERRORS == return_value) && (::EmbeddedProto::Error::NO_ERRORS == tag_value))
+      {
+        switch(id_number)
+        {
+          {% for field in typedef.fields %}
+          case static_cast<uint32_t>(id::{{field.get_variable_id_name()}}):
+          {
+            {{ field.render_deserialize(environment)|indent(12) }}
+            break;
+          }
+
+          {% endfor %}
+{#        {% for oneof in typedef.oneofs %}
+          {% for field in oneof.fields() %}
+          case static_cast<uint32_t>(id::{{field.get_variable_id_name()}}):
+          {
+            {{ field_deserialize_macro(field)|indent(12) }}
+            break;
+          }
+
+          {% endfor %}
+          {% endfor %} #}
+          default:
+            break;
+        }
+
+        if(::EmbeddedProto::Error::NO_ERRORS == return_value)
+        {
+            // Read the next tag.
+            tag_value = ::EmbeddedProto::WireFormatter::DeserializeTag(buffer, wire_type, id_number);
+        }
+      }
+
+      // When an error was detect while reading the tag but no other errors where found, set it in the return value.
+      if((::EmbeddedProto::Error::NO_ERRORS == return_value)
+         && (::EmbeddedProto::Error::NO_ERRORS != tag_value)
+         && (::EmbeddedProto::Error::END_OF_BUFFER != tag_value)) // The end of the buffer is not an array in this case.
+      {
+        return_value = tag_value;
+      }
+
+      return return_value;
+    };
+
+    void clear() final
+    {
+      {% for field in typedef.fields %}
+      clear_{{field.get_name()}}();
+      {% endfor %}
+      {% for oneof in typedef.oneofs %}
+      clear_{{oneof.name}}();
+      {% endfor %}
+    }
+
     private:
 
       {% for field in typedef.fields %}
-      {{field.get_type()}} {{field.variable_name}};
+      {{field.get_type()}} {{field.get_variable_name()}};
       {% endfor %}
 };