Serialize JSON response to a string.
28 {
29
30
32 const fl::size bodyLength = jsonStr.
size();
33 const fl::size prefixLength = prefix ?
fl::strlen(prefix) : 0;
34 if (bodyLength == 0) {
35
36
37 return outOfMemoryResponse(prefix, prefixLength);
38 }
39 if (prefixLength != 0) {
40 const fl::size totalLength = bodyLength + prefixLength;
43 jsonStr.
write(prefix, prefixLength);
44 }
45 if (jsonStr.
size() != totalLength || totalLength < bodyLength) {
46
47
50 }
51 char *bytes = &jsonStr[0];
52 fl::memmove(bytes + prefixLength, bytes, bodyLength);
54 }
55
56
57 for (fl::size i = prefixLength; i < jsonStr.
size(); ++i) {
58 char &byte = jsonStr[i];
59 if (byte == '\n' || byte == '\r') {
60 byte = ' ';
61 }
62 }
63 return jsonStr;
64}
void clear(bool freeMemory=false) FL_NO_EXCEPT
void reserve(fl::size newCapacity) FL_NO_EXCEPT
fl::size write(const fl::u8 *data, fl::size n) FL_NO_EXCEPT
fl::size size() const FL_NO_EXCEPT
static constexpr fl::size npos
fl::string outOfMemoryResponse(const char *prefix, fl::size prefixLength) FL_NO_EXCEPT
FASTLED_FORCE_INLINE void * memmove(void *dest, const void *src, size_t n) FL_NO_EXCEPT
FASTLED_FORCE_INLINE void * memcpy(void *dest, const void *src, size_t n) FL_NO_EXCEPT
FASTLED_FORCE_INLINE size_t strlen(const char *s) FL_NO_EXCEPT