diff --git a/libbroker/broker/internal_command.cc b/libbroker/broker/internal_command.cc index b27c1eae..019d483c 100644 --- a/libbroker/broker/internal_command.cc +++ b/libbroker/broker/internal_command.cc @@ -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 +void do_stringify(const T& what, std::string& out) { + caf::detail::stringification_inspector f{out}; + broker::inspect(f, const_cast(what)); +} + +} // namespace + std::string to_string(command_tag x) { switch (x) { case command_tag::action: @@ -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