FastLED 3.10.9
Loading...
Searching...
No Matches

◆ createSerialResponseSink()

fl::function< void(const fl::json &)> fl::createSerialResponseSink ( const char * prefix = "REMOTE: ")
inline

Create a JSON-RPC ResponseSink that writes to fl:: serial output.

Parameters
prefixOptional prefix to prepend to responses (default: "REMOTE: ")
Returns
ResponseSink callback suitable for fl::Remote constructor
Note
Composes protocol layer (schema filtering) with transport layer (serial I/O)

Definition at line 197 of file serial.h.

197 : ") FL_NO_EXCEPT {
198 return [prefix](const fl::json& response) {
199 // Stream the serialized response straight to serial so large
200 // responses (e.g. rpc.discover) never need a contiguous heap buffer
201 // proportional to the document (FastLED #4899).
202 SerialWriter serial;
203 if (prefix && prefix[0] != '\0') {
204 serial.write(prefix, fl::strlen(prefix));
205 }
206 response.write_to(
207 [](void* ctx, const char* data, fl::size len) {
208 static_cast<SerialWriter*>(ctx)->write(data, len);
209 },
210 &serial);
211 serial.println("");
212 };
213}

References FL_NO_EXCEPT, fl::SerialWriter::println(), strlen(), and fl::SerialWriter::write().

Referenced by createSerialTransport().

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