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

---

# llarp/rpc/json_conversions.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[nlohmann](Namespaces/namespacenlohmann.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[nlohmann::adl_serializer< T, std::enable_if_t< llarp::rpc::json_is_binary< T > > >](Classes/structnlohmann_1_1adl__serializer_3_01T_00_01std_1_1enable__if__t_3_01llarp_1_1rpc_1_1json__is__binary_3_01T_01_4_01_4_01_4.md)**  |




## Source code

```cpp
#pragma once

#include <llarp/net/ip_range.hpp>
#include <nlohmann/json_fwd.hpp>
#include "json_binary_proxy.hpp"

namespace llarp
{
  void
  to_json(nlohmann::json& j, const IPRange& ipr);
  void
  from_json(const nlohmann::json& j, IPRange& ipr);
}  // namespace llarp

namespace nlohmann
{
  // 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>>>
  {
    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);
    }
  };

}  // namespace nlohmann
```


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

Updated on 2023-04-27 at 04:17:18 +0000
