16 using value_type = glz::generic;
17 using object_type = value_type::object_t;
18 using array_type = value_type::array_t;
19 using string_type = std::string;
20 using number_type = double;
21 using integer_type = std::int64_t;
22 using boolean_type = bool;
24 static bool is_integer(
double value) {
return std::trunc(value) == value; }
29 if (val.is_object()) {
return type::object; }
30 if (val.is_array()) {
return type::array; }
31 if (val.is_string()) {
return type::string; }
32 if (val.is_number() && is_integer(val.get_number())) {
return type::integer; }
33 if (val.is_number()) {
return type::number; }
34 if (val.is_boolean()) {
return type::boolean; }
36 throw std::logic_error(
"invalid type");
39 static object_type as_object(
const value_type& val) {
40 if (get_type(val) != jwt::json::type::object)
throw std::bad_cast();
41 return val.get_object();
44 static array_type as_array(
const value_type& val) {
45 if (get_type(val) != jwt::json::type::array)
throw std::bad_cast();
46 return val.get_array();
49 static string_type as_string(
const value_type& val) {
50 if (get_type(val) != jwt::json::type::string)
throw std::bad_cast();
51 return val.get_string();
54 static integer_type as_integer(
const value_type& val) {
55 if (get_type(val) != jwt::json::type::integer)
throw std::bad_cast();
56 return val.get_number();
59 static boolean_type as_boolean(
const value_type& val) {
60 if (get_type(val) != jwt::json::type::boolean)
throw std::bad_cast();
61 return val.get_boolean();
64 static number_type as_number(
const value_type& val) {
65 if (get_type(val) != jwt::json::type::number)
throw std::bad_cast();
66 return val.get_number();
69 static bool parse(value_type& val, string_type str) {
70 if (
auto parsed = glz::read_json<glz::generic>(str); parsed) {
78 static string_type serialize(
const value_type& val) {
return val.dump().value(); }