mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-04-20 19:12:13 +02:00
up
This commit is contained in:
parent
9ccc2d4ff5
commit
8c51e1a518
24 changed files with 1285 additions and 405 deletions
|
|
@ -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(",");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue