18 using value_type = rfl::Generic;
19 using object_type = rfl::Generic::Object;
20 using array_type = rfl::Generic::Array;
21 using string_type = std::string;
22 using number_type = double;
23 using integer_type = int64_t;
24 using boolean_type = bool;
28 using Ts::operator()...;
34 [](boolean_type
const&) ->
jwt::json::type {
return jwt::json::type::boolean; },
35 [](integer_type
const&) ->
jwt::json::type {
return jwt::json::type::integer; },
36 [](number_type
const&) ->
jwt::json::type {
return jwt::json::type::number; },
37 [](string_type
const&) ->
jwt::json::type {
return jwt::json::type::string; },
38 [](array_type
const&) ->
jwt::json::type {
return jwt::json::type::array; },
39 [](object_type
const&) ->
jwt::json::type {
return jwt::json::type::object; },
40 [](std::nullopt_t
const&) ->
jwt::json::type {
throw std::logic_error(
"invalid type"); },
45 static object_type as_object(
const value_type& val) {
46 const auto& variant = val.get();
47 if (!std::holds_alternative<object_type>(variant))
throw std::bad_cast();
48 return std::get<object_type>(variant);
51 static array_type as_array(
const value_type& val) {
52 const auto& variant = val.get();
53 if (!std::holds_alternative<array_type>(variant))
throw std::bad_cast();
54 return std::get<array_type>(variant);
57 static string_type as_string(
const value_type& val) {
58 const auto& variant = val.get();
59 if (!std::holds_alternative<string_type>(variant))
throw std::bad_cast();
60 return std::get<string_type>(variant);
63 static integer_type as_integer(
const value_type& val) {
64 const auto& variant = val.get();
65 if (!std::holds_alternative<integer_type>(variant))
throw std::bad_cast();
66 return std::get<integer_type>(variant);
69 static boolean_type as_boolean(
const value_type& val) {
70 const auto& variant = val.get();
71 if (!std::holds_alternative<boolean_type>(variant))
throw std::bad_cast();
72 return std::get<boolean_type>(variant);
75 static number_type as_number(
const value_type& val) {
76 const auto& variant = val.get();
77 if (!std::holds_alternative<number_type>(variant))
throw std::bad_cast();
78 return std::get<number_type>(variant);
81 static bool parse(value_type& out, string_type
const& json) {
82 auto res = rfl::json::read<rfl::Generic>(json);
84 out = *std::move(res);
90 static std::string serialize(
const value_type& val) {
return rfl::json::write(val); }