PrettyAsyncJsonResponse for ArduinoJson 6.x (#539)
* PrettyAsyncJsonResponse for ArduinoJson 6.x add support for PrettyAsyncJsonResponse in ArduinoJson 6.x * Update AsyncJson.h Maintain order of args to AsyncJsonResponse between ArduinoJson 5.x and 6.x compatibility for ease of migration
This commit is contained in:
parent
69aaf767eb
commit
59066bd1e4
|
@ -101,7 +101,7 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
|
|||
_root = _jsonBuffer.createObject();
|
||||
}
|
||||
#else
|
||||
AsyncJsonResponse(size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE, bool isArray=false) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
|
||||
AsyncJsonResponse(bool isArray=false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
|
||||
_code = 200;
|
||||
_contentType = JSON_MIMETYPE;
|
||||
if(isArray)
|
||||
|
@ -140,18 +140,25 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
|
|||
}
|
||||
};
|
||||
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
class PrettyAsyncJsonResponse: public AsyncJsonResponse {
|
||||
public:
|
||||
PrettyAsyncJsonResponse (bool isArray=false) : AsyncJsonResponse{isArray} {}
|
||||
size_t setLength () {
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
_contentLength = _root.measurePrettyLength ();
|
||||
#else
|
||||
_contentLength = measureJsonPretty(_root);
|
||||
#endif
|
||||
if (_contentLength) {_isValid = true;}
|
||||
return _contentLength;
|
||||
}
|
||||
size_t _fillBuffer (uint8_t *data, size_t len) {
|
||||
ChunkPrint dest (data, _sentLength, len);
|
||||
#ifdef ARDUINOJSON_5_COMPATIBILITY
|
||||
_root.prettyPrintTo (dest);
|
||||
#else
|
||||
serializeJsonPretty(_root, dest);
|
||||
#endif
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue