| 779 | } |
| 780 | |
| 781 | void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const int current_indent) const |
| 782 | { |
| 783 | // Indentation |
| 784 | const std::string indent(current_indent, ' '); |
| 785 | const std::string indent_next(current_indent + 2, ' '); |
| 786 | |
| 787 | // Elements in a JSON structure (dictionary or array) are separated by a comma |
| 788 | const std::string maybe_separator{outer_type != OuterType::NONE ? "," : ""}; |
| 789 | |
| 790 | // The key name if recursed into an dictionary |
| 791 | const std::string maybe_key{ |
| 792 | outer_type == OuterType::OBJ ? |
| 793 | "\"" + this->m_key_name + "\" : " : |
| 794 | ""}; |
| 795 | |
| 796 | // Format description with type |
| 797 | const auto Description = [&](const std::string& type) { |
| 798 | return "(" + type + (this->m_optional ? ", optional" : "") + ")" + |
| 799 | (this->m_description.empty() ? "" : " " + this->m_description); |
| 800 | }; |
| 801 | |
| 802 | switch (m_type) { |
| 803 | case Type::ELISION: { |
| 804 | // If the inner result is empty, use three dots for elision |
| 805 | sections.PushSection({indent + "..." + maybe_separator, m_description}); |
| 806 | return; |
| 807 | } |
| 808 | case Type::ANY: { |
| 809 | CHECK_NONFATAL(false); // Only for testing |
| 810 | } |
| 811 | case Type::NONE: { |
| 812 | sections.PushSection({indent + "null" + maybe_separator, Description("json null")}); |
| 813 | return; |
| 814 | } |
| 815 | case Type::STR: { |
| 816 | sections.PushSection({indent + maybe_key + "\"str\"" + maybe_separator, Description("string")}); |
| 817 | return; |
| 818 | } |
| 819 | case Type::STR_AMOUNT: { |
| 820 | sections.PushSection({indent + maybe_key + "n" + maybe_separator, Description("numeric")}); |
| 821 | return; |
| 822 | } |
| 823 | case Type::STR_HEX: { |
| 824 | sections.PushSection({indent + maybe_key + "\"hex\"" + maybe_separator, Description("string")}); |
| 825 | return; |
| 826 | } |
| 827 | case Type::NUM: { |
| 828 | sections.PushSection({indent + maybe_key + "n" + maybe_separator, Description("numeric")}); |
| 829 | return; |
| 830 | } |
| 831 | case Type::NUM_TIME: { |
| 832 | sections.PushSection({indent + maybe_key + "xxx" + maybe_separator, Description("numeric")}); |
| 833 | return; |
| 834 | } |
| 835 | case Type::BOOL: { |
| 836 | sections.PushSection({indent + maybe_key + "true|false" + maybe_separator, Description("boolean")}); |
| 837 | return; |
| 838 | } |
no test coverage detected