FastLED 3.10.6
Loading...
Searching...
No Matches

◆ json_convert_to_i64_core()

FL_NO_INLINE TypeConversionResult fl::detail::json_convert_to_i64_core ( const json_value & val,
fl::i64 * out_value )

Definition at line 17 of file json_dispatch.cpp.hpp.

18 {
20 if (auto* p = val.data.template ptr<i64>()) {
21 *out_value = *p;
22 return result;
23 }
24 if (auto* p = val.data.template ptr<bool>()) {
25 *out_value = *p ? 1 : 0;
26 result.addWarning(fl::string("bool converted to int ") + fl::to_string(*out_value));
27 return result;
28 }
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)) {
33 result.addWarning(fl::string("float ") + fl::to_string(*p, 6) +
34 " truncated to int " + fl::to_string(*out_value));
35 }
36#else
37 (void)p;
38 *out_value = 0;
39 result.setError("float -> int not supported on Low-memory");
40#endif
41 return result;
42 }
43 if (auto* p = val.data.template ptr<fl::string>()) {
44 char* end = nullptr;
45 long parsed = fl::strtol(p->c_str(), &end, 10);
46 if (end != p->c_str() && *end == '\0') {
47 *out_value = static_cast<i64>(parsed);
48 result.addWarning(fl::string("string '") + *p + "' parsed to int " + fl::to_string(*out_value));
49 } else {
50 result.setError(fl::string("cannot parse string '") + *p + "' as integer");
51 }
52 return result;
53 }
54 if (val.data.template ptr<fl::nullptr_t>()) {
55 result.setError("cannot convert null to integer");
56 return result;
57 }
58 // Any remaining alternative (json_object, json_array, vector<i16>,
59 // vector<u8>, vector<float>) -- all are "container" types that don't
60 // convert cleanly to an integer.
61 result.setError("cannot convert array or object to integer");
62 *out_value = 0;
63 return result;
64}
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
string to_string(T value) FL_NO_EXCEPT
Definition string.h:459
long strtol(const char *str, char **endptr, int base)
fl::i64 i64
Definition stdint.h:221
variant_t data
Definition types.h:760

References fl::end(), fl::FL_NO_EXCEPT, fl::strtol(), and fl::to_string().

Referenced by fl::detail::JsonToType< T, typename fl::enable_if< fl::is_integral< T >::value &&!fl::is_same< T, bool >::value >::type >::convert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: