ESPHome
2026.12.0-dev
Loading...
Searching...
No Matches
esphome
components
web_server_base
chunk.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstddef>
4
#include <cstdint>
5
#include <cstring>
6
7
#include "
esphome/core/helpers.h
"
8
9
// HTTP chunked transfer framing, shared by the /events stream and other chunked responses
10
namespace
esphome::web_server_base
{
11
12
// Chunk header "%08x\r\n"
13
constexpr
size_t
CHUNK_HDR_LEN = 10;
14
// Chunk terminator
15
constexpr
char
CHUNK_END
[] =
"\r\n"
;
16
constexpr
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
19
inline
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
helpers.h
esphome::web_server_base
Definition
async_stream_response.cpp:16
esphome::web_server_base::CHUNK_END
constexpr char CHUNK_END[]
Definition
chunk.h:15
esphome::web_server_base::write_chunk_header
void write_chunk_header(char *buf, size_t chunk_len)
Definition
chunk.h:19
esphome::format_hex_to
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
uint32_t
static void uint32_t
Definition
crash_handler.cpp:179
Generated by
1.12.0