Archetype: cpp_protocol.hpp.mustache

Table of Contents

Request/response message types for the entity's NATS API. protocol profile. NATS messaging contract: request and response message structs used by the service layer for inter-component communication.

See the Template variable reference for the complete list of available variables and their semantics.

Template

The full template source. Edit here and re-tangle with compass build --direct tangle_codegen_templates to regenerate library/templates/cpp_protocol.hpp.mustache.

{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/cpp_messaging.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#ifndef ORES_{{component_include_upper}}_MESSAGING_{{entity_singular_upper}}_PROTOCOL_HPP
#define ORES_{{component_include_upper}}_MESSAGING_{{entity_singular_upper}}_PROTOCOL_HPP

#include <cstdint>
#include <string>
#include <vector>
#include "ores.{{component_include}}/domain/{{entity_singular}}.hpp"

namespace ores::{{component}}::messaging {

struct get_{{entity_plural}}_request {
    using response_type = struct get_{{entity_plural}}_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.list";
    std::uint32_t offset = 0;
    std::uint32_t limit = 100;
{{#list_filter_column}}
    std::string {{list_filter_column}};
{{/list_filter_column}}
};

struct get_{{entity_plural}}_response {
    std::vector<ores::{{component}}::domain::{{entity_singular}}> {{entity_plural_short}};
    int total_available_count = 0;
    bool success = false;
    std::string message;
};

struct save_{{entity_singular}}_request {
    using response_type = struct save_{{entity_singular}}_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.save";
    ores::{{component}}::domain::{{entity_singular}} data;

    static save_{{entity_singular}}_request from(ores::{{component}}::domain::{{entity_singular}} v) {
        return {.data = std::move(v)};
    }
};

struct save_{{entity_singular}}_response {
    bool success = false;
    std::string message;
};

struct delete_{{entity_singular}}_request {
    using response_type = struct delete_{{entity_singular}}_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.delete";
{{#primary_key.is_text}}
    std::vector<std::string> {{primary_key.column}}s;
{{/primary_key.is_text}}
{{#primary_key.is_uuid}}
    std::vector<std::string> ids;
{{/primary_key.is_uuid}}
};

struct delete_{{entity_singular}}_response {
    bool success = false;
    std::string message;
};

struct get_{{entity_singular}}_history_request {
    using response_type = struct get_{{entity_singular}}_history_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.history";
{{#primary_key.is_text}}
    std::string {{primary_key.column}};
{{/primary_key.is_text}}
{{#primary_key.is_uuid}}
    std::string {{primary_key.column}};
{{/primary_key.is_uuid}}
};

struct get_{{entity_singular}}_history_response {
    std::vector<ores::{{component}}::domain::{{entity_singular}}> history;
    bool success = false;
    std::string message;
};

{{#extra_list_requests}}
struct get_{{entity_plural}}_{{name_suffix}}_request {
    using response_type = struct get_{{entity_plural}}_{{name_suffix}}_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.{{nats_suffix}}";
    std::string {{filter_column}};
};

struct get_{{entity_plural}}_{{name_suffix}}_response {
    std::vector<ores::{{component}}::domain::{{entity_singular}}> {{entity_plural_short}};
    bool success = false;
    std::string message;
};

{{/extra_list_requests}}
}

#endif
{{/domain_entity}}
{{#entity}}
#ifndef ORES_{{component_include_upper}}_MESSAGING_{{entity_singular_upper}}_PROTOCOL_HPP
#define ORES_{{component_include_upper}}_MESSAGING_{{entity_singular_upper}}_PROTOCOL_HPP

#include <cstdint>
#include <string>
#include <vector>
#include "ores.{{component_include}}/domain/{{entity_singular}}.hpp"

namespace ores::{{component}}::messaging {

struct get_{{entity_plural}}_request {
    using response_type = struct get_{{entity_plural}}_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.list";
    std::uint32_t offset = 0;
    std::uint32_t limit = 100;
{{#list_filter_column}}
    std::string {{list_filter_column}};
{{/list_filter_column}}
};

struct get_{{entity_plural}}_response {
    std::vector<ores::{{component}}::domain::{{entity_singular}}> {{entity_plural_short}};
    int total_available_count = 0;
    bool success = false;
    std::string message;
};

struct save_{{entity_singular}}_request {
    using response_type = struct save_{{entity_singular}}_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.save";
    ores::{{component}}::domain::{{entity_singular}} data;

    static save_{{entity_singular}}_request from(ores::{{component}}::domain::{{entity_singular}} v) {
        return {.data = std::move(v)};
    }
};

struct save_{{entity_singular}}_response {
    bool success = false;
    std::string message;
};

struct delete_{{entity_singular}}_request {
    using response_type = struct delete_{{entity_singular}}_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.delete";
{{#primary_key.is_text}}
    std::vector<std::string> {{primary_key.column}}s;
{{/primary_key.is_text}}
{{^primary_key.is_text}}
    std::vector<std::string> ids;
{{/primary_key.is_text}}
};

struct delete_{{entity_singular}}_response {
    bool success = false;
    std::string message;
};

struct get_{{entity_singular}}_history_request {
    using response_type = struct get_{{entity_singular}}_history_response;
    static constexpr std::string_view nats_subject =
        "{{component}}.v1.{{entity_plural}}.history";
    std::string {{primary_key.column}};
};

struct get_{{entity_singular}}_history_response {
    std::vector<ores::{{component}}::domain::{{entity_singular}}> history;
    bool success = false;
    std::string message;
};

}

#endif
{{/entity}}

See also

Emacs 29.1 (Org mode 9.6.6)