Memory-bounded streaming builder for /controller. Produces the JSON payload one small unit at a time into a fixed 3KB buffer, so a chunked HTTP response can drain it as the TCP send window allows — no growing cbuf in the async response stream.

This commit is contained in:
cjkas 2026-04-21 14:56:20 +02:00
parent f51e90bb7c
commit 6365f16850
4 changed files with 270 additions and 31 deletions

View file

@ -35,6 +35,17 @@ void JsonSockEvent::_safecat(const char *val, bool escape) {
else strcat(this->buff, val);
if(escape) strcat(this->buff, "\"");
}
void BufferedJsonFormatter::setBuffer(char *b, size_t sz) {
this->buff = b;
this->buffSize = sz;
this->buff[0] = 0;
this->_nocomma = true;
this->_objects = 0;
this->_arrays = 0;
}
size_t BufferedJsonFormatter::length() const {
return strlen(this->buff);
}
void AsyncJsonResp::beginResponse(AsyncWebServerRequest *request, char *buff, size_t buffSize) {
this->_request = request;
this->buff = buff;