FastLED 3.9.15
Loading...
Searching...
No Matches
serial.cpp.hpp
Go to the documentation of this file.
1// src/fl/remote/transport/serial.cpp.hpp
2// Implementation of JSON-RPC serial transport layer
3
4#pragma once
5
7#include "fl/stl/cstring.h"
8#include "fl/stl/strstream.h"
9
10namespace fl {
11
12fl::string formatJsonResponse(const fl::json& response, const char* prefix) {
13 // Use sstream to minimize allocations
14 fl::sstream ss;
15
16 // Add prefix if provided
17 if (prefix && prefix[0] != '\0') {
18 ss << prefix;
19 }
20
21 // Serialize to compact JSON
22 fl::string jsonStr = response.to_string();
23
24 // Stream copy with inline filtering (replace newlines with spaces)
25 for (size_t i = 0; i < jsonStr.size(); ++i) {
26 char c = jsonStr[i];
27 ss << ((c == '\n' || c == '\r') ? ' ' : c);
28 }
29
30 return ss.str();
31}
32
33} // namespace fl
fl::size size() const FL_NOEXCEPT
string str() const FL_NOEXCEPT
Definition strstream.h:43
fl::string formatJsonResponse(const fl::json &response, const char *prefix)
Serialize JSON response to a string.
Base definition for an LED controller.
Definition crgb.hpp:179