FastLED 3.10.8
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#include "fl/stl/noexcept.h"
10
11namespace fl {
12
13fl::string formatJsonResponse(const fl::json& response, const char* prefix) FL_NO_EXCEPT {
14 // Use sstream to minimize allocations
15 fl::sstream ss;
16
17 // Add prefix if provided
18 if (prefix && prefix[0] != '\0') {
19 ss << prefix;
20 }
21
22 // Serialize to compact JSON
23 fl::string jsonStr = response.to_string();
24
25 // Stream copy with inline filtering (replace newlines with spaces)
26 for (size_t i = 0; i < jsonStr.size(); ++i) {
27 char c = jsonStr[i];
28 ss << ((c == '\n' || c == '\r') ? ' ' : c);
29 }
30
31 return ss.str();
32}
33
34} // namespace fl
fl::size size() const FL_NO_EXCEPT
string str() const FL_NO_EXCEPT
Definition strstream.h:43
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::string formatJsonResponse(const fl::json &response, const char *prefix) FL_NO_EXCEPT
Serialize JSON response to a string.
Base definition for an LED controller.
Definition crgb.hpp:179