---
title: llarp/rpc/param_parser.hpp

---

# llarp/rpc/param_parser.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::rpc](Namespaces/namespacellarp_1_1rpc.md)**  |




## Source code

```cpp
#pragma once

#include "json_binary_proxy.hpp"
#include <nlohmann/json.hpp>


namespace llarp::rpc {

    // Checks that key names are given in ascending order
    template <typename... Ignore>
    void check_ascending_names(std::string_view name1, std::string_view name2, const Ignore&...) {
        if (!(name2 > name1))
        throw std::runtime_error{"Internal error: request values must be retrieved in ascending order"};
    }

    // Accessor for simple, flat value retrieval from a json or bt_dict_consumer.  In the later
    // case note that the given bt_dict_consumer will be advanced, so you *must* take care to
    // process keys in order, both for the keys passed in here *and* for use before and after this
    // call.
    template <typename Input, typename T, typename... More>
    void get_values(Input& in, std::string_view name, T&& val, More&&... more) {
        if constexpr (std::is_same_v<rpc_input, Input>) {
        if (auto* json_in = std::get_if<json>(&in)) {
            json_range r{json_in->cbegin(), json_in->cend()};
            get_values(r, name, val, std::forward<More>(more)...);
        } else if (auto* dict = std::get_if<bt_dict_consumer>(&in)) {
            get_values(*dict, name, val, std::forward<More>(more)...);
        } else {
            // A monostate indicates that no parameters field was provided at all
            get_values(var::get<std::monostate>(in), name, val, std::forward<More>(more)...);
        }
        }
        else if constexpr (std::is_same_v<std::string_view, Input>)
        {
        if (in.front() == 'd')
        {
            bt_dict_consumer d{in};
            get_values(d, name, val, std::forward<More>(more)...);
        }
        else
        {
            auto json_in = json::parse(in);
            json_range r{json_in.cbegin(), json_in.cend()};
            get_values(r, name, val, std::forward<More>(more)...);
        }
        } else {
        static_assert(
            std::is_same_v<json_range, Input> ||
            std::is_same_v<bt_dict_consumer, Input> ||
            std::is_same_v<std::monostate, Input>);
        get_next_value(in, name, val);
        if constexpr (sizeof...(More) > 0) {
            check_ascending_names(name, more...);
            get_values(in, std::forward<More>(more)...);
        }
        }
    }

}  // namespace llarp::rpc
```


-------------------------------

Updated on 2023-01-18 at 23:51:38 +0000
