1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2026-08-18 18:32:30 +02:00

Fix for PageNavigation

This commit is contained in:
Norbert Walter
2026-03-12 18:40:36 +00:00
parent 64f9058f85
commit 57272f3a44
2 changed files with 27 additions and 3 deletions
+24 -3
View File
@@ -10,10 +10,20 @@ extern "C" {
// Constructor
NetworkClient::NetworkClient(size_t reserveSize)
: _doc(reserveSize),
_valid(false)
_valid(false),
_jsonRaw(nullptr),
_jsonRawLen(0)
{
}
NetworkClient::~NetworkClient() {
if (_jsonRaw != nullptr) {
free(_jsonRaw);
_jsonRaw = nullptr;
_jsonRawLen = 0;
}
}
// Skip GZIP Header an goto DEFLATE content
int NetworkClient::skipGzipHeader(const uint8_t* data, size_t len) {
if (len < 10) return -1;
@@ -324,6 +334,13 @@ bool NetworkClient::httpGetGzip(const String& url, uint8_t*& outData, size_t& ou
bool NetworkClient::fetchAndDecompressJson(const String& url) {
_valid = false;
_doc.clear();
if (_jsonRaw != nullptr) {
free(_jsonRaw);
_jsonRaw = nullptr;
_jsonRawLen = 0;
}
uint8_t* raw = nullptr;
size_t rawLen = 0;
@@ -333,14 +350,18 @@ bool NetworkClient::fetchAndDecompressJson(const String& url) {
return false;
}
DeserializationError err = deserializeJson(_doc, raw, rawLen);
free(raw);
// Parse in zero-copy mode and keep the backing buffer alive in the class.
DeserializationError err = deserializeJson(_doc, reinterpret_cast<char*>(raw), rawLen);
if (err) {
Serial.printf("JSON ERROR: %s\n", err.c_str());
free(raw);
return false;
}
_jsonRaw = raw;
_jsonRawLen = rawLen;
if (DEBUGING) {Serial.println("JSON OK!");}
_valid = true;
return true;
+3
View File
@@ -12,6 +12,7 @@
class NetworkClient {
public:
NetworkClient(size_t reserveSize = 0);
~NetworkClient();
bool fetchAndDecompressJson(const String& url);
JsonDocument& json();
@@ -20,6 +21,8 @@ public:
private:
DynamicJsonDocument _doc;
bool _valid;
uint8_t* _jsonRaw;
size_t _jsonRawLen;
int skipGzipHeader(const uint8_t* data, size_t len);
bool httpGetGzip(const String& url, uint8_t*& outData, size_t& outLen);