2023-01-26 17:51:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include "json_binary_proxy.hpp"
|
|
|
|
|
2023-01-26 17:51:55 +00:00
|
|
|
#include <llarp/net/ip_range.hpp>
|
2023-10-19 21:59:57 +00:00
|
|
|
|
2023-10-24 13:18:03 +00:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2023-01-26 17:51:55 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
void to_json(nlohmann::json& j, const IPRange& ipr);
|
|
|
|
void from_json(const nlohmann::json& j, IPRange& ipr);
|
2023-01-26 17:51:55 +00:00
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
namespace nlohmann
|
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
// Specializations of binary types for deserialization; when receiving these from json we expect
|
|
|
|
// them encoded in hex or base64. These may *not* be used for serialization, and will throw if
|
|
|
|
// so invoked; for serialization you need to use RPC_COMMAND::response_hex (or _b64) instead.
|
|
|
|
template <typename T>
|
|
|
|
struct adl_serializer<T, std::enable_if_t<llarp::rpc::json_is_binary<T>>>
|
2023-01-26 17:51:55 +00:00
|
|
|
{
|
2024-02-01 12:43:43 +00:00
|
|
|
static_assert(
|
|
|
|
std::is_trivially_copyable_v<T> && std::has_unique_object_representations_v<T>);
|
|
|
|
|
|
|
|
static void to_json(json&, const T&)
|
|
|
|
{
|
|
|
|
throw std::logic_error{"Internal error: binary types are not directly serializable"};
|
|
|
|
}
|
|
|
|
static void from_json(const json& j, T& val)
|
|
|
|
{
|
|
|
|
llarp::rpc::load_binary_parameter(j.get<std::string_view>(), false /*no raw*/, val);
|
|
|
|
}
|
|
|
|
};
|
2023-01-26 17:51:55 +00:00
|
|
|
|
|
|
|
} // namespace nlohmann
|