[Yunq] Add support for repeated nested fields

This commit is contained in:
Drew Galbraith 2024-01-11 22:09:42 -08:00
parent 05f2403dc2
commit 9c860dd6a4
14 changed files with 207 additions and 61 deletions

View file

@ -20,7 +20,8 @@ class {{message.name}} {
{{message.name}}() {}
// Delete copy and move until implemented.
{{message.name}}(const {{message.name}}&) = delete;
{{message.name}}({{message.name}}&&) = delete;
{{message.name}}({{message.name}}&&) = default;
{{message.name}}& operator=({{message.name}}&&) = default;
[[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message);
[[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer&);
@ -28,19 +29,24 @@ class {{message.name}} {
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
{%- for field in message.fields %}
{%- if field.type == Type.MESSAGE %}
{%- if not field.repeated %}
const {{field.cpp_type()}}& {{field.name}}() const { return {{field.name}}_; }
{{field.cpp_type()}}& mutable_{{field.name}}() { return {{field.name}}_; }
{%- if field.type != Type.MESSAGE %}
void set_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_ = value; }
{%- endif %}
{%- else %}
{%- if not field.repeated %}
const {{field.cpp_type()}}& {{field.name}}() const { return {{field.name}}_; }
void set_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_ = value; }
{%- else %}
const glcr::Vector<{{field.cpp_type()}}>& {{field.name}}() const { return {{field.name}}_; }
glcr::Vector<{{field.cpp_type()}}>& mutable_{{field.name}}() { return {{field.name}}_; }
{%- if field.type != Type.MESSAGE %}
void add_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_.PushBack(value); }
{%- endif %}
void add_{{field.name}}({{field.cpp_type()}}&& value) { {{field.name}}_.PushBack(glcr::Move(value)); }
{%- endif %}
{%- endfor %}