From b90b76c3679abf022d2d49d2068e57e24046b459 Mon Sep 17 00:00:00 2001 From: suwatchai Date: Tue, 12 Nov 2019 03:21:17 +0700 Subject: [PATCH] Fix FirebaseJson array parsing. --- README.md | 4 ++-- library.properties | 2 +- src/FirebaseESP8266.cpp | 6 ++--- src/FirebaseESP8266.h | 6 ++--- src/FirebaseJson.cpp | 50 ++++++++++++++++++++++++----------------- src/FirebaseJson.h | 5 +++-- src/README.md | 2 +- 7 files changed, 42 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index d2054e70..6d9f400f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Firebase Realtime Database Arduino Library for ESP8266 -Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.6 +Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.7 This library supports ESP8266 MCU from Espressif. The following are platforms which library are also available. @@ -48,7 +48,7 @@ This library supports ESP8266 MCU from Espressif. The following are platforms wh ## Changes from earlier version -For library v 2.6.6 (comes with FirebaseJson v 2.2.4) or later, FirebaseJson object will be used to handle JSON data instead of JSON string which, the following functions are affected: +For library v 2.6.7 (comes with FirebaseJson v 2.2.5) or later, FirebaseJson object will be used to handle JSON data instead of JSON string which, the following functions are affected: getJson, setJson, pushJson, updateNode and updateNodeSilent. diff --git a/library.properties b/library.properties index ea0696c5..1c1b37fd 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=Firebase ESP8266 Client -version=2.6.6 +version=2.6.7 author=Mobizt diff --git a/src/FirebaseESP8266.cpp b/src/FirebaseESP8266.cpp index 985b2616..a40e23f8 100644 --- a/src/FirebaseESP8266.cpp +++ b/src/FirebaseESP8266.cpp @@ -1,12 +1,12 @@ /* - * Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.6 + * Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.7 * - * November 7, 2019 + * November 12, 2019 * * Feature Added: * * Feature Fixed: - * - BearSSL reserved rx buffer. + * - FirebaseJson array parsing. * * * This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update diff --git a/src/FirebaseESP8266.h b/src/FirebaseESP8266.h index 0ee5bcb7..1e6900e7 100644 --- a/src/FirebaseESP8266.h +++ b/src/FirebaseESP8266.h @@ -1,12 +1,12 @@ /* - * Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.6 + * Google's Firebase Realtime Database Arduino Library for ESP8266, version 2.6.7 * - * November 7, 2019 + * November 12, 2019 * * Feature Added: * * Feature Fixed: - * - BearSSL reserved rx buffer. + * - FirebaseJson array parsing. * * * This library provides ESP8266 to perform REST API by GET PUT, POST, PATCH, DELETE data from/to with Google's Firebase database using get, set, update diff --git a/src/FirebaseJson.cpp b/src/FirebaseJson.cpp index 9d67a044..96e9921c 100644 --- a/src/FirebaseJson.cpp +++ b/src/FirebaseJson.cpp @@ -1,9 +1,9 @@ /* - * FirebaseJson, version 2.2.4 + * FirebaseJson, version 2.2.5 * * The Easiest ESP8266/ESP32 Arduino library for parse, create and edit JSON object using relative path. * - * October 27, 2019 + * November 12, 2019 * * Features * - None recursive operations @@ -293,7 +293,6 @@ void FirebaseJson::_addBool(const std::string &key, bool value) _add(key.c_str(), _tr, key.length(), 6, false, true); else _add(key.c_str(), _fls, key.length(), 7, false, true); - } void FirebaseJson::_addNull(const std::string &key) @@ -675,25 +674,29 @@ bool FirebaseJson::_updateTkIndex(uint16_t index, int &depth, char *searchKey, i } else { - for (int k = _el[i].oindex - 1; k < searchIndex; k++) + if (!_arrReplaced) { - if (printMode == PRINT_MODE_PRETTY) - { - _jsonData._dbuf += _nl; - for (int j = 0; j < depth + 2; j++) - _jsonData._dbuf += _tab; - } - if (k == searchIndex - 1) + for (int k = _el[i].oindex - 1; k < searchIndex; k++) { - if (_parseCompleted == (int)_pathTk.size()) - _jsonData._dbuf += replace; + if (printMode == PRINT_MODE_PRETTY) + { + _jsonData._dbuf += _nl; + for (int j = 0; j < depth + 2; j++) + _jsonData._dbuf += _tab; + } + if (k == searchIndex - 1) + { + if (_parseCompleted == (int)_pathTk.size()) + _jsonData._dbuf += replace; + else + _insertChilds(replace, printMode); + _arrReplaced = true; + } else - _insertChilds(replace, printMode); - } - else - { - _jsonData._dbuf += _nll; - _jsonData._dbuf += _cm; + { + _jsonData._dbuf += _nll; + _jsonData._dbuf += _cm; + } } } } @@ -885,7 +888,7 @@ void FirebaseJson::_insertChilds(char *data, PRINT_MODE printMode) void FirebaseJson::_addArrNodes(std::string &str, std::string &str2, int index, char *data, PRINT_MODE printMode) { - + int i = _getArrIndex(index); str += _brk3; if (printMode == PRINT_MODE_PRETTY) @@ -1558,7 +1561,7 @@ void FirebaseJson::_compileToken(uint16_t &i, char *buf, int &depth, char *searc _refToken = -1; } -void FirebaseJson::_removeToken(uint16_t &i, char *buf, int &depth, char *searchKey, int searchIndex, PRINT_MODE printMode, char *replace, int refTokenIndex, bool removeTk) +void FirebaseJson::_removeToken(uint16_t &i, char *buf, int &depth, char *searchKey, int searchIndex, PRINT_MODE printMode, char *replace, int refTokenIndex, bool removeTk) { bool ncm = false; tk_index_t tk; @@ -1854,6 +1857,7 @@ void FirebaseJson::_parse(const char *path, PRINT_MODE printMode) _parentIndex = -1; _TkRefOk = false; _parseCompleted = 0; + _arrReplaced = false; _refTkIndex = -1; _remTkIndex = -1; _remFirstTk = false; @@ -2155,6 +2159,7 @@ void FirebaseJson::_set(const char *path, const char *data) _parentIndex = -1; _TkRefOk = false; _parseCompleted = 0; + _arrReplaced = false; _refTkIndex = -1; _remTkIndex = -1; _remFirstTk = false; @@ -2183,6 +2188,7 @@ void FirebaseJson::_set(const char *path, const char *data) _parentIndex = -1; _TkRefOk = false; _parseCompleted = 0; + _arrReplaced = false; _refTkIndex = -1; _tokenMatch = false; _paresRes = true; @@ -2230,6 +2236,7 @@ bool FirebaseJson::remove(const String &path) _parentIndex = -1; _TkRefOk = false; _parseCompleted = 0; + _arrReplaced = false; _refTkIndex = -1; _remTkIndex = -1; _remFirstTk = false; @@ -2257,6 +2264,7 @@ bool FirebaseJson::remove(const String &path) _parentIndex = -1; _TkRefOk = false; _parseCompleted = 0; + _arrReplaced = false; _refTkIndex = -1; _tokenMatch = false; _paresRes = true; diff --git a/src/FirebaseJson.h b/src/FirebaseJson.h index 6970ca65..c160f3bc 100644 --- a/src/FirebaseJson.h +++ b/src/FirebaseJson.h @@ -1,9 +1,9 @@ /* - * FirebaseJson, version 2.2.4 + * FirebaseJson, version 2.2.5 * * The Easiest ESP8266/ESP32 Arduino library for parse, create and edit JSON object using relative path. * - * October 27, 2019 + * November 12, 2019 * * Features * - None recursive operations @@ -556,6 +556,7 @@ class FirebaseJson bool _remLastTk = false; bool _collectTk = false; bool _paresRes = false; + bool _arrReplaced = false; char *_qt = nullptr; char *_tab = nullptr; diff --git a/src/README.md b/src/README.md index 4f62df5c..9233dd33 100644 --- a/src/README.md +++ b/src/README.md @@ -1,7 +1,7 @@ # Firebase Realtime Database Arduino Library for ESP8266 -Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.6 +Google's Firebase Realtime Database Arduino Library for ESP8266 v 2.6.7 ## Global functions