mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-11 07:10:36 +00:00
13b01c86a6
-- Moved all RPCServer initialization logic to rpcserver constructor -- Fixed config logic, fxn binding to rpc address, fxn adding rpc cats -- router hive failed CI/CD resulting from outdated reference to rpcBindAddr -- ipc socket as default hidden from windows (for now) refactored config endpoint - added rpc call script (contrib/omq-rpc.py) - added new fxns to .ini config stuff - added delete .ini file functionality to config endpoint - added edge case control for config endpoint add commented out line in clang-form for header reorg later
47 lines
1.0 KiB
C++
47 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <nlohmann/json.hpp>
|
|
#include <oxenc/bt_value.h>
|
|
|
|
using nlohmann::json;
|
|
|
|
namespace llarp::rpc
|
|
{
|
|
|
|
inline oxenc::bt_value
|
|
json_to_bt(json&& j)
|
|
{
|
|
if (j.is_object())
|
|
{
|
|
oxenc::bt_dict res;
|
|
for (auto& [k, v] : j.items())
|
|
{
|
|
if (v.is_null())
|
|
continue; // skip k-v pairs with a null v (for other nulls we fail).
|
|
res[k] = json_to_bt(std::move(v));
|
|
}
|
|
return res;
|
|
}
|
|
if (j.is_array())
|
|
{
|
|
oxenc::bt_list res;
|
|
for (auto& v : j)
|
|
res.push_back(json_to_bt(std::move(v)));
|
|
return res;
|
|
}
|
|
if (j.is_string())
|
|
{
|
|
return std::move(j.get_ref<std::string&>());
|
|
}
|
|
if (j.is_boolean())
|
|
return j.get<bool>() ? 1 : 0;
|
|
if (j.is_number_unsigned())
|
|
return j.get<uint64_t>();
|
|
if (j.is_number_integer())
|
|
return j.get<int64_t>();
|
|
throw std::domain_error{
|
|
"internal error: encountered some unhandled/invalid type in json-to-bt translation"};
|
|
}
|
|
|
|
} // namespace llarp::rpc
|