Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/util.cpp
Show First 20 Lines • Show All 640 Lines • ▼ Show 20 Lines | void RPCResult::ToSections(Sections §ions, const OuterType outer_type, | ||||
const auto Description = [&](const std::string &type) { | const auto Description = [&](const std::string &type) { | ||||
return "(" + type + (this->m_optional ? ", optional" : "") + ")" + | return "(" + type + (this->m_optional ? ", optional" : "") + ")" + | ||||
(this->m_description.empty() ? "" : " " + this->m_description); | (this->m_description.empty() ? "" : " " + this->m_description); | ||||
}; | }; | ||||
switch (m_type) { | switch (m_type) { | ||||
case Type::ELISION: { | case Type::ELISION: { | ||||
// If the inner result is empty, use three dots for elision | // If the inner result is empty, use three dots for elision | ||||
sections.PushSection({indent_next + "...", m_description}); | sections.PushSection( | ||||
{indent + "..." + maybe_separator, m_description}); | |||||
return; | return; | ||||
} | } | ||||
case Type::NONE: { | case Type::NONE: { | ||||
sections.PushSection({indent + "None", Description("json null")}); | sections.PushSection( | ||||
{indent + "null" + maybe_separator, Description("json null")}); | |||||
return; | return; | ||||
} | } | ||||
case Type::STR: { | case Type::STR: { | ||||
sections.PushSection( | sections.PushSection( | ||||
{indent + maybe_key + "\"str\"" + maybe_separator, | {indent + maybe_key + "\"str\"" + maybe_separator, | ||||
Description("string")}); | Description("string")}); | ||||
return; | return; | ||||
} | } | ||||
Show All 26 Lines | switch (m_type) { | ||||
} | } | ||||
case Type::ARR_FIXED: | case Type::ARR_FIXED: | ||||
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) { | CHECK_NONFATAL(!m_inner.empty()); | ||||
if (m_type == Type::ARR && m_inner.back().m_type != Type::ELISION) { | |||||
sections.PushSection({indent_next + "...", ""}); | sections.PushSection({indent_next + "...", ""}); | ||||
} else { | } else { | ||||
CHECK_NONFATAL(!m_inner.empty()); | |||||
// Remove final comma, which would be invalid JSON | // Remove final comma, which would be invalid JSON | ||||
sections.m_sections.back().m_left.pop_back(); | 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) { | CHECK_NONFATAL(!m_inner.empty()); | ||||
if (m_type == Type::OBJ_DYN && | |||||
m_inner.back().m_type != Type::ELISION) { | |||||
// 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 { | } else { | ||||
CHECK_NONFATAL(!m_inner.empty()); | |||||
// Remove final comma, which would be invalid JSON | // Remove final comma, which would be invalid JSON | ||||
sections.m_sections.back().m_left.pop_back(); | 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 175 Lines • Show Last 20 Lines |