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
6
#include "
fl/remote/transport/serial.h
"
7
#include "
fl/stl/cstring.h
"
8
#include "
fl/stl/strstream.h
"
9
10
namespace
fl
{
11
12
fl::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::basic_string::size
fl::size size() const FL_NOEXCEPT
Definition
basic_string.h:153
fl::json
Definition
json.h:128
fl::sstream::str
string str() const FL_NOEXCEPT
Definition
strstream.h:43
fl::sstream
Definition
strstream.h:34
fl::string
Definition
string.h:193
cstring.h
fl::formatJsonResponse
fl::string formatJsonResponse(const fl::json &response, const char *prefix)
Serialize JSON response to a string.
Definition
serial.cpp.hpp:12
fl
Base definition for an LED controller.
Definition
crgb.hpp:179
serial.h
strstream.h
fl
remote
transport
serial.cpp.hpp
Generated on Tue Jun 16 2026 00:06:59 for FastLED by
1.13.2