0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd:Ⓜ️ Add additional format selection for pretty_oneline(event).

This commit is contained in:
Jason Volk 2019-07-25 15:54:44 -07:00
parent 58dd728f49
commit 9a5df1ae9c
2 changed files with 25 additions and 19 deletions

View file

@ -14,8 +14,11 @@
namespace ircd::m
{
// Informational pretty string condensed to single line.
std::ostream &pretty_oneline(std::ostream &, const event &, const bool &content_keys = true);
std::string pretty_oneline(const event &, const bool &content_keys = true);
// fmt = 0: w/o content keys, w/ hashes/sigs
// fmt = 1: w/ content keys w/ hashes/sigs
// fmt = 2: w/o content keys w/o hashes/sigs
std::ostream &pretty_oneline(std::ostream &, const event &, const int &fmt = 1);
std::string pretty_oneline(const event &, const int &fmt = 1);
// Informational pretty string on multiple lines.
std::ostream &pretty(std::ostream &, const event &);

View file

@ -107,12 +107,12 @@ ircd::m::pretty(std::ostream &s,
std::string
ircd::m::pretty_oneline(const event &event,
const bool &content_keys)
const int &fmt)
{
std::string ret;
std::stringstream s;
pubsetbuf(s, ret, 4096);
pretty_oneline(s, event, content_keys);
pretty_oneline(s, event, fmt);
resizebuf(s, ret);
return ret;
}
@ -120,7 +120,7 @@ ircd::m::pretty_oneline(const event &event,
std::ostream &
ircd::m::pretty_oneline(std::ostream &s,
const event &event,
const bool &content_keys)
const int &fmt)
{
if(defined(json::get<"room_id"_>(event)))
s << json::get<"room_id"_>(event) << ' ';
@ -159,23 +159,26 @@ ircd::m::pretty_oneline(std::ostream &s,
const auto &prev_events{json::get<"prev_events"_>(event)};
s << "E:" << prev_events.count() << ' ';
const auto &hashes{json::get<"hashes"_>(event)};
s << "[ ";
for(const auto &hash : hashes)
s << hash.first << ' ';
s << "] ";
const auto &signatures{json::get<"signatures"_>(event)};
s << "[ ";
for(const auto &signature : signatures)
if(fmt >= 2)
{
s << signature.first << "[ ";
for(const auto &key : json::object{signature.second})
s << key.first << ' ';
const auto &hashes{json::get<"hashes"_>(event)};
s << "[ ";
for(const auto &hash : hashes)
s << hash.first << ' ';
s << "] ";
const auto &signatures{json::get<"signatures"_>(event)};
s << "[ ";
for(const auto &signature : signatures)
{
s << signature.first << "[ ";
for(const auto &key : json::object{signature.second})
s << key.first << ' ';
s << "] ";
}
s << "] ";
}
s << "] ";
if(defined(json::get<"type"_>(event)))
s << json::get<"type"_>(event) << ' ';
@ -210,7 +213,7 @@ ircd::m::pretty_oneline(std::ostream &s,
const json::object &contents
{
content_keys?
fmt >= 1?
json::get<"content"_>(event):
json::object{}
};