Skip to content

Commit

Permalink
Fix string conversion for internal_command
Browse files Browse the repository at this point in the history
  • Loading branch information
Neverlord committed Nov 23, 2024
1 parent 94901e9 commit 0b07d2c
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions libbroker/broker/internal_command.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#include "broker/internal_command.hh"
#include "broker/internal/type_id.hh"

#include "caf/deep_to_string.hpp"

namespace broker {

namespace {

// Usually, we could simply call caf::deep_to_string. However, Broker injects a
// `to_string` function for any type offering `convert`. Because of this greedy
// template, calling `caf::deep_to_string` would simply call `convert` again,
// leading to an endless recursion. Calling the `inspect` overload here manually
// avoids this issue.
template <class T>
void do_stringify(const T& what, std::string& out) {
caf::detail::stringification_inspector f{out};
broker::inspect(f, const_cast<T&>(what));
}

} // namespace

std::string to_string(command_tag x) {
switch (x) {
case command_tag::action:
Expand All @@ -18,63 +34,63 @@ std::string to_string(command_tag x) {
}

void convert(const put_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const put_unique_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const put_unique_result_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const erase_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const expire_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const add_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const subtract_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const clear_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const attach_writer_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const ack_clone_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const cumulative_ack_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const nack_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const keepalive_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const retransmit_failed_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

void convert(const internal_command& x, std::string& str) {
str = caf::deep_to_string(x);
do_stringify(x, str);
}

} // namespace broker

0 comments on commit 0b07d2c

Please sign in to comment.