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

◆ crgbFromJson()

bool fl::crgbFromJson ( const json & document,
span< CRGB > pixels )

Decode a versioned JSON object into an existing CRGB pixel buffer.

The document must use schema version 1 and contain exactly one RGB triplet per output pixel. Every channel must be an integer from 0 through 255. The complete document is validated before any output pixel is changed.

Parameters
documentJSON object produced by crgbToJson().
pixelsDestination pixel buffer.
Returns
true on success; false if the document is invalid. On failure, pixels is left unchanged.

Definition at line 101 of file crgb_json.cpp.hpp.

101 {
102 if (!document.is_object()) {
103 return false;
104 }
105
106 const json versionJson = document["version"];
107 const optional<i64> version = versionJson.as<i64>();
108 if (!versionJson.is_int() || versionJson.is_bool() || !version ||
109 *version != 1) {
110 return false;
111 }
112
113 const json encodedPixels = document["pixels"];
114 if (!encodedPixels.is_array() || encodedPixels.size() != pixels.size()) {
115 return false;
116 }
117
118 for (size i = 0; i < encodedPixels.size(); ++i) {
119 if (!crgbJsonPixel(encodedPixels[i])) {
120 return false;
121 }
122 }
123
124 for (size i = 0; i < encodedPixels.size(); ++i) {
125 pixels[i] = *crgbJsonPixel(encodedPixels[i]);
126 }
127 return true;
128}
bool is_object() const FL_NO_EXCEPT
Definition json.h:391
fl::optional< T > as() const FL_NO_EXCEPT
Definition json.h:490
constexpr fl::size size() const FL_NO_EXCEPT
Definition span.h:483
optional< CRGB > crgbJsonPixel(const json &value) FL_NO_EXCEPT
Optional< T > optional
Definition optional.h:16
fl::i64 i64
Definition stdint.h:221

References fl::json::as(), FL_NO_EXCEPT, fl::json::is_array(), fl::json::is_bool(), fl::json::is_int(), and fl::json::size().

+ Here is the call graph for this function: