ores.cpp.wire-codec.protocol_codec_impl
Table of Contents
Defines the four functions of each wire_traits specialisation the protocol
header declares, one message at a time.
The shapes are stated beside the structs in the protocol header, so nothing here repeats a member list: each definition is the object form of the message, and the members' own carriers do the rest. A message that holds a domain type or another message recurses into that type's codec, which is why the protocol header carries the field lists rather than this unit, and why this unit includes the entity's own domain codec: that is the header those field lists are declared in. The envelope's own shapes come from the utility package, which states them beside the structs the same way.
The unit renders only where ores.cpp.protocol renders for the same model,
stated as #+requires_facet:. Its functions define what the protocol header
declares, so a model that turns its protocol off, as an internal table does,
has no header for this unit to include.
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_protocol_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}}/messaging/{{entity_singular}}_protocol.hpp"
{{^family}}
#include "ores.{{component_include}}/domain/{{entity_singular}}_codec.hpp"
{{/family}}
{{#message_codec_includes}}
#include "{{{.}}}"
{{/message_codec_includes}}
#include "ores.utility/codec/struct_codec.hpp"
#include "ores.utility/domain/protocol_codec.hpp"
namespace ores::utility::codec {
{{#messages}}
std::string wire_traits<ores::{{component}}::messaging::{{name}}>::write_json(
const ores::{{component}}::messaging::{{name}}& v) {
return object::write_json(v);
}
ores::{{component}}::messaging::{{name}}
wire_traits<ores::{{component}}::messaging::{{name}}>::read_json(std::string_view text) {
return object::read_json<ores::{{component}}::messaging::{{name}}>(text);
}
std::string wire_traits<ores::{{component}}::messaging::{{name}}>::write_msgpack(
const ores::{{component}}::messaging::{{name}}& v) {
return object::write_msgpack(v);
}
ores::{{component}}::messaging::{{name}}
wire_traits<ores::{{component}}::messaging::{{name}}>::read_msgpack(
std::span<const std::byte> data) {
return object::read_msgpack<ores::{{component}}::messaging::{{name}}>(data);
}
{{/messages}}
}
{{/domain_entity}}
{{#junction}}
#include "ores.{{component_include}}/messaging/{{name_singular}}_protocol.hpp"
#include "ores.{{component_include}}/domain/{{name_singular}}_codec.hpp"
#include "ores.utility/codec/struct_codec.hpp"
#include "ores.utility/domain/protocol_codec.hpp"
namespace ores::utility::codec {
{{#messages}}
std::string wire_traits<ores::{{component}}::messaging::{{name}}>::write_json(
const ores::{{component}}::messaging::{{name}}& v) {
return object::write_json(v);
}
ores::{{component}}::messaging::{{name}}
wire_traits<ores::{{component}}::messaging::{{name}}>::read_json(std::string_view text) {
return object::read_json<ores::{{component}}::messaging::{{name}}>(text);
}
std::string wire_traits<ores::{{component}}::messaging::{{name}}>::write_msgpack(
const ores::{{component}}::messaging::{{name}}& v) {
return object::write_msgpack(v);
}
ores::{{component}}::messaging::{{name}}
wire_traits<ores::{{component}}::messaging::{{name}}>::read_msgpack(
std::span<const std::byte> data) {
return object::read_msgpack<ores::{{component}}::messaging::{{name}}>(data);
}
{{/messages}}
}
{{/junction}}
{{#operation}}
{{#has_generated_wire_codec}}
#include "ores.{{component_include}}/messaging/{{entity_singular}}_protocol.hpp"
{{#message_codec_includes}}
#include "{{{.}}}"
{{/message_codec_includes}}
#include "ores.utility/codec/struct_codec.hpp"
#include "ores.utility/domain/protocol_codec.hpp"
namespace ores::utility::codec {
{{#messages}}
std::string wire_traits<{{namespace}}::{{name}}>::write_json(
const {{namespace}}::{{name}}& v) {
return object::write_json(v);
}
{{namespace}}::{{name}}
wire_traits<{{namespace}}::{{name}}>::read_json(std::string_view text) {
return object::read_json<{{namespace}}::{{name}}>(text);
}
std::string wire_traits<{{namespace}}::{{name}}>::write_msgpack(
const {{namespace}}::{{name}}& v) {
return object::write_msgpack(v);
}
{{namespace}}::{{name}}
wire_traits<{{namespace}}::{{name}}>::read_msgpack(
std::span<const std::byte> data) {
return object::read_msgpack<{{namespace}}::{{name}}>(data);
}
{{/messages}}
}
{{/has_generated_wire_codec}}
{{/operation}}
{{#family}}
{{#has_generated_wire_codec}}
#include "ores.{{component_include}}/messaging/{{entity_singular}}_protocol.hpp"
{{#message_codec_includes}}
#include "{{{.}}}"
{{/message_codec_includes}}
#include "ores.utility/codec/struct_codec.hpp"
#include "ores.utility/domain/protocol_codec.hpp"
namespace ores::utility::codec {
{{#messages}}
std::string wire_traits<ores::{{component}}::messaging::{{name}}>::write_json(
const ores::{{component}}::messaging::{{name}}& v) {
return object::write_json(v);
}
ores::{{component}}::messaging::{{name}}
wire_traits<ores::{{component}}::messaging::{{name}}>::read_json(std::string_view text) {
return object::read_json<ores::{{component}}::messaging::{{name}}>(text);
}
std::string wire_traits<ores::{{component}}::messaging::{{name}}>::write_msgpack(
const ores::{{component}}::messaging::{{name}}& v) {
return object::write_msgpack(v);
}
ores::{{component}}::messaging::{{name}}
wire_traits<ores::{{component}}::messaging::{{name}}>::read_msgpack(
std::span<const std::byte> data) {
return object::read_msgpack<ores::{{component}}::messaging::{{name}}>(data);
}
{{/messages}}
}
{{/has_generated_wire_codec}}
{{/family}}
2. See also
- Parent facet: ores.cpp.wire-codec
- ores.cpp.protocol.protocol_header — the structs and the declarations this answers.