2
0
mirror of https://github.com/boostorg/redis.git synced 2026-02-22 03:32:22 +00:00
Files
redis/include/aedis/resp3/impl/node.ipp
Marcelo Zimbres 98bb12c8b6 More refactoring.
2021-12-12 23:04:27 +01:00

72 lines
1.5 KiB
C++

/* Copyright (c) 2019 - 2021 Marcelo Zimbres Silva (mzimbres at gmail dot com)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <aedis/resp3/node.hpp>
namespace aedis {
namespace resp3 {
void node::dump(dump_format format, int indent, std::string& out) const
{
switch (format) {
case node::dump_format::raw:
{
out += std::to_string(depth);
out += '\t';
out += to_string(data_type);
out += '\t';
out += std::to_string(size);
out += '\t';
if (!is_aggregate(data_type))
out += data;
} break;
case node::dump_format::clean:
{
std::string prefix(indent * depth, ' ');
out += prefix;
if (is_aggregate(data_type)) {
out += "(";
out += to_string(data_type);
out += ")";
if (size == 0) {
std::string prefix2(indent * (depth + 1), ' ');
out += "\n";
out += prefix2;
out += "(empty)";
}
} else {
if (std::empty(data))
out += "(empty)";
else
out += data;
}
} break;
default: { }
}
}
bool operator==(node const& a, node const& b)
{
return a.size == b.size
&& a.depth == b.depth
&& a.data_type == b.data_type
&& a.data == b.data;
};
std::ostream& operator<<(std::ostream& os, node const& o)
{
std::string res;
o.dump(node::dump_format::clean, 3, res);
os << res;
return os;
}
} // resp3
} // aedis