FastLED 3.9.15
Loading...
Searching...
No Matches

◆ writeChunk()

size_t fl::net::http::ChunkedWriter::writeChunk ( fl::span< const u8 > data,
fl::span< u8 > out )

Definition at line 186 of file chunked_encoding.cpp.hpp.

186 {
187 // Format: <size-hex>\r\n<data>\r\n
188 char sizeHex[32];
189 int hexLen = fl::snprintf(sizeHex, sizeof(sizeHex), "%zx\r\n", data.size());
190 size_t totalNeeded = static_cast<size_t>(hexLen) + data.size() + 2;
191 if (out.size() < totalNeeded) {
192 return 0;
193 }
194
195 u8* dst = out.data();
196
197 // Write size hex + CRLF
198 memcpy(dst, sizeHex, static_cast<size_t>(hexLen));
199 dst += hexLen;
200
201 // Write data
202 memcpy(dst, data.data(), data.size());
203 dst += data.size();
204
205 // Write trailing CRLF
206 *dst++ = '\r';
207 *dst++ = '\n';
208
209 return totalNeeded;
210}
const T * data() const FL_NOEXCEPT
Definition span.h:461
constexpr fl::size size() const FL_NOEXCEPT
Definition span.h:458
void * memcpy(void *dest, const void *src, size_t n) FL_NOEXCEPT
unsigned char u8
Definition stdint.h:131
int snprintf(char *buffer, fl::size size, const char *format, const Args &... args) FL_NOEXCEPT
Snprintf-like formatting function that writes to a buffer.
Definition stdio.h:666

References fl::span< T, Extent >::data(), fl::memcpy(), fl::span< T, Extent >::size(), and fl::snprintf().

+ Here is the call graph for this function: