20 if (
auto* p = val.data.template ptr<i64>()) {
24 if (
auto* p = val.data.template ptr<bool>()) {
25 *out_value = *p ? 1 : 0;
29 if (
auto* p = val.data.template ptr<float>()) {
30#if FL_PLATFORM_HAS_LARGE_MEMORY
31 *out_value =
static_cast<i64>(*p);
32 if (*p !=
static_cast<float>(*out_value)) {
39 result.setError(
"float -> int not supported on Low-memory");
43 if (
auto* p = val.data.template ptr<fl::string>()) {
46 if (
end != p->c_str() && *
end ==
'\0') {
47 *out_value =
static_cast<i64>(parsed);
54 if (val.data.template ptr<fl::nullptr_t>()) {
55 result.setError(
"cannot convert null to integer");
61 result.setError(
"cannot convert array or object to integer");
70 if (
auto* p = val.data.template ptr<bool>()) {
74 if (
auto* p = val.data.template ptr<i64>()) {
75 *out_value = (*p != 0);
77 " converted to bool " + (*out_value ?
"true" :
"false"));
80 if (
auto* p = val.data.template ptr<float>()) {
81#if FL_PLATFORM_HAS_LARGE_MEMORY
82 *out_value = (*p != 0.0f);
84 " converted to bool " + (*out_value ?
"true" :
"false"));
88 result.setError(
"float -> bool not supported on Low-memory");
92 if (
auto* p = val.data.template ptr<fl::string>()) {
93 if (*p ==
"true" || *p ==
"1" || *p ==
"yes") {
96 }
else if (*p ==
"false" || *p ==
"0" || *p ==
"no") {
105 if (val.data.template ptr<fl::nullptr_t>()) {
106 result.setError(
"cannot convert null to bool");
110 result.setError(
"cannot convert array or object to bool");
119 if (
auto* p = val.data.template ptr<float>()) {
123 if (
auto* p = val.data.template ptr<i64>()) {
124#if FL_PLATFORM_HAS_LARGE_MEMORY
125 *out_value =
static_cast<float>(*p);
126 if (
sizeof(
float) < 8 && (*p > 16777216 || *p < -16777216)) {
128 " may lose precision as float");
132 if (*p > 2147483647LL) {
133 *out_value =
static_cast<float>(2147483647);
134 }
else if (*p < -2147483648LL) {
135 *out_value =
static_cast<float>(-2147483648);
137 *out_value =
static_cast<float>(
static_cast<fl::i32
>(*p));
142 if (
auto* p = val.data.template ptr<bool>()) {
143 *out_value = *p ? 1.0f : 0.0f;
145 (*p ?
"1.0" :
"0.0"));
148 if (
auto* p = val.data.template ptr<fl::string>()) {
149#if FL_PLATFORM_HAS_LARGE_MEMORY
152 if (
end != p->c_str() && *
end ==
'\0') {
153 *out_value =
static_cast<float>(parsed);
162 result.setError(
"string -> float not supported on Low-memory");
166 if (val.data.template ptr<fl::nullptr_t>()) {
167 result.setError(
"cannot convert null to float");
171 result.setError(
"cannot convert array or object to float");
180 if (
auto* p = val.data.template ptr<fl::string>()) {
184 if (
auto* p = val.data.template ptr<i64>()) {
186 result.addWarning(
fl::string(
"int ") + *out_value +
" converted to string");
189 if (
auto* p = val.data.template ptr<float>()) {
190#if FL_PLATFORM_HAS_LARGE_MEMORY
192 result.addWarning(
fl::string(
"float ") + *out_value +
" converted to string");
196 result.setError(
"float -> string not supported on Low-memory");
200 if (
auto* p = val.data.template ptr<bool>()) {
201 *out_value = *p ?
"true" :
"false";
202 result.addWarning(
fl::string(
"bool converted to string '") + *out_value +
"'");
205 if (val.data.template ptr<fl::nullptr_t>()) {
207 result.addWarning(
"null converted to string 'null'");
210 result.setError(
"cannot convert array or object to string");
FL_NO_INLINE TypeConversionResult json_convert_to_i64_core(const json_value &val, fl::i64 *out_value) FL_NO_EXCEPT
FL_NO_INLINE TypeConversionResult json_convert_to_float_core(const json_value &val, float *out_value) FL_NO_EXCEPT
FL_NO_INLINE TypeConversionResult json_convert_to_bool_core(const json_value &val, bool *out_value) FL_NO_EXCEPT
FL_NO_INLINE TypeConversionResult json_convert_to_string_core(const json_value &val, fl::string *out_value) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
expected< T, E > result
Alias for expected (Rust-style naming)
InputGamut g FL_NO_EXCEPT
constexpr T * end(T(&array)[N]) FL_NO_EXCEPT
string to_string(T value) FL_NO_EXCEPT
double strtod(const char *str, char **endptr)
long strtol(const char *str, char **endptr, int base)
Base definition for an LED controller.