*/
#include "protozero-trace.hh"
+#include "base64.hh"
+#include <string>
+#include <variant>
namespace pdns::trace
{
return {};
}
+std::string AnyValue::toLogString() const
+{
+ if (std::holds_alternative<std::string>(*this)) {
+ return "\"" + std::get<std::string>(*this) + "\"";
+ }
+ if (std::holds_alternative<bool>(*this)) {
+ if (std::get<bool>(*this)) {
+ return "true";
+ }
+ return "false";
+ }
+ if (std::holds_alternative<int64_t>(*this)) {
+ return std::to_string(std::get<int64_t>(*this));
+ }
+ if (std::holds_alternative<double>(*this)) {
+ return std::to_string(std::get<double>(*this));
+ }
+ if (std::holds_alternative<ArrayValue>(*this)) {
+ std::string tmp = "[";
+ for (auto const& val : std::get<ArrayValue>(*this).values) {
+ tmp += val.toLogString() + ", ";
+ }
+ tmp.resize(tmp.size() - 2); // Strip ", "
+ return tmp += "]";
+ }
+ if (std::holds_alternative<KeyValueList>(*this)) {
+ std::string tmp = "{";
+ for (auto const& val : std::get<KeyValueList>(*this).values) {
+ tmp += val.key + ": " + val.value.toLogString() + ", ";
+ }
+ if (tmp.size() > 2) {
+ tmp.resize(tmp.size() - 2); // Strip ", "
+ }
+ return tmp += "}";
+ }
+ if (std::holds_alternative<std::vector<uint8_t>>(*this)) {
+ auto val = std::get<std::vector<uint8_t>>(*this);
+ return Base64Encode(std::string(val.begin(), val.end()));
+ }
+ return "UNSUPPORTED TYPE";
+}
+
void EntityRef::encode(protozero::pbf_writer& writer) const
{
pdns::trace::encode(writer, 1, schema_url);
{
void encode(protozero::pbf_writer& writer) const;
static AnyValue decode(protozero::pbf_reader& reader);
+ [[nodiscard]] std::string toLogString() const;
+ friend std::ostream& operator<<(std::ostream& ostrm, const AnyValue& val)
+ {
+ return ostrm << val.toLogString();
+ }
};
struct EntityRef