Skip to content

Commit

Permalink
[json] parse buffer now uses heap.
Browse files Browse the repository at this point in the history
  • Loading branch information
tschak909 committed Jul 18, 2023
1 parent 0b524e9 commit 003948b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/fnjson/fnjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ FNJSON::FNJSON()
Debug_printf("FNJSON::ctor()\r\n");
_protocol = nullptr;
_json = nullptr;
_parseBuffer = nullptr;
}

/**
Expand All @@ -35,6 +36,9 @@ FNJSON::~FNJSON()
if (_json != nullptr)
cJSON_Delete(_json);
_json = nullptr;

if (_parseBuffer != nullptr)
delete(_parseBuffer);
}

/**
Expand Down Expand Up @@ -253,7 +257,12 @@ int FNJSON::readValueLen()
bool FNJSON::parse()
{
NetworkStatus ns;
_parseBuffer.clear();
if (_parseBuffer != nullptr)
{
delete _parseBuffer;
}

_parseBuffer = new string();

if (_json != nullptr)
cJSON_Delete(_json);
Expand All @@ -269,14 +278,14 @@ bool FNJSON::parse()
while (ns.connected)
{
_protocol->read(ns.rxBytesWaiting);
_parseBuffer += *_protocol->receiveBuffer;
*_parseBuffer += *_protocol->receiveBuffer;
_protocol->receiveBuffer->clear();
_protocol->status(&ns);
vTaskDelay(10);
}

Debug_printf("S: %s\r\n",_parseBuffer.c_str());
_json = cJSON_Parse(_parseBuffer.c_str());
Debug_printf("S: %s\r\n",_parseBuffer->c_str());
_json = cJSON_Parse(_parseBuffer->c_str());

if (_json == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/fnjson/fnjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FNJSON
uint8_t _queryParam;
string lineEnding;
string getValue(cJSON *item);
string _parseBuffer;
string *_parseBuffer;
};

#endif /* JSON_H */

0 comments on commit 003948b

Please sign in to comment.