ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
chunk.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <cstring>
6
8
9// HTTP chunked transfer framing, shared by the /events stream and other chunked responses
11
12// Chunk header "%08x\r\n"
13constexpr size_t CHUNK_HDR_LEN = 10;
14// Chunk terminator
15constexpr char CHUNK_END[] = "\r\n";
16constexpr size_t CHUNK_END_LEN = sizeof(CHUNK_END) - 1;
17
18// Fills the header placeholder at the start of buf once the chunk length is known
19inline void write_chunk_header(char *buf, size_t chunk_len) {
20 // Eight lowercase hex digits; the temp keeps the terminator format_hex_to writes out of buf
21 char digits[9];
22 format_hex_to(digits, static_cast<uint32_t>(chunk_len));
23 std::memcpy(buf, digits, 8);
24 buf[8] = '\r';
25 buf[9] = '\n';
26}
27
28} // namespace esphome::web_server_base
constexpr char CHUNK_END[]
Definition chunk.h:15
void write_chunk_header(char *buf, size_t chunk_len)
Definition chunk.h:19
char * format_hex_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as lowercase hex to buffer (base implementation).
Definition helpers.cpp:459
static void uint32_t