packio
converters.h
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4 
5 #ifndef PACKIO_JSON_RPC_CONVERTERS_H
6 #define PACKIO_JSON_RPC_CONVERTERS_H
7 
8 #include <boost/json.hpp>
9 
10 namespace packio {
11 namespace json_rpc {
12 namespace internal {
13 
14 template <typename... Args, std::size_t... Idxs>
15 std::tuple<Args...> json_to_tuple(
16  const boost::json::array& jv,
17  std::index_sequence<Idxs...>)
18 {
19  return {boost::json::value_to<Args>(jv.at(Idxs))...};
20 }
21 
22 } // internal
23 } // json_rpc
24 } // packio
25 
26 namespace boost {
27 namespace json {
28 
29 template <typename... Args>
30 std::tuple<Args...> tag_invoke(value_to_tag<std::tuple<Args...>>, const value& jv)
31 {
32  return ::packio::json_rpc::internal::json_to_tuple<Args...>(
33  jv.get_array(), std::make_index_sequence<sizeof...(Args)>());
34 }
35 
36 template <
37  typename CStr,
38  typename = std::enable_if_t<std::is_same_v<std::decay_t<CStr>, const char*>>>
39 void tag_invoke(value_from_tag, value& jv, CStr&& from)
40 {
41  jv.emplace_string().assign(std::forward<CStr>(from));
42 }
43 
44 } // json
45 } // boost
46 
47 #endif // PACKIO_JSON_RPC_CONVERTERS_H
The packio namespace.
Definition: arg.h:14