json response is more human readable with PrettyAsyncJsonResponse class (#398)

* Update AsyncJson.h

Adding PrettyAsyncJsonResponse class

* Update AsyncJson.h

* Adding a PrettyAsyncJsonResponse class

json response is more human readable than with AsyncJsonResponse
This commit is contained in:
Gérald Guiony 2019-06-22 18:24:01 +02:00 committed by Me No Dev
parent d55dd73e44
commit 781bddf20c
1 changed files with 16 additions and 1 deletions

View File

@ -78,7 +78,7 @@ class ChunkPrint : public Print {
};
class AsyncJsonResponse: public AsyncAbstractResponse {
private:
protected:
#ifdef ARDUINOJSON_5_COMPATIBILITY
DynamicJsonBuffer _jsonBuffer;
@ -140,6 +140,21 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
}
};
class PrettyAsyncJsonResponse: public AsyncJsonResponse {
public:
PrettyAsyncJsonResponse (bool isArray=false) : AsyncJsonResponse{isArray} {}
size_t setLength () {
_contentLength = _root.measurePrettyLength ();
if (_contentLength) {_isValid = true;}
return _contentLength;
}
size_t _fillBuffer (uint8_t *data, size_t len) {
ChunkPrint dest (data, _sentLength, len);
_root.prettyPrintTo (dest);
return len;
}
};
typedef std::function<void(AsyncWebServerRequest *request, JsonVariant &json)> ArJsonRequestHandlerFunction;
class AsyncCallbackJsonWebHandler: public AsyncWebHandler {