Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
PrettyAsyncJsonResponse for ArduinoJson 6.x (#539)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
atanisoft authored and me-no-dev committed Sep 24, 2019
1 parent 91b8b0c commit 2cb62c9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/AsyncJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
};
Expand Down

0 comments on commit 2cb62c9

Please sign in to comment.