ores.cpp.wire-codec.codec_impl

Table of Contents

States the type's members as a list of ores::utility::codec::field, and defines the four wire functions over it.

The list is the whole of the encoding: object::write_json writes an object whose keys are the fields' names in the order the list states them, and object::read_json reads each one back by name. A field's own form is the carrier's for its member's type, so a string, a number, a truth value, an instance, a decimal and a uuid need nothing here.

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

1. Template

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

{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.wire-codec.org. Edit the org source. }}
{{{cpp_license}}}
{{#domain_entity}}
#include "ores.{{component_include}}/domain/{{entity_singular}}_codec.hpp"

#include "ores.utility/codec/struct_codec.hpp"
{{#wire_codec_includes}}
#include "{{{.}}}"
{{/wire_codec_includes}}

namespace ores::utility::codec {

std::string wire_traits<ores::{{component}}::domain::{{entity_singular}}>::write_json(const ores::{{component}}::domain::{{entity_singular}}& v) {
    return object::write_json(v);
}

ores::{{component}}::domain::{{entity_singular}} wire_traits<ores::{{component}}::domain::{{entity_singular}}>::read_json(std::string_view text) {
    return object::read_json<ores::{{component}}::domain::{{entity_singular}}>(text);
}

std::string wire_traits<ores::{{component}}::domain::{{entity_singular}}>::write_msgpack(const ores::{{component}}::domain::{{entity_singular}}& v) {
    return object::write_msgpack(v);
}

ores::{{component}}::domain::{{entity_singular}} wire_traits<ores::{{component}}::domain::{{entity_singular}}>::read_msgpack(std::span<const std::byte> data) {
    return object::read_msgpack<ores::{{component}}::domain::{{entity_singular}}>(data);
}

}

{{/domain_entity}}
{{#junction}}
#include "ores.{{component_include}}/domain/{{name_singular}}_codec.hpp"

#include "ores.utility/codec/struct_codec.hpp"

namespace ores::{{component}}::domain {

}

namespace ores::utility::codec {

std::string wire_traits<ores::{{component}}::domain::{{name_singular}}>::write_json(const ores::{{component}}::domain::{{name_singular}}& v) {
    return object::write_json(v);
}

ores::{{component}}::domain::{{name_singular}} wire_traits<ores::{{component}}::domain::{{name_singular}}>::read_json(std::string_view text) {
    return object::read_json<ores::{{component}}::domain::{{name_singular}}>(text);
}

std::string wire_traits<ores::{{component}}::domain::{{name_singular}}>::write_msgpack(const ores::{{component}}::domain::{{name_singular}}& v) {
    return object::write_msgpack(v);
}

ores::{{component}}::domain::{{name_singular}} wire_traits<ores::{{component}}::domain::{{name_singular}}>::read_msgpack(std::span<const std::byte> data) {
    return object::read_msgpack<ores::{{component}}::domain::{{name_singular}}>(data);
}

}


{{/junction}}

2. See also

Emacs 29.3 (Org mode 9.6.15)