Skip to content

Commit

Permalink
Update FirebaseJson.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 19, 2022
1 parent 0a1e441 commit 81df70d
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 181 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Firebase Arduino Client Library for ESP8266 and ESP32",
"version": "3.1.6",
"version": "3.1.7",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "The library supports Firebase products e.g. Realtime database, Cloud Firestore database, Firebase Storage and Google Cloud Storage, Cloud Functions for Firebase and Cloud Messaging. The library also supported other Arduino devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=Firebase Arduino Client Library for ESP8266 and ESP32

version=3.1.6
version=3.1.7

author=Mobizt

Expand Down
11 changes: 7 additions & 4 deletions src/Firebase_ESP_Client.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#ifndef FIREBASE_CLIENT_VERSION
#define FIREBASE_CLIENT_VERSION "3.1.6"
#define FIREBASE_CLIENT_VERSION "3.1.7"
#endif

/**
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v3.1.6
* Google's Firebase ESP Client Main class, Firebase_ESP_Client.h v3.1.7
*
* This library supports Espressif ESP8266 and ESP32 MCUs
*
* Created April 15, 2022
* Created April 19, 2022
*
* Updates:
* - Fixed ESP8266 core v2.x.x compilation error.
* - Fixed FirebaseJson double to string conversion issue.
* - Fixed FirebaseJson array's set by index issue.
* - Add support FirebaseJson non-object type data via setJsonData and setJsonArrayData functions.
* - Remove Nagle disable from TCP client.
*
*
* This work is a part of Firebase ESP Client library
Expand Down
49 changes: 44 additions & 5 deletions src/json/FirebaseJson.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* FirebaseJson, version 2.6.15
* FirebaseJson, version 2.6.17
*
* The Easiest Arduino library to parse, create and edit JSON object using a relative path.
*
* Created April 15, 2022
* Created April 19, 2022
*
* Features
* - Using path to access node element in search style e.g. json.get(result,"a/b/c")
* - Serializing to writable objects e.g. String, C/C++ string, Client (WiFi and Ethernet), File and Hardware Serial.
* - Deserializing from const char, char array, string literal and stream e.g. Client (WiFi and Ethernet), File and
* - Serializing to writable objects e.g. String, C/C++ string, Clients (WiFi, Ethernet, and GSM), File and Hardware Serial.
* - Deserializing from const char, char array, string literal and stream e.g. Clients (WiFi, Ethernet, and GSM), File and
* Hardware Serial.
* - Use managed class, FirebaseJsonData to keep the deserialized result, which can be casted to any primitive data types.
*
Expand Down Expand Up @@ -77,7 +77,27 @@ void FirebaseJsonBase::mCopy(FirebaseJsonBase &other)
bool FirebaseJsonBase::setRaw(const char *raw)
{
mClear();
root = parse(raw);

if (raw)
{
size_t i = 0;
while (i < strlen(raw) && raw[i] == ' ')
{
i++;
}

if (raw[i] == '{' || raw[i] == '[')
{
this->root_type = (raw[i] == '{') ? Root_Type_JSON : Root_Type_JSONArray;
root = parse(raw);
}
else
{
this->root_type = Root_Type_Raw;
root = MB_JSON_CreateRaw(raw);
}
}

return root != NULL;
}

Expand Down Expand Up @@ -768,6 +788,13 @@ void FirebaseJsonBase::mSetElementType(FirebaseJsonData *result)

strcpy(buf, (const char *)MBSTRING_FLASH_MCR("string"));
result->typeNum = JSON_STRING;

// try casting the string to numbers
if (result->stringValue.length() <= 32)
{
mSetResInt(result, result->stringValue.c_str());
mSetResFloat(result, result->stringValue.c_str());
}
}
else if (result->type_num == MB_JSON_NULL)
{
Expand Down Expand Up @@ -931,6 +958,11 @@ FirebaseJsonArray::FirebaseJsonArray(FirebaseJsonArray &other)

FirebaseJsonArray &FirebaseJsonArray::nAdd(MB_JSON *value)
{
if (root_type != Root_Type_JSONArray)
mClear();

root_type = Root_Type_JSONArray;

prepareRoot();

if (value == NULL)
Expand Down Expand Up @@ -967,6 +999,13 @@ bool FirebaseJsonArray::mGetIdx(FirebaseJsonData *result, int index, bool pretti

bool FirebaseJsonArray::mSetIdx(int index, MB_JSON *value)
{
if (root_type != Root_Type_JSONArray)
mClear();

root_type = Root_Type_JSONArray;

prepareRoot();

int size = MB_JSON_GetArraySize(root);
if (index < size)
return MB_JSON_ReplaceItemInArray(root, index, value);
Expand Down
Loading

0 comments on commit 81df70d

Please sign in to comment.