|
|
@@ -7,7 +7,210 @@ enum {{ _enum.name }}
|
|
|
};
|
|
|
|
|
|
{% endmacro %}
|
|
|
-
|
|
|
+{# #}
|
|
|
+{# ------------------------------------------------------------------------------------------------------------------ #}
|
|
|
+{# #}
|
|
|
+{% macro field_get_set_macro(_field) %}
|
|
|
+{% if _field.is_repeated_field %}
|
|
|
+inline const {{_field.type}}& {{_field.name}}(uint32_t index) const { return {{_field.variable_full_name}}[index]; }
|
|
|
+{% if _field.which_oneof is defined %}
|
|
|
+inline void clear_{{_field.name}}()
|
|
|
+{
|
|
|
+ if(id::{{_field.variable_id_name}} == {{_field.which_oneof}})
|
|
|
+ {
|
|
|
+ {{_field.which_oneof}} = id::NOT_SET;
|
|
|
+ {{_field.variable_full_name}}.clear();
|
|
|
+ }
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(uint32_t index, const {{_field.type}}& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}}.set(index, value);
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(uint32_t index, const {{_field.type}}&& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}}.set(index, value);
|
|
|
+}
|
|
|
+inline void add_{{_field.name}}(const {{_field.type}}& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}}.add(value);
|
|
|
+}
|
|
|
+inline {{_field.repeated_type}}& mutable_{{_field.name}}()
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ return {{_field.variable_full_name}};
|
|
|
+}
|
|
|
+{% else %}
|
|
|
+inline void clear_{{_field.name}}() { {{_field.variable_full_name}}.clear(); }
|
|
|
+inline void set_{{_field.name}}(uint32_t index, const {{_field.type}}& value) { {{_field.variable_full_name}}.set(index, value); }
|
|
|
+inline void set_{{_field.name}}(uint32_t index, const {{_field.type}}&& value) { {{_field.variable_full_name}}.set(index, value); }
|
|
|
+inline void add_{{_field.name}}(const {{_field.type}}& value) { {{_field.variable_full_name}}.add(value); }
|
|
|
+inline {{_field.repeated_type}}& mutable_{{_field.name}}() { return {{_field.variable_full_name}}; }
|
|
|
+{% endif %}
|
|
|
+inline const {{_field.repeated_type}}& get_{{_field.name}}() const { return {{_field.variable_full_name}}; }
|
|
|
+{% elif _field.of_type_message %}
|
|
|
+inline const {{_field.type}}& {{_field.name}}() const { return {{_field.variable_full_name}}; }
|
|
|
+{% if _field.which_oneof is defined %}
|
|
|
+inline void clear_{{_field.name}}()
|
|
|
+{
|
|
|
+ if(id::{{_field.variable_id_name}} == {{_field.which_oneof}})
|
|
|
+ {
|
|
|
+ {{_field.which_oneof}} = id::NOT_SET;
|
|
|
+ {{_field.variable_full_name}}.clear();
|
|
|
+ }
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}} = value;
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}&& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}} = value;
|
|
|
+}
|
|
|
+inline {{_field.type}}& mutable_{{_field.name}}()
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ return {{_field.variable_full_name}};
|
|
|
+}
|
|
|
+{% else %}
|
|
|
+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}}; }
|
|
|
+{% endif %}
|
|
|
+inline const {{_field.type}}& get_{{_field.name}}() const { return {{_field.variable_full_name}}; }
|
|
|
+{% elif _field.of_type_enum %}
|
|
|
+inline {{_field.type}} {{_field.name}}() const { return {{_field.variable_full_name}}; }
|
|
|
+{% if _field.which_oneof is defined %}
|
|
|
+inline void clear_{{_field.name}}()
|
|
|
+{
|
|
|
+ if(id::{{_field.variable_id_name}} == {{_field.which_oneof}})
|
|
|
+ {
|
|
|
+ {{_field.which_oneof}} = id::NOT_SET;
|
|
|
+ {{_field.variable_full_name}} = static_cast<{{_field.type}}>({{_field.default_value}});
|
|
|
+ }
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}} = value;
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}&& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}} = value;
|
|
|
+}
|
|
|
+{% else %}
|
|
|
+inline void clear_{{_field.name}}() { {{_field.variable_full_name}} = static_cast<{{_field.type}}>({{_field.default_value}}); }
|
|
|
+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; }
|
|
|
+{% endif %} inline {{_field.type}} get_{{_field.name}}() const { return {{_field.variable_full_name}}; }
|
|
|
+{% else %}
|
|
|
+inline {{_field.type}}::FIELD_TYPE {{_field.name}}() const { return {{_field.variable_full_name}}.get(); }
|
|
|
+{% if _field.which_oneof is defined %}
|
|
|
+inline void clear_{{_field.name}}()
|
|
|
+{
|
|
|
+ if(id::{{_field.variable_id_name}} == {{_field.which_oneof}})
|
|
|
+ {
|
|
|
+ {{_field.which_oneof}} = id::NOT_SET;
|
|
|
+ {{_field.variable_full_name}}.set({{_field.default_value}});
|
|
|
+ }
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}::FIELD_TYPE& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}}.set(value);
|
|
|
+}
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}::FIELD_TYPE&& value)
|
|
|
+{
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {{_field.variable_full_name}}.set(value);
|
|
|
+}
|
|
|
+{% else %}
|
|
|
+inline void clear_{{_field.name}}() { {{_field.variable_full_name}}.set({{_field.default_value}}); }
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}::FIELD_TYPE& value) { {{_field.variable_full_name}}.set(value); }
|
|
|
+inline void set_{{_field.name}}(const {{_field.type}}::FIELD_TYPE&& value) { {{_field.variable_full_name}}.set(value); }
|
|
|
+{% endif %}
|
|
|
+inline {{_field.type}}::FIELD_TYPE get_{{_field.name}}() const { return {{_field.variable_full_name}}.get(); }
|
|
|
+{% endif %}
|
|
|
+{% endmacro %}
|
|
|
+{# #}
|
|
|
+{# ------------------------------------------------------------------------------------------------------------------ #}
|
|
|
+{# #}
|
|
|
+{% macro field_serialize_macro(_field) %}
|
|
|
+{% if _field.is_repeated_field %}
|
|
|
+if(result)
|
|
|
+{
|
|
|
+ result = {{_field.variable_full_name}}.serialize(static_cast<uint32_t>(id::{{_field.variable_id_name}}), buffer);
|
|
|
+}
|
|
|
+{% elif _field.of_type_message %}
|
|
|
+if(result)
|
|
|
+{
|
|
|
+ const ::EmbeddedProto::MessageInterface* x = &{{_field.variable_full_name}};
|
|
|
+ result = x->serialize(static_cast<uint32_t>(id::{{_field.variable_id_name}}), buffer);
|
|
|
+}
|
|
|
+{% elif _field.of_type_enum %}
|
|
|
+if(({{_field.default_value}} != {{_field.variable_full_name}}) && result)
|
|
|
+{
|
|
|
+ EmbeddedProto::uint32 value;
|
|
|
+ value.set(static_cast<uint32_t>({{_field.variable_full_name}}));
|
|
|
+ result = value.serialize(static_cast<uint32_t>(id::{{_field.variable_id_name}}), buffer);
|
|
|
+}
|
|
|
+{% else %}
|
|
|
+if(({{_field.default_value}} != {{_field.variable_full_name}}.get()) && result)
|
|
|
+{
|
|
|
+ result = {{_field.variable_full_name}}.serialize(static_cast<uint32_t>(id::{{_field.variable_id_name}}), buffer);
|
|
|
+} {% endif %} {% endmacro %}
|
|
|
+{# #}
|
|
|
+{# ------------------------------------------------------------------------------------------------------------------ #}
|
|
|
+{# #}
|
|
|
+{% macro field_deserialize_macro(_field) %}
|
|
|
+{% if _field.is_repeated_field %}
|
|
|
+if(::EmbeddedProto::WireFormatter::WireType::LENGTH_DELIMITED == wire_type)
|
|
|
+{
|
|
|
+ result = {{_field.variable_full_name}}.deserialize(buffer);
|
|
|
+}
|
|
|
+{% else %}
|
|
|
+if(::EmbeddedProto::WireFormatter::WireType::{{_field.wire_type}} == wire_type)
|
|
|
+{
|
|
|
+ {% if _field.of_type_message %}
|
|
|
+ uint32_t size;
|
|
|
+ result = ::EmbeddedProto::WireFormatter::DeserializeVarint(buffer, size);
|
|
|
+ ::EmbeddedProto::ReadBufferSection bufferSection(buffer, size);
|
|
|
+ result = result && {{_field.variable_full_name}}.deserialize(bufferSection);
|
|
|
+ {% elif _field.of_type_enum %}
|
|
|
+ uint32_t value;
|
|
|
+ result = ::EmbeddedProto::WireFormatter::DeserializeVarint(buffer, value);
|
|
|
+ if(result)
|
|
|
+ {
|
|
|
+ {{_field.variable_full_name}} = static_cast<{{_field.type}}>(value);
|
|
|
+ {% if _field.which_oneof is defined %}
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ {% endif %}
|
|
|
+ }
|
|
|
+ {% else %}
|
|
|
+ result = {{_field.variable_full_name}}.deserialize(buffer);
|
|
|
+ {% if _field.which_oneof is defined %}
|
|
|
+ if(result)
|
|
|
+ {
|
|
|
+ {{_field.which_oneof}} = id::{{_field.variable_id_name}};
|
|
|
+ }
|
|
|
+ {% endif %}
|
|
|
+ {% endif %}
|
|
|
+}
|
|
|
+{% endif %}
|
|
|
+else
|
|
|
+{
|
|
|
+ // TODO Error wire type does not match field.
|
|
|
+ result = false;
|
|
|
+} {% endmacro %}
|
|
|
+{# #}
|
|
|
+{# ------------------------------------------------------------------------------------------------------------------ #}
|
|
|
+{# #}
|
|
|
{% macro msg_macro(msg) %}
|
|
|
{% if msg.templates is defined %}
|
|
|
{% for template in msg.templates %}
|
|
|
@@ -20,11 +223,14 @@ class {{ msg.name }} final: public ::EmbeddedProto::MessageInterface
|
|
|
{{ msg.name }}() :
|
|
|
{% for field in msg.fields() %}
|
|
|
{% if field.of_type_enum %}
|
|
|
- {{field.variable_name}}({{field.default_value}}){{"," if not loop.last}}
|
|
|
+ {{field.variable_full_name}}({{field.default_value}}){{"," if not loop.last}}
|
|
|
{% else %}
|
|
|
- {{field.variable_name}}(){{"," if not loop.last}}
|
|
|
+ {{field.variable_full_name}}(){{"," if not loop.last}}{{"," if loop.last and msg.has_oneofs}}
|
|
|
{% endif %}
|
|
|
{% endfor %}
|
|
|
+ {% for oneof in msg.oneofs() %}
|
|
|
+ {{oneof.which_oneof}}(id::NOT_SET){{"," if not loop.last}}
|
|
|
+ {% endfor %}
|
|
|
{
|
|
|
|
|
|
};
|
|
|
@@ -34,67 +240,44 @@ class {{ msg.name }} final: public ::EmbeddedProto::MessageInterface
|
|
|
{{ enum_macro(enum) }}
|
|
|
|
|
|
{% endfor %}
|
|
|
+ enum class id
|
|
|
+ {
|
|
|
+ NOT_SET = 0,
|
|
|
+ {% for id_set in msg.field_ids %}
|
|
|
+ {{id_set[1]}} = {{id_set[0]}}{{ "," if not loop.last }}
|
|
|
+ {% endfor %}
|
|
|
+ };
|
|
|
+
|
|
|
{% for field in msg.fields() %}
|
|
|
- static const uint32_t {{field.variable_id_name}} = {{field.variable_id}};
|
|
|
- {% if field.is_repeated_field %}
|
|
|
- inline const {{field.type}}& {{field.name}}(uint32_t index) const { return {{field.variable_name}}[index]; }
|
|
|
- inline void clear_{{field.name}}() { {{field.variable_name}}.clear(); }
|
|
|
- inline void set_{{field.name}}(uint32_t index, const {{field.type}}& value) { {{field.variable_name}}.set(index, value); }
|
|
|
- inline void set_{{field.name}}(uint32_t index, const {{field.type}}&& value) { {{field.variable_name}}.set(index, value); }
|
|
|
- inline void add_{{field.name}}(const {{field.type}}& value) { {{field.variable_name}}.add(value); }
|
|
|
- inline const {{field.repeated_type}}& get_{{field.name}}() const { return {{field.variable_name}}; }
|
|
|
- inline {{field.repeated_type}}& mutable_{{field.name}}() { return {{field.variable_name}}; }
|
|
|
- {% elif field.of_type_message %}
|
|
|
- inline const {{field.type}}& {{field.name}}() const { return {{field.variable_name}}; }
|
|
|
- inline void clear_{{field.name}}() { {{field.variable_name}}.clear(); }
|
|
|
- inline void set_{{field.name}}(const {{field.type}}& value) { {{field.variable_name}} = value; }
|
|
|
- inline void set_{{field.name}}(const {{field.type}}&& value) { {{field.variable_name}} = value; }
|
|
|
- inline const {{field.type}}& get_{{field.name}}() const { return {{field.variable_name}}; }
|
|
|
- inline {{field.type}}& mutable_{{field.name}}() { return {{field.variable_name}}; }
|
|
|
- {% elif field.of_type_enum %}
|
|
|
- inline {{field.type}} {{field.name}}() const { return {{field.variable_name}}; }
|
|
|
- inline void clear_{{field.name}}() { {{field.variable_name}} = static_cast<{{field.type}}>({{field.default_value}}); }
|
|
|
- inline void set_{{field.name}}(const {{field.type}}& value) { {{field.variable_name}} = value; }
|
|
|
- inline void set_{{field.name}}(const {{field.type}}&& value) { {{field.variable_name}} = value; }
|
|
|
- inline {{field.type}} get_{{field.name}}() const { return {{field.variable_name}}; }
|
|
|
- {% else %}
|
|
|
- inline {{field.type}}::FIELD_TYPE {{field.name}}() const { return {{field.variable_name}}.get(); }
|
|
|
- inline void clear_{{field.name}}() { {{field.variable_name}}.set({{field.default_value}}); }
|
|
|
- inline void set_{{field.name}}(const {{field.type}}::FIELD_TYPE& value) { {{field.variable_name}}.set(value); }
|
|
|
- inline void set_{{field.name}}(const {{field.type}}::FIELD_TYPE&& value) { {{field.variable_name}}.set(value); }
|
|
|
- inline {{field.type}}::FIELD_TYPE get_{{field.name}}() const { return {{field.variable_name}}.get(); }
|
|
|
- {% endif %}
|
|
|
+ {{ field_get_set_macro(field)|indent(4) }}
|
|
|
+ {% endfor %}
|
|
|
+ {% for oneof in msg.oneofs() %}
|
|
|
+ id get_which_{{oneof.name}}() const { return {{oneof.which_oneof}}; }
|
|
|
|
|
|
+ {% for field in oneof.fields() %}
|
|
|
+ {{ field_get_set_macro(field)|indent(4) }}
|
|
|
+ {% endfor %}
|
|
|
{% endfor %}
|
|
|
bool serialize(::EmbeddedProto::WriteBufferInterface& buffer) const final
|
|
|
{
|
|
|
bool result = true;
|
|
|
|
|
|
{% for field in msg.fields() %}
|
|
|
- {% if field.is_repeated_field %}
|
|
|
- if(result)
|
|
|
- {
|
|
|
- result = {{field.variable_name}}.serialize({{field.variable_id_name}}, buffer);
|
|
|
- }
|
|
|
- {% elif field.of_type_message %}
|
|
|
- if(result)
|
|
|
- {
|
|
|
- const ::EmbeddedProto::MessageInterface* x = &{{field.variable_name}};
|
|
|
- result = x->serialize({{field.variable_id_name}}, buffer);
|
|
|
- }
|
|
|
- {% elif field.of_type_enum %}
|
|
|
- if(({{field.default_value}} != {{field.variable_name}}) && result)
|
|
|
- {
|
|
|
- EmbeddedProto::uint32 value;
|
|
|
- value.set(static_cast<uint32_t>({{field.variable_name}}));
|
|
|
- result = value.serialize({{field.variable_id_name}}, buffer);
|
|
|
- }
|
|
|
- {% else %}
|
|
|
- if(({{field.default_value}} != {{field.variable_name}}.get()) && result)
|
|
|
+ {{ field_serialize_macro(field)|indent(6) }}
|
|
|
+
|
|
|
+ {% endfor %}
|
|
|
+ {% for oneof in msg.oneofs() %}
|
|
|
+ switch({{oneof.which_oneof}})
|
|
|
{
|
|
|
- result = {{field.variable_name}}.serialize({{field.variable_id_name}}, buffer);
|
|
|
+ {% for field in oneof.fields() %}
|
|
|
+ case id::{{field.variable_id_name}}:
|
|
|
+ {{ field_serialize_macro(field)|indent(12) }}
|
|
|
+ break;
|
|
|
+
|
|
|
+ {% endfor %}
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
- {% endif %}
|
|
|
|
|
|
{% endfor %}
|
|
|
return result;
|
|
|
@@ -111,41 +294,22 @@ class {{ msg.name }} final: public ::EmbeddedProto::MessageInterface
|
|
|
switch(id_number)
|
|
|
{
|
|
|
{% for field in msg.fields() %}
|
|
|
- case {{field.variable_id_name}}:
|
|
|
+ case static_cast<uint32_t>(id::{{field.variable_id_name}}):
|
|
|
+ {
|
|
|
+ {{ field_deserialize_macro(field)|indent(12) }}
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ {% endfor %}
|
|
|
+ {% for oneof in msg.oneofs() %}
|
|
|
+ {% for field in oneof.fields() %}
|
|
|
+ case static_cast<uint32_t>(id::{{field.variable_id_name}}):
|
|
|
{
|
|
|
- {% if field.is_repeated_field %}
|
|
|
- if(::EmbeddedProto::WireFormatter::WireType::LENGTH_DELIMITED == wire_type)
|
|
|
- {
|
|
|
- result = {{field.variable_name}}.deserialize(buffer);
|
|
|
- }
|
|
|
- {% else %}
|
|
|
- if(::EmbeddedProto::WireFormatter::WireType::{{field.wire_type}} == wire_type)
|
|
|
- {
|
|
|
- {% if field.of_type_message %}
|
|
|
- uint32_t size;
|
|
|
- result = ::EmbeddedProto::WireFormatter::DeserializeVarint(buffer, size);
|
|
|
- ::EmbeddedProto::ReadBufferSection bufferSection(buffer, size);
|
|
|
- result = result && {{field.variable_name}}.deserialize(bufferSection);
|
|
|
- {% elif field.of_type_enum %}
|
|
|
- uint32_t value;
|
|
|
- result = ::EmbeddedProto::WireFormatter::DeserializeVarint(buffer, value);
|
|
|
- if(result)
|
|
|
- {
|
|
|
- {{field.variable_name}} = static_cast<{{field.type}}>(value);
|
|
|
- }
|
|
|
- {% else %}
|
|
|
- result = {{field.variable_name}}.deserialize(buffer);
|
|
|
- {% endif %}
|
|
|
- }
|
|
|
- {% endif %}
|
|
|
- else
|
|
|
- {
|
|
|
- // TODO Error wire type does not match field.
|
|
|
- result = false;
|
|
|
- }
|
|
|
+ {{ field_deserialize_macro(field)|indent(12) }}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
+ {% endfor %}
|
|
|
{% endfor %}
|
|
|
default:
|
|
|
break;
|
|
|
@@ -170,8 +334,29 @@ class {{ msg.name }} final: public ::EmbeddedProto::MessageInterface
|
|
|
{{field.type}} {{field.variable_name}};
|
|
|
{% endif %}
|
|
|
{% endfor %}
|
|
|
+
|
|
|
+ {% for oneof in msg.oneofs() %}
|
|
|
+ id {{oneof.which_oneof}};
|
|
|
+ union {{oneof.name}}
|
|
|
+ {
|
|
|
+ {{oneof.name}}() {}
|
|
|
+ ~{{oneof.name}}() {}
|
|
|
+ {% for field in oneof.fields() %}
|
|
|
+ {% if field.is_repeated_field %}
|
|
|
+ {{field.repeated_type}} {{field.variable_name}};
|
|
|
+ {% else %}
|
|
|
+ {{field.type}} {{field.variable_name}};
|
|
|
+ {% endif %}
|
|
|
+ {% endfor %}
|
|
|
+ };
|
|
|
+ {{oneof.name}} {{oneof.name}}_;
|
|
|
+
|
|
|
+ {% endfor %}
|
|
|
};
|
|
|
{% endmacro %}
|
|
|
+{# #}
|
|
|
+{# ------------------------------------------------------------------------------------------------------------------ #}
|
|
|
+{# #}
|
|
|
// This file is generated. Please do not edit!
|
|
|
#ifndef _{{filename.upper()}}_H_
|
|
|
#define _{{filename.upper()}}_H_
|