This commit is contained in:
cjkas 2026-03-23 08:11:12 +01:00
parent 9ccc2d4ff5
commit 8c51e1a518
24 changed files with 1285 additions and 405 deletions

View file

@ -68,6 +68,35 @@ void JsonResponse::_safecat(const char *val, bool escape) {
if(escape) strcat(this->buff, "\"");
}
void AsyncJsonResp::beginResponse(AsyncWebServerRequest *request, char *buff, size_t buffSize) {
this->buff = buff;
this->buffSize = buffSize;
this->buff[0] = 0x00;
this->_nocomma = true;
this->_headersSent = false;
this->_stream = request->beginResponseStream("application/json");
}
void AsyncJsonResp::endResponse() {
if(strlen(this->buff)) this->flush();
}
void AsyncJsonResp::flush() {
if(this->_stream && strlen(this->buff) > 0) {
this->_stream->print(this->buff);
this->buff[0] = 0x00;
}
}
void AsyncJsonResp::_safecat(const char *val, bool escape) {
size_t len = (escape ? this->calcEscapedLength(val) : strlen(val)) + strlen(this->buff);
if(escape) len += 2;
if(len >= this->buffSize) {
this->flush();
}
if(escape) strcat(this->buff, "\"");
if(escape) this->escapeString(val, &this->buff[strlen(this->buff)]);
else strcat(this->buff, val);
if(escape) strcat(this->buff, "\"");
}
void JsonFormatter::beginObject(const char *name) {
if(name && strlen(name) > 0) this->appendElem(name);
else if(!this->_nocomma) this->_safecat(",");