Use std::avriant to encode event payloads

It's a bit more complicated this way, but nwo we can easily add support
for the opcode specific structs.
This commit is contained in:
Robbert van der Helm
2020-03-08 17:47:09 +01:00
parent d434bcf682
commit ff89d12c1a
5 changed files with 119 additions and 49 deletions
+9 -10
View File
@@ -121,7 +121,7 @@ void Logger::log_event(bool is_dispatch,
int opcode,
int index,
intptr_t value,
std::optional<std::string> payload,
EventPayload payload,
float option) {
if (BOOST_UNLIKELY(verbosity >= Verbosity::events)) {
std::ostringstream message;
@@ -140,15 +140,14 @@ void Logger::log_event(bool is_dispatch,
message << "(index = " << index << ", value = " << value
<< ", option = " << option << ", data = ";
if (!payload.has_value()) {
message << "<nullptr>";
} else if (payload->empty()) {
message << "<writable_buffer>";
} else {
// Might print binary payload, maybe check for this?
message << "\"" << payload.value() << "\"";
}
message << ")";
std::visit(
overload{[&](std::nullptr_t) { message << "<nullptr>"; },
[&](std::string s) { message << "\"" << s << "\""; },
[&](std::array<char, max_string_length>) {
message << "<writeable_buffer>";
}},
payload);
log(message.str());
}