Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
Show First 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* A pair of strings that can be aligned (through padding) with other Sections | * A pair of strings that can be aligned (through padding) with other Sections | ||||
* later on | * later on | ||||
*/ | */ | ||||
struct Section { | struct Section { | ||||
Section(const std::string &left, const std::string &right) | Section(const std::string &left, const std::string &right) | ||||
: m_left{left}, m_right{right} {} | : m_left{left}, m_right{right} {} | ||||
const std::string m_left; | std::string m_left; | ||||
const std::string m_right; | const std::string m_right; | ||||
}; | }; | ||||
/** | /** | ||||
* Keeps track of RPCArgs by transforming them into sections for the purpose | * Keeps track of RPCArgs by transforming them into sections for the purpose | ||||
* of serializing everything to a single string | * of serializing everything to a single string | ||||
*/ | */ | ||||
struct Sections { | struct Sections { | ||||
▲ Show 20 Lines • Show All 378 Lines • ▼ Show 20 Lines | switch (m_type) { | ||||
case Type::ARR: { | case Type::ARR: { | ||||
sections.PushSection( | sections.PushSection( | ||||
{indent + maybe_key + "[", Description("json array")}); | {indent + maybe_key + "[", Description("json array")}); | ||||
for (const auto &i : m_inner) { | for (const auto &i : m_inner) { | ||||
i.ToSections(sections, OuterType::ARR, current_indent + 2); | i.ToSections(sections, OuterType::ARR, current_indent + 2); | ||||
} | } | ||||
if (m_type == Type::ARR) { | if (m_type == Type::ARR) { | ||||
sections.PushSection({indent_next + "...", ""}); | sections.PushSection({indent_next + "...", ""}); | ||||
} else { | |||||
CHECK_NONFATAL(!m_inner.empty()); | |||||
// Remove final comma, which would be invalid JSON | |||||
sections.m_sections.back().m_left.pop_back(); | |||||
} | } | ||||
sections.PushSection({indent + "]" + maybe_separator, ""}); | sections.PushSection({indent + "]" + maybe_separator, ""}); | ||||
return; | return; | ||||
} | } | ||||
case Type::OBJ_DYN: | case Type::OBJ_DYN: | ||||
case Type::OBJ: { | case Type::OBJ: { | ||||
sections.PushSection( | sections.PushSection( | ||||
{indent + maybe_key + "{", Description("json object")}); | {indent + maybe_key + "{", Description("json object")}); | ||||
for (const auto &i : m_inner) { | for (const auto &i : m_inner) { | ||||
i.ToSections(sections, OuterType::OBJ, current_indent + 2); | i.ToSections(sections, OuterType::OBJ, current_indent + 2); | ||||
} | } | ||||
if (m_type == Type::OBJ_DYN) { | if (m_type == Type::OBJ_DYN) { | ||||
// If the dictionary keys are dynamic, use three dots for | // If the dictionary keys are dynamic, use three dots for | ||||
// continuation | // continuation | ||||
sections.PushSection({indent_next + "...", ""}); | sections.PushSection({indent_next + "...", ""}); | ||||
} else { | |||||
CHECK_NONFATAL(!m_inner.empty()); | |||||
// Remove final comma, which would be invalid JSON | |||||
sections.m_sections.back().m_left.pop_back(); | |||||
} | } | ||||
sections.PushSection({indent + "}" + maybe_separator, ""}); | sections.PushSection({indent + "}" + maybe_separator, ""}); | ||||
return; | return; | ||||
} | } | ||||
// no default case, so the compiler can warn about missing cases | // no default case, so the compiler can warn about missing cases | ||||
} | } | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |