diff --git a/.travis.yml b/.travis.yml index 9d30c387..7c9131df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino -- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - ( cd ${HOME} && wget https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz && tar xf arduino-${ARDUINO_VERSION}-linux64.tar.xz ) @@ -17,17 +17,18 @@ install: - ( LIB=Adafruit_NeoPixel VERSION=${LIB_NEOPIXEL_VERSION} && cd ${HOME} && wget https://github.com/adafruit/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) - ( LIB=Adafruit-GFX-Library VERSION=${LIB_GFX_VERSION} && cd ${HOME} && wget https://github.com/adafruit/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) - ( LIB=Adafruit_SSD1306 VERSION=${LIB_SSD1306_VERSION} && cd ${HOME} && wget https://github.com/adafruit/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) +- ( LIB=ArduinoJson VERSION=${LIB_JSON_VERSION} && cd ${HOME} && wget https://github.com/bblanchon/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) - git clone --branch ${ARDUINO_ESP8266_VERSION} https://github.com/esp8266/Arduino.git ${ARDUINO_ESP8266_ROOT} - git submodule init && git submodule update - ( cd ${ARDUINO_ESP8266_ROOT}/tools && python get.py ) before_script: - mkdir -p ${ARDUINO_HOME}/libraries -- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${TRAVIS_BUILD_DIR}/src/third-party/arduino-json-5.6.7 ArduinoJson && ln -s ${HOME}/SoftwareSerial ./ && ln -s ${HOME}/Adafruit_NeoPixel ./ && ln -s ${HOME}/Adafruit-GFX-Library ./ && ln -s ${HOME}/Adafruit_SSD1306 ./) +- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${HOME}/SoftwareSerial ./ && ln -s ${HOME}/Adafruit_NeoPixel ./ && ln -s ${HOME}/Adafruit-GFX-Library ./ && ln -s ${HOME}/Adafruit_SSD1306 ./ && ln -s ${HOME}/ArduinoJson ./) script: -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseNeoPixel_ESP8266/FirebaseNeoPixel_ESP8266.ino -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseRoom_ESP8266/FirebaseRoom_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseNeoPixel_ESP8266/FirebaseNeoPixel_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseRoom_ESP8266/FirebaseRoom_ESP8266.ino - ( cd contrib/test && make check ) - ( cd contrib/test/modem/ && make test ) - contrib/test/travis/check_all_examples_use_standard_init.sh diff --git a/README.md b/README.md index 9cea7625..62836a1f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,15 @@ This repo contains a collection of samples and an Arduino library that show how to call the [Firebase](https://www.firebase.com/) API from the [ESP8266 Arduino core](https://github.com/esp8266/Arduino). -The Arduino library is [under heavy development](https://github.com/googlesamples/firebase-arduino/issues), **experimental**, **unversioned** and its API is **not stable**. + +## Status + +![Status: Frozen](https://img.shields.io/badge/Status-Frozen-yellow) + +This repository is no longer under active development. No new features will be added and issues are not actively triaged. Pull Requests which fix bugs are welcome and will be reviewed on a best-effort basis. + +If you maintain a fork of this repository that you believe is healthier than the official version, we may consider recommending your fork. Please open a Pull Request if you believe that is the case. + ## Samples @@ -19,6 +27,11 @@ The Arduino library is [under heavy development](https://github.com/googlesample - [FirebaseArduino API Reference](http://firebase-arduino.readthedocs.io/) +## Dependencies +- FirebaseArduino now depends on [ArduinoJson library](https://github.com/bblanchon/ArduinoJson) instead of containing it's own version of it. Please either use Library Manager or download specific version of the library from github. We recommend that ArduinoJson is at least version [5.13.1](https://github.com/bblanchon/ArduinoJson/tree/v5.13.1) + +- ESP8266 Core SDK. We recommend using officially tagged releases and it should be at least [2.4.1](https://github.com/esp8266/Arduino/tree/2.4.1) + ## Disclaimer *This is not an official Google product*. diff --git a/README.rst b/README.rst index 93f9d299..3b34df98 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,10 @@ FirebaseArduino is a library to simplify connecting to the Firebase database fro arduino clients. It is a full abstraction of Firebase's REST API exposed through C++ calls in a wiring -friendly way. All Json parsing is handled by the library and you may deal in pure C/Arduino -types. +friendly way. + +ArduinoJson is no longer part of this library and you will have to install latest version +in Arduino environment yourself. (through Board manager or download+unpack from master: +https://github.com/bblanchon/ArduinoJson) ---------------------------------- diff --git a/contrib/src/modem/command.h b/contrib/src/modem/command.h index 89aaee1a..bc5bde8c 100644 --- a/contrib/src/modem/command.h +++ b/contrib/src/modem/command.h @@ -1,7 +1,7 @@ #ifndef MODEM_COMMAND_H #define MODEM_COMMAND_H -#include "Firebase.h" +#include "FirebaseArduino.h" #include "modem/output-stream.h" #include "modem/input-stream.h" @@ -10,19 +10,19 @@ namespace modem { class Command { public: - Command(Firebase* fbase) : fbase_(fbase) {} + Command(FirebaseArduino* fbase) : fbase_(fbase) {} // Execute command, reading any additional data needed from stream. // Return false if execution failed. virtual bool execute(const String& command, InputStream* in, OutputStream* out) = 0; protected: - Firebase& fbase() { + FirebaseArduino& fbase() { return *fbase_; } private: - Firebase* fbase_; + FirebaseArduino* fbase_; }; } // modem diff --git a/contrib/src/modem/db/DatabaseProtocol.cpp b/contrib/src/modem/db/DatabaseProtocol.cpp index 338daf82..8a053ebb 100644 --- a/contrib/src/modem/db/DatabaseProtocol.cpp +++ b/contrib/src/modem/db/DatabaseProtocol.cpp @@ -42,7 +42,7 @@ void DatabaseProtocol::Execute(const String& command_name, InputStream* in, } std::unique_ptr DatabaseProtocol::CreateCommand(const String& text, - Firebase* fbase) { + FirebaseArduino* fbase) { std::unique_ptr command; if (text == "GET") { command.reset(new GetCommand(fbase)); diff --git a/contrib/src/modem/db/DatabaseProtocol.h b/contrib/src/modem/db/DatabaseProtocol.h index dec7fad5..8da8ed62 100644 --- a/contrib/src/modem/db/DatabaseProtocol.h +++ b/contrib/src/modem/db/DatabaseProtocol.h @@ -13,9 +13,9 @@ class DatabaseProtocol : public SerialProtocol { const std::vector& commands() const override; void Execute(const String& command, InputStream* in, OutputStream* out) override; private: - std::unique_ptr CreateCommand(const String& text, Firebase* fbase); + std::unique_ptr CreateCommand(const String& text, FirebaseArduino* fbase); - std::unique_ptr fbase_; + std::unique_ptr fbase_; }; diff --git a/contrib/src/modem/db/begin-command.cpp b/contrib/src/modem/db/begin-command.cpp index 9658815d..9950f8e7 100644 --- a/contrib/src/modem/db/begin-command.cpp +++ b/contrib/src/modem/db/begin-command.cpp @@ -33,13 +33,14 @@ bool BeginCommand::execute(const String& command, return false; } - new_firebase_.reset(new Firebase(host.c_str(), auth.c_str())); + new_firebase_.reset(new FirebaseArduino()); + new_firebase_.get()->begin(host.c_str(), auth.c_str()); out->println("+OK"); return true; } -std::unique_ptr BeginCommand::firebase() { +std::unique_ptr BeginCommand::firebase() { return std::move(new_firebase_); } diff --git a/contrib/src/modem/db/commands.h b/contrib/src/modem/db/commands.h index f6808024..2bb6bb71 100644 --- a/contrib/src/modem/db/commands.h +++ b/contrib/src/modem/db/commands.h @@ -1,7 +1,7 @@ #ifndef MODEM_DB_COMMANDS_H #define MODEM_DB_COMMANDS_H -#include "Firebase.h" +#include "FirebaseArduino.h" #include "modem/command.h" #include "modem/output-stream.h" #include "modem/input-stream.h" @@ -11,28 +11,28 @@ namespace modem { class GetCommand : public Command { public: - GetCommand(Firebase* fbase) : Command(fbase) {} + GetCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; class SetCommand : public Command { public: - SetCommand(Firebase* fbase) : Command(fbase) {} + SetCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; class RemoveCommand : public Command { public: - RemoveCommand(Firebase* fbase) : Command(fbase) {} + RemoveCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; class PushCommand : public Command { public: - PushCommand(Firebase* fbase) : Command(fbase) {} + PushCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; @@ -44,15 +44,15 @@ class BeginCommand : public Command { bool execute(const String& command, InputStream* in, OutputStream* out); // This can only be called once. - std::unique_ptr firebase(); + std::unique_ptr firebase(); private: - std::unique_ptr new_firebase_; + std::unique_ptr new_firebase_; }; class StreamCommand : public Command { public: - StreamCommand(Firebase* fbase) : Command(fbase) {} + StreamCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; diff --git a/contrib/src/modem/db/get-command.cpp b/contrib/src/modem/db/get-command.cpp index f7c7c7ef..0fb2c478 100644 --- a/contrib/src/modem/db/get-command.cpp +++ b/contrib/src/modem/db/get-command.cpp @@ -13,16 +13,14 @@ bool GetCommand::execute(const String& command, return false; } - std::string path = in->readLine().c_str(); - std::unique_ptr get(fbase().getPtr(path)); - - if (get->error()) { + String path = in->readLine(); + String value = fbase().getString(path); + if (fbase().error().length() != 0) { out->print("-FAIL "); - out->println(get->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } - String value(get->response().c_str()); // TODO implement json parsing to pull and process value. out->print("+"); out->println(value); diff --git a/contrib/src/modem/db/push-command.cpp b/contrib/src/modem/db/push-command.cpp index 8ceb33b7..0ed420e5 100644 --- a/contrib/src/modem/db/push-command.cpp +++ b/contrib/src/modem/db/push-command.cpp @@ -14,15 +14,14 @@ bool PushCommand::execute(const String& command, return false; } - std::string path(in->readStringUntil(' ').c_str()); - std::string data(in->readLine().c_str()); + String path = in->readStringUntil(' '); + String data = in->readLine(); - std::unique_ptr push( - fbase().pushPtr(path, EncodeForJson(data))); + fbase().pushString(path, data); - if (push->error()) { + if (fbase().error().length() != 0) { out->print("-FAIL "); - out->println(push->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } else { out->println("+OK"); diff --git a/contrib/src/modem/db/remove-command.cpp b/contrib/src/modem/db/remove-command.cpp index a144de23..3e17ce56 100644 --- a/contrib/src/modem/db/remove-command.cpp +++ b/contrib/src/modem/db/remove-command.cpp @@ -14,11 +14,11 @@ bool RemoveCommand::execute(const String& command, } String path = in->readLine(); - std::unique_ptr get(fbase().removePtr(path.c_str())); + fbase().remove(path); - if (get->error()) { + if (fbase().error().length() != 0) { out->print("-FAIL "); - out->println(get->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } diff --git a/contrib/src/modem/db/set-command.cpp b/contrib/src/modem/db/set-command.cpp index 71530539..c91821e1 100644 --- a/contrib/src/modem/db/set-command.cpp +++ b/contrib/src/modem/db/set-command.cpp @@ -14,15 +14,14 @@ bool SetCommand::execute(const String& command, return false; } - std::string path(in->readStringUntil(' ').c_str()); - std::string data(in->readLine().c_str()); + String path = in->readStringUntil(' '); + String data = in->readLine(); - std::unique_ptr set(fbase().setPtr(path, - EncodeForJson(data))); + fbase().setString(path, data); - if (set->error()) { + if (fbase().error().length() != 0) { out->print("-FAIL "); - out->println(set->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } else { out->println("+OK"); diff --git a/contrib/src/modem/db/stream-command.cpp b/contrib/src/modem/db/stream-command.cpp index 23c94d61..69e5bd33 100644 --- a/contrib/src/modem/db/stream-command.cpp +++ b/contrib/src/modem/db/stream-command.cpp @@ -13,27 +13,24 @@ bool StreamCommand::execute(const String& command, return false; } - std::string path = in->readLine().c_str(); - std::unique_ptr stream(fbase().streamPtr(path)); + String path = in->readLine().c_str(); + fbase().stream(path); - if (stream->error()) { + if (fbase().error().length() != 0) { out->print("-FAIL "); - out->println(stream->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } - bool running = true; DynamicJsonBuffer buffer; while(running) { - if (stream->available()) { - std::string json; - FirebaseStream::Event event = stream->read(json); + if (fbase().available()) { + FirebaseObject event = fbase().readEvent(); out->print("+"); - out->print(FirebaseStream::EventToName(event).c_str()); + out->print(event.getString("type").c_str()); out->print(" "); - const auto& object = buffer.parseObject(json.c_str()); - String data = object["data"]; - out->println(object["path"].asString()); + String data = event.getString("data"); + out->println(event.getString("path")); out->println(data.length()); out->println(data); } else if (in->available()) { diff --git a/contrib/src/thing/Config.cpp b/contrib/src/thing/Config.cpp index d810630e..133c527a 100644 --- a/contrib/src/thing/Config.cpp +++ b/contrib/src/thing/Config.cpp @@ -1,6 +1,6 @@ #include "Arduino.h" #include "thing/Config.h" -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include namespace thing { diff --git a/contrib/src/thing/Config.h b/contrib/src/thing/Config.h index 3acf3ed1..0cabf61c 100644 --- a/contrib/src/thing/Config.h +++ b/contrib/src/thing/Config.h @@ -4,7 +4,7 @@ #include "Arduino.h" #include #include -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include namespace thing { diff --git a/contrib/src/thing/Portal.cpp b/contrib/src/thing/Portal.cpp index cf70a363..5a105a79 100644 --- a/contrib/src/thing/Portal.cpp +++ b/contrib/src/thing/Portal.cpp @@ -1,5 +1,5 @@ #include "thing/Portal.h" -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include namespace thing { diff --git a/contrib/test/FirebaseArduino_test.cpp b/contrib/test/FirebaseArduino_test.cpp index c2624d8a..186acbc6 100644 --- a/contrib/test/FirebaseArduino_test.cpp +++ b/contrib/test/FirebaseArduino_test.cpp @@ -17,6 +17,7 @@ #include "FirebaseObject.h" #include "gtest/gtest.h" + TEST(FirebaseObjectTest, GetBool) { FirebaseObject obj("true"); EXPECT_EQ(true, obj.getBool()); @@ -44,15 +45,15 @@ TEST(FirebaseObjectTest, GetInt) { TEST(FirebaseObjectTest, GetFloat) { { - FirebaseObject obj("43.0"); - EXPECT_EQ(43, obj.getFloat()); + FirebaseObject obj("43.1"); + EXPECT_FLOAT_EQ(43.1, obj.getFloat()); EXPECT_TRUE(obj.success()); EXPECT_FALSE(obj.failed()); EXPECT_EQ(obj.error(), ""); } { FirebaseObject obj("43"); - EXPECT_EQ(43, obj.getFloat()); + EXPECT_FLOAT_EQ(43, obj.getFloat()); EXPECT_TRUE(obj.success()); EXPECT_FALSE(obj.failed()); EXPECT_EQ(obj.error(), ""); @@ -111,6 +112,59 @@ TEST(FirebaseObjectTest, GetStringFailure) { EXPECT_EQ(obj.error(), "failed to convert to string"); } +TEST(FirebaseObjectTest, GetTwice) { + { + FirebaseObject obj("{\"foo\":\"bar\"}"); + EXPECT_EQ(obj.getString("hop"), ""); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to string"); + + EXPECT_EQ(obj.getString("foo"), "bar"); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } + { + FirebaseObject obj("{\"foo\": 42}"); + EXPECT_EQ(obj.getInt("hop"), 0); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to number"); + + EXPECT_EQ(obj.getInt("foo"), 42); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } + { + FirebaseObject obj("{\"foo\": true}"); + EXPECT_EQ(obj.getBool("hop"), 0); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to bool"); + + EXPECT_EQ(obj.getBool("foo"), true); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } + { + FirebaseObject obj("{\"foo\": 43.1}"); + EXPECT_FLOAT_EQ(obj.getFloat("hop"), 0); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to number"); + + EXPECT_FLOAT_EQ(obj.getFloat("foo"), 43.1); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } +} + + + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/contrib/test/Makefile b/contrib/test/Makefile index 71f5f589..f9063cb6 100644 --- a/contrib/test/Makefile +++ b/contrib/test/Makefile @@ -16,7 +16,7 @@ FIREBASE_DIR=../.. GTEST_DIR=googletest/googletest -ARDUINOJSON_DIR=../../src/third-party/arduino-json-5.6.7 +ARDUINOJSON_DIR=${ARDUINO_HOME}/libraries/ArduinoJson FIREBASE_SRCS=${FIREBASE_DIR}/src/FirebaseObject.cpp GTEST_SRCS=${GTEST_DIR}/src/gtest-all.cpp @@ -27,7 +27,7 @@ SRCS=FirebaseArduino_test.cpp\ OBJS=${SRCS:.cpp=.o} -CXXFLAGS=-I. -I${FIREBASE_DIR}/src -Igoogletest/googletest/include -Igoogletest/googletest -std=c++11 -g +CXXFLAGS=-I. -I${FIREBASE_DIR}/src -I${ARDUINOJSON_DIR}/src -Igoogletest/googletest/include -Igoogletest/googletest -std=c++11 -g LDFLAGS=-lpthread all: check diff --git a/contrib/test/dummies/FirebaseHttpClient_dummy.cpp b/contrib/test/dummies/FirebaseHttpClient_dummy.cpp index 571fa842..2a89ff90 100644 --- a/contrib/test/dummies/FirebaseHttpClient_dummy.cpp +++ b/contrib/test/dummies/FirebaseHttpClient_dummy.cpp @@ -23,6 +23,10 @@ class FirebaseHttpClientDummy : public FirebaseHttpClient { void addHeader(const std::string& UNUSED_ARG(name), const std::string& UNUSED_ARG(value)) override { } + bool connected() override { + return true; + } + void collectHeaders(const char* UNUSED_ARG(header_keys[]), const int UNUSED_ARG(count)) override { } diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 92f1e9fa..916f4d00 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -3,48 +3,22 @@ #include #include "gtest/gtest.h" -#include "Firebase.h" +#include "FirebaseArduino.h" namespace firebase { namespace modem { -class MockFirebase : public Firebase { +class MockFirebase : public FirebaseArduino { public: - MOCK_METHOD1(getPtr, std::unique_ptr(const std::string&)); - MOCK_METHOD2(setPtr, std::unique_ptr(const std::string&, const std::string&)); - MOCK_METHOD2(pushPtr, std::unique_ptr(const std::string&, const std::string&)); - MOCK_METHOD1(removePtr, std::unique_ptr(const std::string&)); - MOCK_METHOD1(streamPtr, std::unique_ptr(const std::string&)); -}; - -class MockFirebaseGet : public FirebaseGet { - public: - MOCK_CONST_METHOD0(response, const std::string&()); - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - -class MockFirebaseSet : public FirebaseSet { - public: - MOCK_CONST_METHOD0(json, const std::string&()); - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - -class MockFirebasePush : public FirebasePush { - public: - MOCK_CONST_METHOD0(name, const std::string&()); - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - -class MockFirebaseRemove : public FirebaseRemove { - public: - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - -class MockFirebaseStream : public FirebaseStream { - public: - MOCK_METHOD0(available, bool()); - MOCK_METHOD1(read, Event(std::string& event)); - MOCK_CONST_METHOD0(error, const FirebaseError&()); + MOCK_METHOD0(error, const String &()); + MOCK_METHOD1(getString, String (const String& path)); + MOCK_METHOD2(pushString, String (const String& path, const String& data)); + MOCK_METHOD1(remove, void(const String& path)); + MOCK_METHOD2(setString, void(const String& path, const String& data)); + MOCK_METHOD0(available, bool ()); + MOCK_METHOD0(readEvent, FirebaseObject ()); + MOCK_METHOD2(begin, void (const String& host, const String& auth)); + MOCK_METHOD1(stream, void (const String& path)); }; } // modem diff --git a/contrib/test/modem/Makefile b/contrib/test/modem/Makefile index a8e15853..bda22d32 100644 --- a/contrib/test/modem/Makefile +++ b/contrib/test/modem/Makefile @@ -34,6 +34,7 @@ FIREBASE_ROOT = ../../.. PROJECT_ROOT = ../.. SRC_ROOT = $(PROJECT_ROOT)/src FIREBASE_SRC_ROOT = $(FIREBASE_ROOT)/src +ARDUINOJSON_DIR=$(ARDUINO_HOME)/libraries/ArduinoJson # Flags passed to the preprocessor. # Set Google Test and Google Mock's header directories as system @@ -45,6 +46,7 @@ CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include \ -I$(PROJECT_ROOT)/test/dummies \ -I$(PROJECT_ROOT)/src \ -I$(FIREBASE_ROOT)/src \ + -I$(ARDUINOJSON_DIR)/src \ -I$(PROJECT_ROOT) # Flags passed to the C++ compiler. @@ -53,8 +55,8 @@ CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11 # All tests produced by this Makefile. Remember to add new tests you # created to the list. TESTS = get-command_test set-command_test remove-command_test \ - push-command_test begin-command_test stream-command_test \ - serial-transceiver_test + push-command_test begin-command_test \ + serial-transceiver_test stream-command_test # All Google Test headers. Usually you shouldn't change this # definition. @@ -128,6 +130,12 @@ arduino_mock_all.a : ArduinoMockAll.o # Builds shared objects. +FirebaseArduino.o : $(FIREBASE_SRC_ROOT)/FirebaseArduino.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/FirebaseArduino.cpp + +FirebaseObject.o : $(FIREBASE_SRC_ROOT)/FirebaseObject.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/FirebaseObject.cpp + Firebase.o : $(FIREBASE_SRC_ROOT)/Firebase.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/Firebase.cpp @@ -142,7 +150,7 @@ get-command.o : $(SRC_ROOT)/modem/db/get-command.cpp get-command_test.o : $(TEST_DIR)/get-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/get-command_test.cpp -get-command_test : get-command_test.o Firebase.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a \ +get-command_test : get-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -153,7 +161,7 @@ set-command.o : $(SRC_ROOT)/modem/db/set-command.cpp set-command_test.o : $(TEST_DIR)/set-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/set-command_test.cpp -set-command_test : set-command.o set-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +set-command_test : set-command.o set-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -164,7 +172,7 @@ remove-command.o : $(SRC_ROOT)/modem/db/remove-command.cpp remove-command_test.o : $(TEST_DIR)/remove-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/remove-command_test.cpp -remove-command_test : remove-command.o remove-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +remove-command_test : remove-command.o remove-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -175,7 +183,7 @@ push-command.o : $(SRC_ROOT)/modem/db/push-command.cpp push-command_test.o : $(TEST_DIR)/push-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/push-command_test.cpp -push-command_test : push-command.o push-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +push-command_test : push-command.o push-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -186,7 +194,7 @@ begin-command.o : $(SRC_ROOT)/modem/db/begin-command.cpp begin-command_test.o : $(TEST_DIR)/begin-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/begin-command_test.cpp -begin-command_test : begin-command.o begin-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +begin-command_test : begin-command.o begin-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -197,7 +205,7 @@ stream-command.o : $(SRC_ROOT)/modem/db/stream-command.cpp stream-command_test.o : $(TEST_DIR)/stream-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/stream-command_test.cpp -stream-command_test : stream-command.o stream-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +stream-command_test : stream-command.o stream-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ diff --git a/contrib/test/modem/WString.h b/contrib/test/modem/WString.h new file mode 100644 index 00000000..4724d8b6 --- /dev/null +++ b/contrib/test/modem/WString.h @@ -0,0 +1,3 @@ +#include + +typedef std::string String; diff --git a/contrib/test/modem/begin-command_test.cpp b/contrib/test/modem/begin-command_test.cpp index e8682cfe..c5700d4f 100644 --- a/contrib/test/modem/begin-command_test.cpp +++ b/contrib/test/modem/begin-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "test/modem/mock-input-stream.h" @@ -52,8 +52,7 @@ TEST_F(BeginCommandTest, hostOnly) { BeginCommand command; ASSERT_TRUE(command.execute("BEGIN_DB", &in_, &out_)); - std::unique_ptr firebase(command.firebase()); - EXPECT_EQ("", firebase->auth()); + std::unique_ptr firebase(command.firebase()); } TEST_F(BeginCommandTest, hostAndAuth) { @@ -66,8 +65,7 @@ TEST_F(BeginCommandTest, hostAndAuth) { BeginCommand command; ASSERT_TRUE(command.execute("BEGIN_DB", &in_, &out_)); - std::unique_ptr firebase(command.firebase()); - EXPECT_EQ(auth, firebase->auth()); + std::unique_ptr firebase(command.firebase()); } TEST_F(BeginCommandTest, neitherHostNorAuth) { @@ -77,7 +75,7 @@ TEST_F(BeginCommandTest, neitherHostNorAuth) { BeginCommand command; ASSERT_FALSE(command.execute("BEGIN_DB", &in_, &out_)); - std::unique_ptr firebase(command.firebase()); + std::unique_ptr firebase(command.firebase()); EXPECT_FALSE(firebase); } } // modem diff --git a/contrib/test/modem/get-command_test.cpp b/contrib/test/modem/get-command_test.cpp index 7372c79e..813fad2f 100644 --- a/contrib/test/modem/get-command_test.cpp +++ b/contrib/test/modem/get-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "test/modem/mock-input-stream.h" @@ -16,22 +16,15 @@ using ::testing::_; class GetCommandTest : public ::testing::Test { protected: void SetUp() override { - get_.reset(new MockFirebaseGet()); } void FeedCommand(const String& path) { const String command_fragment(String(" ") + path); - EXPECT_CALL(in_, readLine()) + EXPECT_CALL(in_, readLine()) .WillOnce(Return(command_fragment)); } bool RunCommand(const FirebaseError& error) { - EXPECT_CALL(*get_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, getPtr(_)) - .WillOnce(Return(ByMove(std::move(get_)))); - GetCommand getCmd(&fbase_); return getCmd.execute("GET", &in_, &out_); } @@ -39,16 +32,18 @@ class GetCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr get_; }; TEST_F(GetCommandTest, gets) { const String path("/test/path"); + const String command_fragment(" /test/path"); FeedCommand(path); const String value("Test value"); - EXPECT_CALL(*get_, response()) - .WillOnce(ReturnRef(value)); + EXPECT_CALL(fbase_, getString(command_fragment)).WillOnce(Return("Test value")); + + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); EXPECT_CALL(out_, print(String("+"))) .WillOnce(Return(1)); @@ -61,13 +56,19 @@ TEST_F(GetCommandTest, gets) { TEST_F(GetCommandTest, handlesError) { FirebaseError error(-200, "Test Error."); + const String command_fragment(" /test/path"); const String path("/test/path"); FeedCommand(path); + const String error_value = "Test Error."; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error_value)); + + EXPECT_CALL(fbase_, getString(command_fragment)).WillOnce(Return("")); + EXPECT_CALL(out_, print(String("-FAIL "))) .WillOnce(Return(1)); - EXPECT_CALL(out_, println(String(error.message().c_str()))) + EXPECT_CALL(out_, println(error_value)) .WillOnce(Return(1)); ASSERT_FALSE(RunCommand(error)); diff --git a/contrib/test/modem/push-command_test.cpp b/contrib/test/modem/push-command_test.cpp index 0b2a1d63..2f2ff82e 100644 --- a/contrib/test/modem/push-command_test.cpp +++ b/contrib/test/modem/push-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "modem/json_util.h" @@ -17,7 +17,6 @@ using ::testing::_; class PushCommandTest : public ::testing::Test { protected: void SetUp() override { - push_.reset(new MockFirebasePush()); } void FeedCommand(const String& path, const String& data) { @@ -40,13 +39,7 @@ class PushCommandTest : public ::testing::Test { .WillOnce(Return(error_message.length())); } - bool RunExpectingData(const String& data, const FirebaseError& error) { - EXPECT_CALL(*push_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, pushPtr(_, EncodeForJson(data))) - .WillOnce(Return(ByMove(std::move(push_)))); - + bool RunCommand() { PushCommand pushCmd(&fbase_); return pushCmd.execute("PUSH", &in_, &out_); } @@ -54,7 +47,6 @@ class PushCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr push_; }; TEST_F(PushCommandTest, sendsData) { @@ -62,22 +54,26 @@ TEST_F(PushCommandTest, sendsData) { const String data("This is a test payload."); FeedCommand(path, data); + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); + ExpectOutput("+OK"); - ASSERT_TRUE(RunExpectingData(data, FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(PushCommandTest, HandlesError) { const String path("/test/path"); const String data("This is a test payload."); - FirebaseError error(-200, "Test error."); FeedCommand(path, data); - ExpectErrorOutput(error.message()); + const String error = "Test Error."; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); - ASSERT_FALSE(RunExpectingData(data, error)); + ExpectErrorOutput(error); + + ASSERT_FALSE(RunCommand()); } } // modem } // firebase - diff --git a/contrib/test/modem/remove-command_test.cpp b/contrib/test/modem/remove-command_test.cpp index 8f71903b..e60f0524 100644 --- a/contrib/test/modem/remove-command_test.cpp +++ b/contrib/test/modem/remove-command_test.cpp @@ -2,7 +2,7 @@ #include "test/modem/mock-output-stream.h" #include "test/modem/mock-input-stream.h" #include "test/mock-firebase.h" -#include "Firebase.h" +#include "FirebaseArduino.h" #include "modem/db/commands.h" namespace firebase { @@ -16,7 +16,6 @@ using ::testing::_; class RemoveCommandTest : public ::testing::Test { protected: void SetUp() override { - remove_.reset(new MockFirebaseRemove()); } void FeedCommand(const String& path) { @@ -25,13 +24,7 @@ class RemoveCommandTest : public ::testing::Test { .WillOnce(Return(command_fragment)); } - bool RunCommand(const FirebaseError& error) { - EXPECT_CALL(*remove_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, removePtr(_)) - .WillOnce(Return(ByMove(std::move(remove_)))); - + bool RunCommand() { RemoveCommand command(&fbase_); return command.execute("REMOVE", &in_, &out_); } @@ -39,30 +32,34 @@ class RemoveCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr remove_; }; TEST_F(RemoveCommandTest, success) { const String path("/test/path"); FeedCommand(path); + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); + EXPECT_CALL(out_, println(String("+OK"))) .WillOnce(Return(3)); - ASSERT_TRUE(RunCommand(FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(RemoveCommandTest, handlesError) { - FirebaseError error(-200, "Test Error."); const String path("/test/path"); FeedCommand(path); EXPECT_CALL(out_, print(String("-FAIL "))) .WillOnce(Return(1)); - EXPECT_CALL(out_, println(String(error.message().c_str()))) + const String error = "Test Error."; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); + + EXPECT_CALL(out_, println(String(error.c_str()))) .WillOnce(Return(1)); - ASSERT_FALSE(RunCommand(error)); + ASSERT_FALSE(RunCommand()); } } // modem diff --git a/contrib/test/modem/serial-transceiver_test.cpp b/contrib/test/modem/serial-transceiver_test.cpp index bcbed2a1..c5328612 100644 --- a/contrib/test/modem/serial-transceiver_test.cpp +++ b/contrib/test/modem/serial-transceiver_test.cpp @@ -1,6 +1,6 @@ #include -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/SerialTransceiver.h" diff --git a/contrib/test/modem/set-command_test.cpp b/contrib/test/modem/set-command_test.cpp index 3bbe4747..99004581 100644 --- a/contrib/test/modem/set-command_test.cpp +++ b/contrib/test/modem/set-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "modem/json_util.h" @@ -17,7 +17,6 @@ using ::testing::_; class SetCommandTest : public ::testing::Test { protected: void SetUp() override { - set_.reset(new MockFirebaseSet()); } void FeedCommand(const String& path, const String& data) { @@ -40,13 +39,7 @@ class SetCommandTest : public ::testing::Test { .WillOnce(Return(error_message.length())); } - bool RunExpectingData(const String& data, const FirebaseError& error) { - EXPECT_CALL(*set_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, setPtr(_, EncodeForJson(data))) - .WillOnce(Return(ByMove(std::move(set_)))); - + bool RunCommand() { SetCommand setCmd(&fbase_); return setCmd.execute("SET", &in_, &out_); } @@ -54,28 +47,30 @@ class SetCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr set_; }; TEST_F(SetCommandTest, sendsData) { const String path("/test/path"); const String data("This is a test payload."); + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); FeedCommand(path, data); ExpectOutput("+OK"); - ASSERT_TRUE(RunExpectingData(data, FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(SetCommandTest, HandlesError) { const String path("/test/path"); const String data("This is a test payload."); - FirebaseError error(-200, "Test error."); + const String error = "TestError"; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); FeedCommand(path, data); - ExpectErrorOutput(error.message()); + ExpectErrorOutput(error); - ASSERT_FALSE(RunExpectingData(data, error)); + ASSERT_FALSE(RunCommand()); } } // modem } // firebase diff --git a/contrib/test/modem/stream-command_test.cpp b/contrib/test/modem/stream-command_test.cpp index 752a01a4..783a24f7 100644 --- a/contrib/test/modem/stream-command_test.cpp +++ b/contrib/test/modem/stream-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "test/modem/mock-input-stream.h" @@ -17,16 +17,9 @@ using ::testing::_; class StreamCommandTest : public ::testing::Test { protected: void SetUp() override { - stream_.reset(new MockFirebaseStream()); } - bool RunCommand(const FirebaseError& error) { - EXPECT_CALL(*stream_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, streamPtr(_)) - .WillOnce(Return(ByMove(std::move(stream_)))); - + bool RunCommand() { StreamCommand cmd(&fbase_); return cmd.execute("BEGIN_STREAM", &in_, &out_); } @@ -34,11 +27,20 @@ class StreamCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr stream_; }; TEST_F(StreamCommandTest, streams) { const String path("/test/path"); + + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(no_error)); + + const String data = "TestValue"; + const String value(String("{\"path\":\"/test/path\",\"data\":\"") + data + "\",\"type\":\"PUT\"}"); + + const FirebaseObject fo = FirebaseObject(value.c_str()); + EXPECT_CALL(fbase_, readEvent()).WillRepeatedly(Return(fo)); + EXPECT_CALL(in_, available()) .WillRepeatedly(Return(true)); @@ -46,17 +48,10 @@ TEST_F(StreamCommandTest, streams) { .WillOnce(Return(path)) .WillOnce(Return("END_STREAM")); - const String data = "Test Value"; - const String value(String("{\"path\" : \"/test/path\", \"data\" : \"") + data + "\"}"); - EXPECT_CALL(*stream_, available()) - .WillOnce(Return(true)) - .WillRepeatedly(Return(false)); - - EXPECT_CALL(*stream_, read(_)) - .WillOnce(Invoke([&value](std::string& json) { - json = value.c_str(); - return FirebaseStream::PUT; - })); + EXPECT_CALL(fbase_, available()) + .WillOnce(Return(true)) + .WillRepeatedly(Return(false)); + EXPECT_CALL(fbase_, stream(path)); EXPECT_CALL(out_, print(String("+"))) .WillOnce(Return(1)); @@ -75,21 +70,23 @@ TEST_F(StreamCommandTest, streams) { EXPECT_CALL(out_, println(String("+OK"))) .WillOnce(Return(1)); - ASSERT_TRUE(RunCommand(FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(StreamCommandTest, handlesError) { - FirebaseError error(-200, "Test Error."); + const String error("Test Error."); const String path("/test/path"); EXPECT_CALL(in_, readLine()) .WillOnce(Return(path)); + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); + EXPECT_CALL(out_, print(String("-FAIL "))) .WillOnce(Return(1)); - EXPECT_CALL(out_, println(String(error.message().c_str()))) + EXPECT_CALL(out_, println(String(error.c_str()))) .WillOnce(Return(1)); - ASSERT_FALSE(RunCommand(error)); + ASSERT_FALSE(RunCommand()); } } // modem diff --git a/examples/FirebaseRoom_ESP8266/README.md b/examples/FirebaseRoom_ESP8266/README.md index 7f1620db..37a38512 100644 --- a/examples/FirebaseRoom_ESP8266/README.md +++ b/examples/FirebaseRoom_ESP8266/README.md @@ -58,7 +58,7 @@ sensor data to Firebase, and trigger actuators from Firebase. - Add Grove modules to modules interactions. - Connect other Grove modules to the room and submit new [PRs](https://github.com/googlesamples/firebase-arduino/pulls) - Reduce the number of Firebase API calls using `FirebaseObject` or `FirebaseStream`. -- Watch or star the [GitHub repo repo](https://github.com/googlesamples/firebase-arduino) +- Watch or star the [GitHub repo](https://github.com/googlesamples/firebase-arduino) - Give [feedback](https://gitter.im/googlesamples/firebase-arduino) - Report [bugs](https://github.com/googlesamples/firebase-arduino/issues/new) - [Fork](https://github.com/googlesamples/firebase-arduino#fork-destination-box) and [contribute](https://github.com/googlesamples/firebase-arduino/blob/master/CONTRIBUTING.md) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index 95cbecc8..fcf32993 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -16,6 +16,7 @@ #include "Firebase.h" using std::unique_ptr; +using std::shared_ptr; namespace { std::string makeFirebaseURL(const std::string& path, const std::string& auth) { @@ -41,169 +42,60 @@ const std::string& Firebase::auth() const { return auth_; } -FirebaseGet Firebase::get(const std::string& path) { - return FirebaseGet(host_, auth_, path, http_.get()); -} - -unique_ptr Firebase::getPtr(const std::string& path) { - return unique_ptr(new FirebaseGet(host_, auth_, path, http_.get())); -} - -FirebaseSet Firebase::set(const std::string& path, const std::string& value) { - return FirebaseSet(host_, auth_, path, value, http_.get()); -} - -unique_ptr Firebase::setPtr(const std::string& path, - const std::string& value) { - return unique_ptr( - new FirebaseSet(host_, auth_, path, value, http_.get())); -} - -FirebasePush Firebase::push(const std::string& path, const std::string& value) { - return FirebasePush(host_, auth_, path, value, http_.get()); -} -unique_ptr Firebase::pushPtr(const std::string& path, const std::string& value) { - return unique_ptr( - new FirebasePush(host_, auth_, path, value, http_.get())); -} - -FirebaseRemove Firebase::remove(const std::string& path) { - return FirebaseRemove(host_, auth_, path, http_.get()); +void FirebaseCall::analyzeError(char* method, int status, const std::string& path_with_auth) { + if (status != 200) { + error_ = FirebaseError(status, + std::string(method) + " " + path_with_auth + + ": " + http_->errorToString(status)); + } else { + error_ = FirebaseError(); + } } -unique_ptr Firebase::removePtr(const std::string& path) { - return unique_ptr( - new FirebaseRemove(host_, auth_, path, http_.get())); +FirebaseCall::~FirebaseCall() { + http_->end(); } -FirebaseStream Firebase::stream(const std::string& path) { - // TODO: create new client dedicated to stream. - return FirebaseStream(host_, auth_, path, http_.get()); +const JsonObject& FirebaseCall::json() { + //TODO(edcoyne): This is not efficient, we should do something smarter with + //the buffers. kotl: Is this still valid? + if (buffer_.get() == NULL) { + buffer_.reset(new StaticJsonBuffer()); + } + return buffer_.get()->parseObject(response().c_str()); } -unique_ptr Firebase::streamPtr(const std::string& path) { - // TODO: create new client dedicated to stream. - return unique_ptr( - new FirebaseStream(host_, auth_, path, http_.get())); +// FirebaseRequest +int FirebaseRequest::sendRequest( + const std::string& host, const std::string& auth, + char* method, const std::string& path, const std::string& data) { + std::string path_with_auth = makeFirebaseURL(path, auth); + http_->setReuseConnection(true); + http_->begin(host, path_with_auth); + int status = http_->sendRequest(method, data); + analyzeError(method, status, path_with_auth); + response_ = http_->getString(); } -// FirebaseCall -FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth, - const char* method, const std::string& path, - const std::string& data, FirebaseHttpClient* http) : http_(http) { +// FirebaseStream +void FirebaseStream::startStreaming(const std::string& host, const std::string& auth, const std::string& path) { std::string path_with_auth = makeFirebaseURL(path, auth); http_->setReuseConnection(true); http_->begin(host, path_with_auth); - bool followRedirect = false; - if (std::string(method) == "STREAM") { - method = "GET"; - http_->addHeader("Accept", "text/event-stream"); - followRedirect = true; - } - - if (followRedirect) { - const char* headers[] = {"Location"}; - http_->collectHeaders(headers, 1); - } + http_->addHeader("Accept", "text/event-stream"); + const char* headers[] = {"Location"}; + http_->collectHeaders(headers, 1); - int status = http_->sendRequest(method, data); + int status = http_->sendRequest("GET", ""); + analyzeError("STREAM", status, path_with_auth); - // TODO: Add a max redirect check - if (followRedirect) { - while (status == HttpStatus::TEMPORARY_REDIRECT) { + while (status == HttpStatus::TEMPORARY_REDIRECT) { std::string location = http_->header("Location"); http_->setReuseConnection(false); http_->end(); http_->setReuseConnection(true); http_->begin(location); status = http_->sendRequest("GET", std::string()); - } - } - - if (status != 200) { - error_ = FirebaseError(status, - std::string(method) + " " + path_with_auth + - ": " + http_->errorToString(status)); - } - - // if not streaming. - if (!followRedirect) { - response_ = http_->getString(); - } -} - -FirebaseCall::~FirebaseCall() { - if (http_) { - http_->end(); - } -} - -const JsonObject& FirebaseCall::json() { - //TODO(edcoyne): This is not efficient, we should do something smarter with - //the buffers. - buffer_ = DynamicJsonBuffer(); - return buffer_.parseObject(response().c_str()); -} - -// FirebaseGet -FirebaseGet::FirebaseGet(const std::string& host, const std::string& auth, - const std::string& path, - FirebaseHttpClient* http) - : FirebaseCall(host, auth, "GET", path, "", http) { -} - -// FirebaseSet -FirebaseSet::FirebaseSet(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, - FirebaseHttpClient* http) - : FirebaseCall(host, auth, "PUT", path, value, http) { - if (!error()) { - // TODO: parse json - json_ = response(); - } -} - -// FirebasePush -FirebasePush::FirebasePush(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, - FirebaseHttpClient* http) - : FirebaseCall(host, auth, "POST", path, value, http) { - if (!error()) { - name_ = json()["name"].as(); - } -} - -// FirebasePush -FirebaseRemove::FirebaseRemove(const std::string& host, const std::string& auth, - const std::string& path, - FirebaseHttpClient* http) - : FirebaseCall(host, auth, "DELETE", path, "", http) { -} - -// FirebaseStream -FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth, - const std::string& path, - FirebaseHttpClient* http) - : FirebaseCall(host, auth, "STREAM", path, "", http) { -} - -bool FirebaseStream::available() { - return http_->getStreamPtr()->available(); -} - -FirebaseStream::Event FirebaseStream::read(std::string& event) { - auto client = http_->getStreamPtr(); - Event type; - std::string typeStr = client->readStringUntil('\n').substring(7).c_str(); - if (typeStr == "put") { - type = Event::PUT; - } else if (typeStr == "patch") { - type = Event::PATCH; - } else { - type = Event::UNKNOWN; } - event = client->readStringUntil('\n').substring(6).c_str(); - client->readStringUntil('\n'); // consume separator - return type; } diff --git a/src/Firebase.h b/src/Firebase.h index 8a352045..44450557 100644 --- a/src/Firebase.h +++ b/src/Firebase.h @@ -20,18 +20,14 @@ #ifndef firebase_h #define firebase_h +#include "WString.h" #include #include +#include + #include "FirebaseHttpClient.h" #include "FirebaseError.h" -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" - -class FirebaseGet; -class FirebaseSet; -class FirebasePush; -class FirebaseRemove; -class FirebaseStream; +#include "FirebaseObject.h" // Firebase REST API client. class Firebase { @@ -41,144 +37,69 @@ class Firebase { const std::string& auth() const; // Fetch json encoded `value` at `path`. - FirebaseGet get(const std::string& path); - virtual std::unique_ptr getPtr(const std::string& path); + void get(const std::string& path); // Set json encoded `value` at `path`. - FirebaseSet set(const std::string& path, const std::string& json); - virtual std::unique_ptr setPtr(const std::string& path, const std::string& json); + void set(const std::string& path, const std::string& json); // Add new json encoded `value` to list at `path`. - FirebasePush push(const std::string& path, const std::string& json); - virtual std::unique_ptr pushPtr(const std::string& path, const std::string& json); + void push(const std::string& path, const std::string& json); // Delete value at `path`. - FirebaseRemove remove(const std::string& path); - virtual std::unique_ptr removePtr(const std::string& path); + void remove(const std::string& path); // Start a stream of events that affect value at `path`. - FirebaseStream stream(const std::string& path); - virtual std::unique_ptr streamPtr(const std::string& path); + void stream(const std::string& path); protected: // Used for testing. Firebase() {} private: - std::unique_ptr http_; + std::shared_ptr http_; std::string host_; std::string auth_; }; + class FirebaseCall { public: - FirebaseCall() {} - FirebaseCall(const std::string& host, const std::string& auth, - const char* method, const std::string& path, - const std::string& data = "", - FirebaseHttpClient* http = NULL); + FirebaseCall(const std::shared_ptr http = NULL) : http_(http) {} virtual ~FirebaseCall(); - virtual const FirebaseError& error() const { + const FirebaseError& error() const { return error_; } - virtual const std::string& response() const { + void analyzeError(char* method, int status, const std::string & path_with_auth); + + const std::string& response() const { return response_; } const JsonObject& json(); protected: - FirebaseHttpClient* http_; + const std::shared_ptr http_; FirebaseError error_; std::string response_; - DynamicJsonBuffer buffer_; -}; - -class FirebaseGet : public FirebaseCall { - public: - FirebaseGet() {} - FirebaseGet(const std::string& host, const std::string& auth, - const std::string& path, FirebaseHttpClient* http = NULL); - - private: - std::string json_; -}; - -class FirebaseSet: public FirebaseCall { - public: - FirebaseSet() {} - FirebaseSet(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, FirebaseHttpClient* http = NULL); - - - private: - std::string json_; + std::shared_ptr> buffer_; }; -class FirebasePush : public FirebaseCall { - public: - FirebasePush() {} - FirebasePush(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, FirebaseHttpClient* http = NULL); - virtual ~FirebasePush() {} - - virtual const std::string& name() const { - return name_; - } - - private: - std::string name_; -}; - -class FirebaseRemove : public FirebaseCall { - public: - FirebaseRemove() {} - FirebaseRemove(const std::string& host, const std::string& auth, - const std::string& path, FirebaseHttpClient* http = NULL); +class FirebaseRequest : public FirebaseCall { + public: + FirebaseRequest(const std::shared_ptr http = NULL) : FirebaseCall(http) { } + virtual ~FirebaseRequest() {} + int sendRequest(const std::string& host, const std::string& auth, + char* method, const std::string& path, const std::string& data = ""); }; - class FirebaseStream : public FirebaseCall { public: - FirebaseStream() {} - FirebaseStream(const std::string& host, const std::string& auth, - const std::string& path, FirebaseHttpClient* http = NULL); + FirebaseStream(const std::shared_ptr http = NULL) : FirebaseCall(http) { } virtual ~FirebaseStream() {} - // Return if there is any event available to read. - virtual bool available(); - - // Event type. - enum Event { - UNKNOWN, - PUT, - PATCH - }; - - static inline std::string EventToName(Event event) { - switch(event) { - case UNKNOWN: - return "UNKNOWN"; - case PUT: - return "PUT"; - case PATCH: - return "PATCH"; - default: - return "INVALID_EVENT_" + event; - } - } - - // Read next json encoded `event` from stream. - virtual Event read(std::string& event); - - const FirebaseError& error() const { - return _error; - } - - private: - FirebaseError _error; + void startStreaming(const std::string& host, const std::string& auth, const std::string& path); }; #endif // firebase_h diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index bdf5105c..bae29595 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -20,12 +20,26 @@ template class std::basic_string; void FirebaseArduino::begin(const String& host, const String& auth) { - http_.reset(FirebaseHttpClient::create()); - http_->setReuseConnection(true); host_ = host.c_str(); auth_ = auth.c_str(); } +void FirebaseArduino::initStream() { + if (stream_http_.get() == nullptr) { + stream_http_.reset(FirebaseHttpClient::create()); + stream_http_->setReuseConnection(true); + stream_.reset(new FirebaseStream(stream_http_)); + } +} + +void FirebaseArduino::initRequest() { + if (req_http_.get() == nullptr) { + req_http_.reset(FirebaseHttpClient::create()); + req_http_->setReuseConnection(true); + req_.reset(new FirebaseRequest(req_http_)); + } +} + String FirebaseArduino::pushInt(const String& path, int value) { return push(path, value); } @@ -44,11 +58,15 @@ String FirebaseArduino::pushString(const String& path, const String& value) { } String FirebaseArduino::push(const String& path, const JsonVariant& value) { - String buf; - value.printTo(buf); - auto push = FirebasePush(host_, auth_, path.c_str(), buf.c_str(), http_.get()); - error_ = push.error(); - return push.name().c_str(); + int size = value.measureLength()+1; + char * buf = new char[size]; + value.printTo(buf, size); + initRequest(); + int status = req_.get()->sendRequest(host_, auth_, "POST", path.c_str(), buf); + error_ = req_.get()->error(); + const char* name = req_.get()->json()["name"].as(); + delete buf; + return name; } void FirebaseArduino::setInt(const String& path, int value) { @@ -69,78 +87,105 @@ void FirebaseArduino::setString(const String& path, const String& value) { } void FirebaseArduino::set(const String& path, const JsonVariant& value) { - String buf; - value.printTo(buf); - auto set = FirebaseSet(host_, auth_, path.c_str(), buf.c_str(), http_.get()); - error_ = set.error(); + int size = value.measureLength()+1; + char* buf= new char[size]; + value.printTo(buf, size); + initRequest(); + req_.get()->sendRequest(host_, auth_, "PUT", path.c_str(), buf); + error_ = req_.get()->error(); + delete buf; +} + +void FirebaseArduino::getRequest(const String& path) { + initRequest(); + req_.get()->sendRequest(host_, auth_, "GET", path.c_str()); + error_ = req_.get()->error(); } FirebaseObject FirebaseArduino::get(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); - error_ = get.error(); + getRequest(path); if (failed()) { return FirebaseObject{""}; } - return FirebaseObject(get.response().c_str()); + return FirebaseObject(req_.get()->response().c_str()); } int FirebaseArduino::getInt(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); - error_ = get.error(); + getRequest(path); if (failed()) { return 0; } - return FirebaseObject(get.response().c_str()).getInt(); + return FirebaseObject(req_.get()->response().c_str()).getInt(); } float FirebaseArduino::getFloat(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); - error_ = get.error(); + getRequest(path); if (failed()) { return 0.0f; } - return FirebaseObject(get.response().c_str()).getFloat(); + return FirebaseObject(req_.get()->response().c_str()).getFloat(); } String FirebaseArduino::getString(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); - error_ = get.error(); + getRequest(path); if (failed()) { return ""; } - return FirebaseObject(get.response().c_str()).getString(); + return FirebaseObject(req_.get()->response().c_str()).getString(); } bool FirebaseArduino::getBool(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); - error_ = get.error(); + getRequest(path); if (failed()) { return ""; } - return FirebaseObject(get.response().c_str()).getBool(); + return FirebaseObject(req_.get()->response().c_str()).getBool(); } void FirebaseArduino::remove(const String& path) { - auto remove = FirebaseRemove(host_, auth_, path.c_str(), http_.get()); - error_ = remove.error(); + initRequest(); + req_.get()->sendRequest(host_, auth_, "DELETE", path.c_str()); + error_ = req_.get()->error(); } void FirebaseArduino::stream(const String& path) { - auto stream = FirebaseStream(host_, auth_, path.c_str(), http_.get()); - error_ = stream.error(); + initStream(); + stream_.get()->startStreaming(host_, auth_, path.c_str()); + error_ = stream_.get()->error(); } bool FirebaseArduino::available() { - return http_->getStreamPtr()->available(); + if (stream_http_.get() == nullptr) { + error_ = FirebaseError(FIREBASE_ERROR_CODES::STREAM_NOT_INITIALIZED, "HTTP stream is not initialized"); + return 0; + } + if (!stream_http_.get()->connected()) { + error_ = FirebaseError(FIREBASE_ERROR_CODES::HTTP_CONNECTION_LOST, "Connection Lost"); + return 0; + } + auto client = stream_http_.get()->getStreamPtr(); + return (client == nullptr) ? false : client->available(); } FirebaseObject FirebaseArduino::readEvent() { - auto client = http_->getStreamPtr(); + if (stream_http_.get() == nullptr) { + return FirebaseObject(""); + } + auto client = stream_http_.get()->getStreamPtr(); + if (client == nullptr) { + return FirebaseObject(""); + } String type = client->readStringUntil('\n').substring(7);; String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().asObject()["type"] = type; + + // required to have a copy of the string but use a char[] format which is + // the only supported format for JsonObject#set (it does not like the std::string of the test env) + char *cstr = new char[type.length() + 1]; + strncpy(cstr, type.c_str(), type.length() + 1); + obj.getJsonVariant().as().set("type", cstr); + delete[] cstr; return obj; } diff --git a/src/FirebaseArduino.h b/src/FirebaseArduino.h index a69f4e16..e2f264e1 100644 --- a/src/FirebaseArduino.h +++ b/src/FirebaseArduino.h @@ -37,7 +37,7 @@ class FirebaseArduino { * \param host Your firebase db host, usually X.firebaseio.com. * \param auth Optional credentials for the db, a secret or token. */ - void begin(const String& host, const String& auth = ""); + virtual void begin(const String& host, const String& auth = ""); /** * Appends the integer value to the node at path. @@ -77,7 +77,7 @@ class FirebaseArduino { * \param value String value that you wish to append to the node. * \return The unique key of the new child node. */ - String pushString(const String& path, const String& value); + virtual String pushString(const String& path, const String& value); /** * Appends the JSON data to the node at path. @@ -123,7 +123,7 @@ class FirebaseArduino { * \param path The path inside of your db to the node you wish to update. * \param value String value that you wish to write. */ - void setString(const String& path, const String& value); + virtual void setString(const String& path, const String& value); /** * Writes the JSON data to the node located at path. @@ -157,7 +157,7 @@ class FirebaseArduino { * \param path The path to the node you wish to retrieve. * \return The string value located at that path. Will only be populated if success() is true. */ - String getString(const String& path); + virtual String getString(const String& path); /** * Gets the boolean value located at path. @@ -181,7 +181,7 @@ class FirebaseArduino { * \param path The path to the node you wish to remove, * including all of its children. */ - void remove(const String& path); + virtual void remove(const String& path); /** * Starts streaming any changes made to the node located at path, including @@ -189,19 +189,16 @@ class FirebaseArduino { * You should check success() after calling. * This changes the state of this object. Once this is called you may start * monitoring available() and calling readEvent() to get new events. - * WARNING: Currently you cannot make another call while the stream is - * running, otherwise you will crash due to memory issues. See: - * https://github.com/googlesamples/firebase-arduino/issues/48 * \param path The path inside of your db to the node you wish to monitor. */ - void stream(const String& path); + virtual void stream(const String& path); /** * Checks if there are new events available. This is only meaningful once * stream() has been called. * \return If a new event is ready. */ - bool available(); + virtual bool available(); /** * Reads the next event in a stream. This is only meaningful once stream() has @@ -209,7 +206,7 @@ class FirebaseArduino { * \return FirebaseObject will have ["type"] that describes the event type, ["path"] * that describes the effected path and ["data"] that was updated. */ - FirebaseObject readEvent(); + virtual FirebaseObject readEvent(); /** * \return Whether the last command was successful. @@ -224,12 +221,19 @@ class FirebaseArduino { /** * \return Error message from last command if failed() is true. */ - const String& error(); + virtual const String& error(); private: std::string host_; std::string auth_; FirebaseError error_; - std::unique_ptr http_; + std::shared_ptr req_http_; + std::shared_ptr req_; + std::shared_ptr stream_http_; + std::shared_ptr stream_; + + void initStream(); + void initRequest(); + void getRequest(const String& path); }; extern FirebaseArduino Firebase; diff --git a/src/FirebaseCloudMessaging.cpp b/src/FirebaseCloudMessaging.cpp index b774fbeb..e88727ab 100644 --- a/src/FirebaseCloudMessaging.cpp +++ b/src/FirebaseCloudMessaging.cpp @@ -63,7 +63,7 @@ const FirebaseError FirebaseCloudMessaging::SendMessageToTopic( const FirebaseError FirebaseCloudMessaging::SendPayload( const char* payload) { - std::unique_ptr client(FirebaseHttpClient::create()); + std::shared_ptr client(FirebaseHttpClient::create()); client->begin("http://fcm.googleapis.com/fcm/send"); client->addHeader("Authorization", auth_header_.c_str()); client->addHeader("Content-Type", "application/json"); diff --git a/src/FirebaseCloudMessaging.h b/src/FirebaseCloudMessaging.h index 7f716b2f..519946c6 100644 --- a/src/FirebaseCloudMessaging.h +++ b/src/FirebaseCloudMessaging.h @@ -26,8 +26,7 @@ #include #include "FirebaseHttpClient.h" #include "FirebaseError.h" -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include // Defines the actual message to the client, for more detail on // options and settings see: diff --git a/src/FirebaseError.h b/src/FirebaseError.h index 2a088aa9..422f9193 100644 --- a/src/FirebaseError.h +++ b/src/FirebaseError.h @@ -1,6 +1,14 @@ #ifndef firebase_error_h #define firebase_error_h + +// These error codes are used in addition to regular HTTP error codes. +// Same error space is shared between HTTP errors and these values. +enum FIREBASE_ERROR_CODES { + HTTP_CONNECTION_LOST = -5, + STREAM_NOT_INITIALIZED = -6 +}; + class FirebaseError { public: // Make it explicit that the empty constructor mean no error. diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 951e7ebf..3fc66eb4 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -33,11 +33,13 @@ class FirebaseHttpClient { virtual std::string errorToString(int error_code) = 0; + virtual bool connected() = 0; + protected: static const uint16_t kFirebasePort = 443; }; static const char kFirebaseFingerprint[] = - "9A E1 A3 B7 88 E0 C9 A3 3F 13 72 4E B5 CB C7 27 41 B2 0F 6A"; + "03:D6:42:23:03:D1:0C:06:73:F7:E2:BD:29:47:13:C3:22:71:37:1B"; // 2020-02 #endif // FIREBASE_HTTP_CLIENT_H diff --git a/src/FirebaseHttpClient_Esp8266.cpp b/src/FirebaseHttpClient_Esp8266.cpp index 7643db1e..c78590dc 100644 --- a/src/FirebaseHttpClient_Esp8266.cpp +++ b/src/FirebaseHttpClient_Esp8266.cpp @@ -15,12 +15,32 @@ #define USE_ESP_ARDUINO_CORE_2_0_0 #endif +// Firebase now returns `Connection: close` after REST streaming redirection. +// +// Override the built-in ESP8266HTTPClient to *not* close the +// connection if forceReuse it set to `true`. +class ForceReuseHTTPClient : public HTTPClient { +public: + void end() { + if (_forceReuse) { + _canReuse = true; + } + HTTPClient::end(); + } + void forceReuse(bool forceReuse) { + _forceReuse = forceReuse; + } +protected: + bool _forceReuse = false; +}; + class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { public: FirebaseHttpClientEsp8266() {} void setReuseConnection(bool reuse) override { http_.setReuse(reuse); + http_.forceReuse(reuse); } void begin(const std::string& url) override { @@ -63,8 +83,12 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { return HTTPClient::errorToString(error_code).c_str(); } + bool connected() override { + return http_.connected(); + } + private: - HTTPClient http_; + ForceReuseHTTPClient http_; }; FirebaseHttpClient* FirebaseHttpClient::create() { diff --git a/src/FirebaseObject.cpp b/src/FirebaseObject.cpp index 44d07f00..6cd9443f 100644 --- a/src/FirebaseObject.cpp +++ b/src/FirebaseObject.cpp @@ -19,7 +19,8 @@ // We need to make a copy of data here, even though it may be large. // It will need to be long lived. FirebaseObject::FirebaseObject(const char* data) : data_{data} { - json_ = buffer_.parse(&data_[0]); + buffer_.reset(new StaticJsonBuffer); + json_ = buffer_.get()->parse(&data_[0]); // TODO(proppy): find a way to check decoding error, tricky because // ArduinoJson doesn't surface error for variant parsing. // See: https://github.com/bblanchon/ArduinoJson/issues/279 @@ -31,6 +32,7 @@ bool FirebaseObject::getBool(const String& path) const { error_ = "failed to convert to bool"; return 0; } + error_ = ""; return static_cast(variant); } @@ -40,6 +42,7 @@ int FirebaseObject::getInt(const String& path) const { error_ = "failed to convert to number"; return 0; } + error_ = ""; return static_cast(variant); } @@ -49,18 +52,25 @@ float FirebaseObject::getFloat(const String& path) const { error_ = "failed to convert to number"; return 0; } + error_ = ""; return static_cast(variant); } String FirebaseObject::getString(const String& path) const { JsonVariant variant = getJsonVariant(path); - if (!variant.is()) { + if (!variant.is() || isNullString(path)) { error_ = "failed to convert to string"; return ""; } + error_ = ""; return static_cast(variant); } +bool FirebaseObject::isNullString(const String& path) const { + JsonVariant variant = getJsonVariant(path); + return variant.is() && variant.asString() == NULL; +} + JsonVariant FirebaseObject::getJsonVariant(const String& path) const { String key(path); char* start = &key[0]; @@ -78,7 +88,7 @@ JsonVariant FirebaseObject::getJsonVariant(const String& path) const { // make `start` a C string. *p = 0; // return json variant at `start`. - json = json.asObject().get(start); + json = json.asObject().get(start); // advance to next path element. start = p + 1; } diff --git a/src/FirebaseObject.h b/src/FirebaseObject.h index 2e1aae44..01caeb5c 100644 --- a/src/FirebaseObject.h +++ b/src/FirebaseObject.h @@ -17,84 +17,98 @@ #ifndef FIREBASE_OBJECT_H #define FIREBASE_OBJECT_H -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" + +#include "WString.h" +#include + +#include + #ifndef FIREBASE_JSONBUFFER_SIZE #define FIREBASE_JSONBUFFER_SIZE JSON_OBJECT_SIZE(32) #endif // FIREBASE_JSONBUFFER_SIZE + + /** * Represents value stored in firebase, may be a singular value (leaf node) or * a tree structure. */ class FirebaseObject { - public: - /** + public: + /** * Construct from json. * \param data JSON formatted string. - */ - FirebaseObject(const char* data); + */ + FirebaseObject(const char* data); - /** + /** * Return the value as a boolean. * \param optional path in the JSON object. * \return result as a bool. - */ - bool getBool(const String& path = "") const; + */ + bool getBool(const String& path = "") const; - /** + /** + * Returns true if specified path is NULL string. + * Useful to detect tree deletions. + * \param optional path in the JSON object. + * \return result as a bool. + */ + bool isNullString(const String& path = "") const; + + /** * Return the value as an int. * \param optional path in the JSON object. * \return result as an integer. - */ - int getInt(const String& path = "") const; + */ + int getInt(const String& path = "") const; - /** + /** * Return the value as a float. * \param optional path in the JSON object. * \return result as a float. - */ - float getFloat(const String& path = "") const; + */ + float getFloat(const String& path = "") const; - /** + /** * Return the value as a String. * \param optional path in the JSON object. * \return result as a String. - */ - String getString(const String& path = "") const; + */ + String getString(const String& path = "") const; - /** + /** * Return the value as a JsonVariant. * \param optional path in the JSON object. * \return result as a JsonVariant. - */ - JsonVariant getJsonVariant(const String& path = "") const; + */ + JsonVariant getJsonVariant(const String& path = "") const; - /** + /** * * \return Whether there was an error decoding or accessing the JSON object. - */ - bool success() const; + */ + bool success() const; - /** + /** * * \return Whether there was an error decoding or accessing the JSON object. - */ - bool failed() const; + */ + bool failed() const; - /** + /** * * \return Error message if failed() is true. - */ - const String& error() const; - - private: - String data_; - StaticJsonBuffer buffer_; - JsonVariant json_; - mutable String error_; + */ + const String& error() const; + + private: + String data_; + std::shared_ptr> buffer_; + JsonVariant json_; + mutable String error_; }; #endif // FIREBASE_OBJECT_H diff --git a/src/third-party/README.md b/src/third-party/README.md deleted file mode 100644 index 76816743..00000000 --- a/src/third-party/README.md +++ /dev/null @@ -1,2 +0,0 @@ -These are packages that we depend upon. They may need to be trimmed, all .cpp -files in them will be compiled by the arduino IDE. diff --git a/src/third-party/arduino-json-5.6.7/ArduinoJson.h b/src/third-party/arduino-json-5.6.7/ArduinoJson.h deleted file mode 100644 index e18b432e..00000000 --- a/src/third-party/arduino-json-5.6.7/ArduinoJson.h +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include "include/ArduinoJson.h" diff --git a/src/third-party/arduino-json-5.6.7/CHANGELOG.md b/src/third-party/arduino-json-5.6.7/CHANGELOG.md deleted file mode 100644 index 070cdcf5..00000000 --- a/src/third-party/arduino-json-5.6.7/CHANGELOG.md +++ /dev/null @@ -1,323 +0,0 @@ -ArduinoJson: change log -======================= - -v5.6.7 ------- - -* Fixed `array[idx].as()` and `object[key].as()` -* Fixed return value of `JsonObject::set()` (issue #350) -* Fixed undefined behavior in `Prettyfier` and `Print` (issue #354) -* Fixed parser that incorrectly rejected floats containing a `+` (issue #349) - -v5.6.6 ------- - -* Fixed `-Wparentheses` warning introduced in v5.6.5 (PR #335 by @nuket) -* Added `.mbedignore` for ARM mbdeb (PR #334 by @nuket) -* Fixed `JsonVariant::success()` which didn't propagate `JsonArray::success()` nor `JsonObject::success()` (issue #342). - -v5.6.5 ------- - -* `as()` now returns `true` when input is `null` (issue #330) - -v5.6.4 ------- - -* Fixed error in float serialization (issue #324) - -v5.6.3 ------- - -* Improved speed of float serialization (about twice faster) -* Added `as()` as a synonym for `as()`... (issue #291) -* Fixed `call of overloaded isinf(double&) is ambiguous` (issue #284) - -v5.6.2 ------- - -* Fixed build when another lib does `#undef isnan` (issue #284) - -v5.6.1 ------- - -* Added missing `#pragma once` (issue #310) - -v5.6.0 ------- - -* ArduinoJson is now a header-only library (issue #199) - -v5.5.1 ------- - -* Fixed compilation error with Intel Galileo (issue #299) - -v5.5.0 ------- - -* Added `JsonVariant::success()` (issue #279) -* Renamed `JsonVariant::invalid()` to `JsonVariant::defaultValue()` - -v5.4.0 ------- - -* Changed `::String` to `ArduinoJson::String` (issue #275) -* Changed `::Print` to `ArduinoJson::Print` too - -v5.3.0 ------- - -* Added custom implementation of `ftoa` (issues #266, #267, #269 and #270) -* Added `JsonVariant JsonBuffer::parse()` (issue #265) -* Fixed `unsigned long` printed as `signed long` (issue #170) - -v5.2.0 ------- - -* Added `JsonVariant::as()` as a synonym for `JsonVariant::as()` (issue #257) -* Added example `JsonHttpClient` (issue #256) -* Added `JsonArray::copyTo()` and `JsonArray::copyFrom()` (issue #254) -* Added `RawJson()` to insert pregenerated JSON portions (issue #259) - -v5.1.1 ------- - -* Removed `String` duplication when one replaces a value in a `JsonObject` (PR #232 by @ulion) - -v5.1.0 ------- - -* Added support of `long long` (issue #171) -* Moved all build settings to `ArduinoJson/Configuration.hpp` - -**BREAKING CHANGE**: -If you defined `ARDUINOJSON_ENABLE_STD_STREAM`, you now need to define it to `1`. - -v5.0.8 ------- - -* Made the library compatible with [PlatformIO](http://platformio.org/) (issue #181) -* Fixed `JsonVariant::is()` that was incorrectly returning false (issue #214) - -v5.0.7 ------- - -* Made library easier to use from a CMake project: simply `add_subdirectory(ArduinoJson/src)` -* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161) - -**BREAKING CHANGES**: -- `JsonVariant(true).as()` now returns `"true"` instead of `"1"` -- `JsonVariant(false).as()` now returns `"false"` instead of `"0"` - -v5.0.6 ------- - -* Added parameter to `DynamicJsonBuffer` constructor to set initial size (issue #152) -* Fixed warning about library category in Arduino 1.6.6 (issue #147) -* Examples: Added a loop to wait for serial port to be ready (issue #156) - -v5.0.5 ------- - -* Added overload `JsonObjectSuscript::set(value, decimals)` (issue #143) -* Use `float` instead of `double` to reduce the size of `JsonVariant` (issue #134) - -v5.0.4 ------- - -* Fixed ambiguous overload with `JsonArraySubscript` and `JsonObjectSubscript` (issue #122) - -v5.0.3 ------- - -* Fixed `printTo(String)` which wrote numbers instead of strings (issue #120) -* Fixed return type of `JsonArray::is()` and some others (issue #121) - -v5.0.2 ------- - -* Fixed segmentation fault in `parseObject(String)` and `parseArray(String)`, when the - `StaticJsonBuffer` is too small to hold a copy of the string -* Fixed Clang warning "register specifier is deprecated" (issue #102) -* Fixed GCC warning "declaration shadows a member" (issue #103) -* Fixed memory alignment, which made ESP8266 crash (issue #104) -* Fixed compilation on Visual Studio 2010 and 2012 (issue #107) - -v5.0.1 ------- - -* Fixed compilation with Arduino 1.0.6 (issue #99) - -v5.0.0 ------- - -* Added support of `String` class (issues #55, #56, #70, #77) -* Added `JsonBuffer::strdup()` to make a copy of a string (issues #10, #57) -* Implicitly call `strdup()` for `String` but not for `char*` (issues #84, #87) -* Added support of non standard JSON input (issue #44) -* Added support of comments in JSON input (issue #88) -* Added implicit cast between numerical types (issues #64, #69, #93) -* Added ability to read number values as string (issue #90) -* Redesigned `JsonVariant` to leverage converting constructors instead of assignment operators (issue #66) -* Switched to new the library layout (requires Arduino 1.0.6 or above) - -**BREAKING CHANGES**: -- `JsonObject::add()` was renamed to `set()` -- `JsonArray::at()` and `JsonObject::at()` were renamed to `get()` -- Number of digits of floating point value are now set with `double_with_n_digits()` - -**Personal note about the `String` class**: -Support of the `String` class has been added to the library because many people use it in their programs. -However, you should not see this as an invitation to use the `String` class. -The `String` class is **bad** because it uses dynamic memory allocation. -Compared to static allocation, it compiles to a bigger, slower program, and is less predictable. -You certainly don't want that in an embedded environment! - -v4.6 ----- - -* Fixed segmentation fault in `DynamicJsonBuffer` when memory allocation fails (issue #92) - -v4.5 ----- - -* Fixed buffer overflow when input contains a backslash followed by a terminator (issue #81) - -**Upgrading is recommended** since previous versions contain a potential security risk. - -Special thanks to [Giancarlo Canales Barreto](https://github.com/gcanalesb) for finding this nasty bug. - -v4.4 ----- - -* Added `JsonArray::measureLength()` and `JsonObject::measureLength()` (issue #75) - -v4.3 ----- - -* Added `JsonArray::removeAt()` to remove an element of an array (issue #58) -* Fixed stack-overflow in `DynamicJsonBuffer` when parsing huge JSON files (issue #65) -* Fixed wrong return value of `parseArray()` and `parseObject()` when allocation fails (issue #68) - -v4.2 ----- - -* Switched back to old library layout (issues #39, #43 and #45) -* Removed global new operator overload (issue #40, #45 and #46) -* Added an example with EthernetServer - -v4.1 ----- - -* Added DynamicJsonBuffer (issue #19) - -v4.0 ----- - -* Unified parser and generator API (issue #23) -* Updated library layout, now requires Arduino 1.0.6 or newer - -**BREAKING CHANGE**: API changed significantly, see [Migrating code to the new API](https://github.com/bblanchon/ArduinoJson/wiki/Migrating-code-to-the-new-API). - - -v3.4 ----- - -* Fixed escaped char parsing (issue #16) - - -v3.3 ----- - -* Added indented output for the JSON generator (issue #11), see example bellow. -* Added `IndentedPrint`, a decorator for `Print` to allow indented output - -Example: - - JsonOject<2> json; - json["key"] = "value"; - json.prettyPrintTo(Serial); - -v3.2 ----- - -* Fixed a bug when adding nested object in `JsonArray` (bug introduced in v3.1). - -v3.1 ----- - -* Calling `Generator::JsonObject::add()` twice with the same `key` now replaces the `value` -* Added `Generator::JsonObject::operator[]`, see bellow the new API -* Added `Generator::JsonObject::remove()` (issue #9) - -Old generator API: - - JsonObject<3> root; - root.add("sensor", "gps"); - root.add("time", 1351824120); - root.add("data", array); - -New generator API: - - JsonObject<3> root; - root["sensor"] = "gps"; - root["time"] = 1351824120; - root["data"] = array; - -v3.0 ----- - -* New parser API, see bellow -* Renamed `JsonHashTable` into `JsonObject` -* Added iterators for `JsonArray` and `JsonObject` (issue #4) - -Old parser API: - - JsonHashTable root = parser.parseHashTable(json); - - char* sensor = root.getString("sensor"); - long time = root.getLong("time"); - double latitude = root.getArray("data").getDouble(0); - double longitude = root.getArray("data").getDouble(1); - -New parser API: - - JsonObject root = parser.parse(json); - - char* sensor = root["sensor"]; - long time = root["time"]; - double latitude = root["data"][0]; - double longitude = root["data"][1]; - -v2.1 ----- - -* Fixed case `#include "jsmn.cpp"` which caused an error in Linux (issue #6) -* Fixed a buffer overrun in JSON Parser (issue #5) - -v2.0 ----- - -* Added JSON encoding (issue #2) -* Renamed the library `ArduinoJsonParser` becomes `ArduinoJson` - -**Breaking change**: you need to add the following line at the top of your program. - - using namespace ArduinoJson::Parser; - -v1.2 ----- - -* Fixed error in JSON parser example (issue #1) - -v1.1 ----- - -* Example: changed `char* json` into `char[] json` so that the bytes are not write protected -* Fixed parsing bug when the JSON contains multi-dimensional arrays - -v1.0 ----- - -Initial release diff --git a/src/third-party/arduino-json-5.6.7/LICENSE.md b/src/third-party/arduino-json-5.6.7/LICENSE.md deleted file mode 100644 index fea79d80..00000000 --- a/src/third-party/arduino-json-5.6.7/LICENSE.md +++ /dev/null @@ -1,10 +0,0 @@ -The MIT License (MIT) ---------------------- - -Copyright © 2014-2016 Benoit BLANCHON - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/third-party/arduino-json-5.6.7/README.md b/src/third-party/arduino-json-5.6.7/README.md deleted file mode 100644 index f578c008..00000000 --- a/src/third-party/arduino-json-5.6.7/README.md +++ /dev/null @@ -1,128 +0,0 @@ -Arduino JSON library -==================== - -[![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/master?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=master)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson) - -*An elegant and efficient JSON library for embedded systems.* - -It's designed to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc). - -It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project. - -Features --------- - -* JSON decoding (comments are supported) -* JSON encoding (with optional indentation) -* Elegant API, very easy to use -* Fixed memory allocation (zero malloc) -* No data duplication (zero copy) -* Portable (written in C++98) -* Self-contained (no external dependency) -* Small footprint -* Header-only library -* MIT License - -Works on --------- - -* All Arduino boards (Uno, Due, Mini, Micro, Yun...) -* ESP8266 -* Teensy -* Intel Edison and Galileo -* PlatformIO -* Energia -* RedBearLab boards (BLE Nano...) -* Computers (Windows, Linux, OSX...) - -See [FAQ: Compatibility issues](https://github.com/bblanchon/ArduinoJson/wiki/Compatibility-issues) - -Quick start ------------ - -#### Decoding / Parsing - -```c++ -char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - -StaticJsonBuffer<200> jsonBuffer; - -JsonObject& root = jsonBuffer.parseObject(json); - -const char* sensor = root["sensor"]; -long time = root["time"]; -double latitude = root["data"][0]; -double longitude = root["data"][1]; -``` - -#### Encoding / Generating - -```c++ -StaticJsonBuffer<200> jsonBuffer; - -JsonObject& root = jsonBuffer.createObject(); -root["sensor"] = "gps"; -root["time"] = 1351824120; - -JsonArray& data = root.createNestedArray("data"); -data.add(48.756080, 6); // 6 is the number of decimals to print -data.add(2.302038, 6); // if not specified, 2 digits are printed - -root.printTo(Serial); -// This prints: -// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} -``` - - -Documentation -------------- - -The documentation is available online in the [Arduino JSON wiki](https://github.com/bblanchon/ArduinoJson/wiki) - -Testimonials ------------- - -From Arduino's Forum user `jflaplante`: -> I tried aJson json-arduino before trying your library. I always ran into memory problem after a while. -> I have no such problem so far with your library. It is working perfectly with my web services. - -From StackOverflow user `thegreendroid`: -> It has a really elegant, simple API and it works like a charm on embedded and Windows/Linux platforms. We recently started using this on an embedded project and I can vouch for its quality. - -From GitHub user `zacsketches`: -> Thanks for a great library!!! -> I've been watching you consistently develop this library over the past six months, and I used it today for a publish and subscribe architecture designed to help hobbyists move into more advanced robotics. Your library allowed me to implement remote subscription in order to facilitate multi-processor robots. -> ArduinoJson saved me a week's worth of time!! - -[From Reddit user `erm_what_`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusjk8c): -> This is a great library and I wouldn't be able to do the project I'm doing without it. I completely recommend it. - -[From Reddit user `makerhacks`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusqg7b): -> I am just starting an ESP8266 clock project and now I can output JSON from my server script and interpret it painlessly. - -[From Twitter user `@hemalchevli`](https://twitter.com/hemalchevli/status/715788439397011456): -> ArduinoJson library should be used as a benchmark/reference for making libraries. Truly elegant. - -Donators --------- - -Special thanks to the following persons and companies who made generous donations to the library author: - -* Robert Murphy USA -* Surge Communications USA -* Alex Scott United Kingdom -* Firepick Services LLC USA -* A B Doodkorte Netherlands -* Scott Smith USA -* Johann Stieger Austria -* Gustavo Donizeti Gini Brazil -* Charles-Henri Hallard France -* Martijn van den Burg Netherlands -* Nick Koumaris Greece -* Jon Williams USA -* Kestutis Liaugminas Lithuania -* Darlington Adibe Nigeria - ---- - -Found this library useful? Please star this project or [help me back with a donation!](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donate%40benoitblanchon%2efr&lc=GB&item_name=Benoit%20Blanchon&item_number=Arduino%20JSON¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted) :smile: diff --git a/src/third-party/arduino-json-5.6.7/examples/IndentedPrintExample/IndentedPrintExample.ino b/src/third-party/arduino-json-5.6.7/examples/IndentedPrintExample/IndentedPrintExample.ino deleted file mode 100644 index 9e86f0f5..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/IndentedPrintExample/IndentedPrintExample.ino +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include - -using namespace ArduinoJson::Internals; - -void setup() { - Serial.begin(9600); - while (!Serial) { - // wait serial port initialization - } - - IndentedPrint serial(Serial); - serial.setTabSize(4); - - serial.println("This is at indentation 0"); - serial.indent(); - serial.println("This is at indentation 1"); - serial.println("This is also at indentation 1"); - serial.indent(); - serial.println("This is at indentation 2"); - - serial.unindent(); - serial.unindent(); - serial.println("This is back at indentation 0"); -} - -void loop() { - // not used in this example -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonGeneratorExample/JsonGeneratorExample.ino b/src/third-party/arduino-json-5.6.7/examples/JsonGeneratorExample/JsonGeneratorExample.ino deleted file mode 100644 index 717a2276..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonGeneratorExample/JsonGeneratorExample.ino +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include - -void setup() { - Serial.begin(9600); - while (!Serial) { - // wait serial port initialization - } - - // Memory pool for JSON object tree. - // - // Inside the brackets, 200 is the size of the pool in bytes. - // If the JSON object is more complex, you need to increase that value. - StaticJsonBuffer<200> jsonBuffer; - - // StaticJsonBuffer allocates memory on the stack, it can be - // replaced by DynamicJsonBuffer which allocates in the heap. - // It's simpler but less efficient. - // - // DynamicJsonBuffer jsonBuffer; - - // Create the root of the object tree. - // - // It's a reference to the JsonObject, the actual bytes are inside the - // JsonBuffer with all the other nodes of the object tree. - // Memory is freed when jsonBuffer goes out of scope. - JsonObject& root = jsonBuffer.createObject(); - - // Add values in the object - // - // Most of the time, you can rely on the implicit casts. - // In other case, you can do root.set("time", 1351824120); - root["sensor"] = "gps"; - root["time"] = 1351824120; - - // Add a nested array. - // - // It's also possible to create the array separately and add it to the - // JsonObject but it's less efficient. - JsonArray& data = root.createNestedArray("data"); - data.add(double_with_n_digits(48.756080, 6)); - data.add(double_with_n_digits(2.302038, 6)); - - root.printTo(Serial); - // This prints: - // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} - - Serial.println(); - - root.prettyPrintTo(Serial); - // This prints: - // { - // "sensor": "gps", - // "time": 1351824120, - // "data": [ - // 48.756080, - // 2.302038 - // ] - // } -} - -void loop() { - // not used in this example -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonHttpClient/JsonHttpClient.ino b/src/third-party/arduino-json-5.6.7/examples/JsonHttpClient/JsonHttpClient.ino deleted file mode 100644 index 6bb3175d..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonHttpClient/JsonHttpClient.ino +++ /dev/null @@ -1,195 +0,0 @@ -// Sample Arduino Json Web Client -// Downloads and parse http://jsonplaceholder.typicode.com/users/1 -// -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include -#include -#include - -EthernetClient client; - -const char* server = "jsonplaceholder.typicode.com"; // server's address -const char* resource = "/users/1"; // http resource -const unsigned long BAUD_RATE = 9600; // serial connection speed -const unsigned long HTTP_TIMEOUT = 10000; // max respone time from server -const size_t MAX_CONTENT_SIZE = 512; // max size of the HTTP response - -// The type of data that we want to extract from the page -struct UserData { - char name[32]; - char company[32]; -}; - -// ARDUINO entry point #1: runs once when you press reset or power the board -void setup() { - initSerial(); - initEthernet(); -} - -// ARDUINO entry point #2: runs over and over again forever -void loop() { - if (connect(server)) { - if (sendRequest(server, resource) && skipResponseHeaders()) { - char response[MAX_CONTENT_SIZE]; - readReponseContent(response, sizeof(response)); - - UserData userData; - if (parseUserData(response, &userData)) { - printUserData(&userData); - } - } - disconnect(); - } - wait(); -} - -// Initialize Serial port -void initSerial() { - Serial.begin(BAUD_RATE); - while (!Serial) { - ; // wait for serial port to initialize - } - Serial.println("Serial ready"); -} - -// Initialize Ethernet library -void initEthernet() { - byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - if (!Ethernet.begin(mac)) { - Serial.println("Failed to configure Ethernet"); - return; - } - Serial.println("Ethernet ready"); - delay(1000); -} - -// Open connection to the HTTP server -bool connect(const char* hostName) { - Serial.print("Connect to "); - Serial.println(hostName); - - bool ok = client.connect(hostName, 80); - - Serial.println(ok ? "Connected" : "Connection Failed!"); - return ok; -} - -// Send the HTTP GET request to the server -bool sendRequest(const char* host, const char* resource) { - Serial.print("GET "); - Serial.println(resource); - - client.print("GET "); - client.print(resource); - client.println(" HTTP/1.1"); - client.print("Host: "); - client.println(server); - client.println("Connection: close"); - client.println(); - - return true; -} - -// Skip HTTP headers so that we are at the beginning of the response's body -bool skipResponseHeaders() { - // HTTP headers end with an empty line - char endOfHeaders[] = "\r\n\r\n"; - - client.setTimeout(HTTP_TIMEOUT); - bool ok = client.find(endOfHeaders); - - if (!ok) { - Serial.println("No response or invalid response!"); - } - - return ok; -} - -// Read the body of the response from the HTTP server -void readReponseContent(char* content, size_t maxSize) { - size_t length = client.readBytes(content, maxSize); - content[length] = 0; - Serial.println(content); -} - -// Parse the JSON from the input string and extract the interesting values -// Here is the JSON we need to parse -// { -// "id": 1, -// "name": "Leanne Graham", -// "username": "Bret", -// "email": "Sincere@april.biz", -// "address": { -// "street": "Kulas Light", -// "suite": "Apt. 556", -// "city": "Gwenborough", -// "zipcode": "92998-3874", -// "geo": { -// "lat": "-37.3159", -// "lng": "81.1496" -// } -// }, -// "phone": "1-770-736-8031 x56442", -// "website": "hildegard.org", -// "company": { -// "name": "Romaguera-Crona", -// "catchPhrase": "Multi-layered client-server neural-net", -// "bs": "harness real-time e-markets" -// } -// } -bool parseUserData(char* content, struct UserData* userData) { - // Compute optimal size of the JSON buffer according to what we need to parse. - // This is only required if you use StaticJsonBuffer. - const size_t BUFFER_SIZE = - JSON_OBJECT_SIZE(8) // the root object has 8 elements - + JSON_OBJECT_SIZE(5) // the "address" object has 5 elements - + JSON_OBJECT_SIZE(2) // the "geo" object has 2 elements - + JSON_OBJECT_SIZE(3); // the "company" object has 3 elements - - // Allocate a temporary memory pool on the stack - StaticJsonBuffer jsonBuffer; - // If the memory pool is too big for the stack, use this instead: - // DynamicJsonBuffer jsonBuffer; - - JsonObject& root = jsonBuffer.parseObject(content); - - if (!root.success()) { - Serial.println("JSON parsing failed!"); - return false; - } - - // Here were copy the strings we're interested in - strcpy(userData->name, root["name"]); - strcpy(userData->company, root["company"]["name"]); - // It's not mandatory to make a copy, you could just use the pointers - // Since, they are pointing inside the "content" buffer, so you need to make - // sure it's still in memory when you read the string - - return true; -} - -// Print the data extracted from the JSON -void printUserData(const struct UserData* userData) { - Serial.print("Name = "); - Serial.println(userData->name); - Serial.print("Company = "); - Serial.println(userData->company); -} - -// Close the connection with the HTTP server -void disconnect() { - Serial.println("Disconnect"); - client.stop(); -} - -// Pause for a 1 minute -void wait() { - Serial.println("Wait 60 seconds"); - delay(60000); -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonParserExample/JsonParserExample.ino b/src/third-party/arduino-json-5.6.7/examples/JsonParserExample/JsonParserExample.ino deleted file mode 100644 index 13536019..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonParserExample/JsonParserExample.ino +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include - -void setup() { - Serial.begin(9600); - while (!Serial) { - // wait serial port initialization - } - - // Memory pool for JSON object tree. - // - // Inside the brackets, 200 is the size of the pool in bytes, - // If the JSON object is more complex, you need to increase that value. - StaticJsonBuffer<200> jsonBuffer; - - // StaticJsonBuffer allocates memory on the stack, it can be - // replaced by DynamicJsonBuffer which allocates in the heap. - // It's simpler but less efficient. - // - // DynamicJsonBuffer jsonBuffer; - - // JSON input string. - // - // It's better to use a char[] as shown here. - // If you use a const char* or a String, ArduinoJson will - // have to make a copy of the input in the JsonBuffer. - char json[] = - "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - - // Root of the object tree. - // - // It's a reference to the JsonObject, the actual bytes are inside the - // JsonBuffer with all the other nodes of the object tree. - // Memory is freed when jsonBuffer goes out of scope. - JsonObject& root = jsonBuffer.parseObject(json); - - // Test if parsing succeeds. - if (!root.success()) { - Serial.println("parseObject() failed"); - return; - } - - // Fetch values. - // - // Most of the time, you can rely on the implicit casts. - // In other case, you can do root["time"].as(); - const char* sensor = root["sensor"]; - long time = root["time"]; - double latitude = root["data"][0]; - double longitude = root["data"][1]; - - // Print values. - Serial.println(sensor); - Serial.println(time); - Serial.println(latitude, 6); - Serial.println(longitude, 6); -} - -void loop() { - // not used in this example -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonServer/JsonServer.ino b/src/third-party/arduino-json-5.6.7/examples/JsonServer/JsonServer.ino deleted file mode 100644 index 895b6729..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonServer/JsonServer.ino +++ /dev/null @@ -1,74 +0,0 @@ -// Sample Arduino Json Web Server -// Created by Benoit Blanchon. -// Heavily inspired by "Web Server" from David A. Mellis and Tom Igoe - -#include -#include -#include - -byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; -IPAddress ip(192, 168, 0, 177); -EthernetServer server(80); - -bool readRequest(EthernetClient& client) { - bool currentLineIsBlank = true; - while (client.connected()) { - if (client.available()) { - char c = client.read(); - if (c == '\n' && currentLineIsBlank) { - return true; - } else if (c == '\n') { - currentLineIsBlank = true; - } else if (c != '\r') { - currentLineIsBlank = false; - } - } - } - return false; -} - -JsonObject& prepareResponse(JsonBuffer& jsonBuffer) { - JsonObject& root = jsonBuffer.createObject(); - - JsonArray& analogValues = root.createNestedArray("analog"); - for (int pin = 0; pin < 6; pin++) { - int value = analogRead(pin); - analogValues.add(value); - } - - JsonArray& digitalValues = root.createNestedArray("digital"); - for (int pin = 0; pin < 14; pin++) { - int value = digitalRead(pin); - digitalValues.add(value); - } - - return root; -} - -void writeResponse(EthernetClient& client, JsonObject& json) { - client.println("HTTP/1.1 200 OK"); - client.println("Content-Type: application/json"); - client.println("Connection: close"); - client.println(); - - json.prettyPrintTo(client); -} - -void setup() { - Ethernet.begin(mac, ip); - server.begin(); -} - -void loop() { - EthernetClient client = server.available(); - if (client) { - bool success = readRequest(client); - if (success) { - StaticJsonBuffer<500> jsonBuffer; - JsonObject& json = prepareResponse(jsonBuffer); - writeResponse(client, json); - } - delay(1); - client.stop(); - } -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonUdpBeacon/JsonUdpBeacon.ino b/src/third-party/arduino-json-5.6.7/examples/JsonUdpBeacon/JsonUdpBeacon.ino deleted file mode 100644 index 7d0fa38a..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonUdpBeacon/JsonUdpBeacon.ino +++ /dev/null @@ -1,55 +0,0 @@ -// Send a JSON object on UDP at regular interval -// -// You can easily test this program with netcat: -// $ nc -ulp 8888 -// -// by Benoit Blanchon, MIT License 2015-2016 - -#include -#include -#include - -byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; -IPAddress localIp(192, 168, 0, 177); -IPAddress remoteIp(192, 168, 0, 109); -unsigned int remotePort = 8888; -unsigned localPort = 8888; -EthernetUDP udp; - -JsonObject& buildJson(JsonBuffer& jsonBuffer) { - JsonObject& root = jsonBuffer.createObject(); - - JsonArray& analogValues = root.createNestedArray("analog"); - for (int pin = 0; pin < 6; pin++) { - int value = analogRead(pin); - analogValues.add(value); - } - - JsonArray& digitalValues = root.createNestedArray("digital"); - for (int pin = 0; pin < 14; pin++) { - int value = digitalRead(pin); - digitalValues.add(value); - } - - return root; -} - -void sendJson(JsonObject& json) { - udp.beginPacket(remoteIp, remotePort); - json.printTo(udp); - udp.println(); - udp.endPacket(); -} - -void setup() { - Ethernet.begin(mac, localIp); - udp.begin(localPort); -} - -void loop() { - delay(1000); - - StaticJsonBuffer<300> jsonBuffer; - JsonObject& json = buildJson(jsonBuffer); - sendJson(json); -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.h b/src/third-party/arduino-json-5.6.7/include/ArduinoJson.h deleted file mode 100644 index 6bed176a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include "ArduinoJson.hpp" -using namespace ArduinoJson; diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson.hpp deleted file mode 100644 index 8ade581d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "ArduinoJson/DynamicJsonBuffer.hpp" -#include "ArduinoJson/JsonArray.hpp" -#include "ArduinoJson/JsonObject.hpp" -#include "ArduinoJson/StaticJsonBuffer.hpp" - -#include "ArduinoJson/Internals/JsonParser.ipp" -#include "ArduinoJson/Internals/JsonSerializer.ipp" -#include "ArduinoJson/JsonArray.ipp" -#include "ArduinoJson/JsonBuffer.ipp" -#include "ArduinoJson/JsonObject.ipp" -#include "ArduinoJson/JsonVariant.ipp" - -using namespace ArduinoJson; diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Configuration.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Configuration.hpp deleted file mode 100644 index 599b85f1..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Configuration.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#ifdef ARDUINO // assume this is an embedded platform - -// store using float instead of double to reduce the memory usage (issue #134) -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 0 -#endif - -// store using a long because it usually match the size of a float. -#ifndef ARDUINOJSON_USE_LONG_LONG -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif -#ifndef ARDUINOJSON_USE_INT64 -#define ARDUINOJSON_USE_INT64 0 -#endif - -// arduino has its own implementation of String to replace std::string -#ifndef ARDUINOJSON_USE_ARDUINO_STRING -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#endif - -// arduino doesn't support STL stream -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 0 -#endif - -#ifndef ARDUINOJSON_ENABLE_ALIGNMENT -#ifdef ARDUINO_ARCH_AVR -// alignment isn't needed for 8-bit AVR -#define ARDUINOJSON_ENABLE_ALIGNMENT 0 -#else -// but must processor needs pointer to be align on word size -#define ARDUINOJSON_ENABLE_ALIGNMENT 1 -#endif -#endif - -#else // assume this is a computer - -// on a computer we have plenty of memory so we can use doubles -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 1 -#endif - -// use long long when available -#ifndef ARDUINOJSON_USE_LONG_LONG -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) -#define ARDUINOJSON_USE_LONG_LONG 1 -#else -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif -#endif - -// use _int64 on old versions of Visual Studio -#ifndef ARDUINOJSON_USE_INT64 -#if defined(_MSC_VER) && _MSC_VER <= 1700 -#define ARDUINOJSON_USE_INT64 1 -#else -#define ARDUINOJSON_USE_INT64 0 -#endif -#endif - -// on a computer, we can use std::string -#ifndef ARDUINOJSON_USE_ARDUINO_STRING -#define ARDUINOJSON_USE_ARDUINO_STRING 0 -#endif - -// on a computer, we can assume that the STL is there -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 1 -#endif - -#ifndef ARDUINOJSON_ENABLE_ALIGNMENT -// even if not required, most cpu's are faster with aligned pointers -#define ARDUINOJSON_ENABLE_ALIGNMENT 1 -#endif - -#endif - -#if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64 -#error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/DynamicJsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/DynamicJsonBuffer.hpp deleted file mode 100644 index 2e02b097..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/DynamicJsonBuffer.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/BlockJsonBuffer.hpp" - -namespace ArduinoJson { -// Implements a JsonBuffer with dynamic memory allocation. -// You are strongly encouraged to consider using StaticJsonBuffer which is much -// more suitable for embedded systems. -typedef Internals::BlockJsonBuffer - DynamicJsonBuffer; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/BlockJsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/BlockJsonBuffer.hpp deleted file mode 100644 index 33873608..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/BlockJsonBuffer.hpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" - -#include - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnon-virtual-dtor" -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#endif - -namespace ArduinoJson { -namespace Internals { -class DefaultAllocator { - public: - void* allocate(size_t size) { - return malloc(size); - } - void deallocate(void* pointer) { - free(pointer); - } -}; - -template -class BlockJsonBuffer : public JsonBuffer { - struct Block; - struct EmptyBlock { - Block* next; - size_t capacity; - size_t size; - }; - struct Block : EmptyBlock { - uint8_t data[1]; - }; - - public: - BlockJsonBuffer(size_t initialSize = 256) - : _head(NULL), _nextBlockSize(initialSize) {} - - ~BlockJsonBuffer() { - Block* currentBlock = _head; - - while (currentBlock != NULL) { - Block* nextBlock = currentBlock->next; - _allocator.deallocate(currentBlock); - currentBlock = nextBlock; - } - } - - size_t size() const { - size_t total = 0; - for (const Block* b = _head; b; b = b->next) total += b->size; - return total; - } - - virtual void* alloc(size_t bytes) { - return canAllocInHead(bytes) ? allocInHead(bytes) : allocInNewBlock(bytes); - } - - private: - bool canAllocInHead(size_t bytes) const { - return _head != NULL && _head->size + bytes <= _head->capacity; - } - - void* allocInHead(size_t bytes) { - void* p = _head->data + _head->size; - _head->size += round_size_up(bytes); - return p; - } - - void* allocInNewBlock(size_t bytes) { - size_t capacity = _nextBlockSize; - if (bytes > capacity) capacity = bytes; - if (!addNewBlock(capacity)) return NULL; - _nextBlockSize *= 2; - return allocInHead(bytes); - } - - bool addNewBlock(size_t capacity) { - size_t bytes = sizeof(EmptyBlock) + capacity; - Block* block = static_cast(_allocator.allocate(bytes)); - if (block == NULL) return false; - block->capacity = capacity; - block->size = 0; - block->next = _head; - _head = block; - return true; - } - - TAllocator _allocator; - Block* _head; - size_t _nextBlockSize; -}; -} -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Comments.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Comments.hpp deleted file mode 100644 index 968625ff..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Comments.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Internals { -inline const char *skipCStyleComment(const char *ptr) { - ptr += 2; - for (;;) { - if (ptr[0] == '\0') return ptr; - if (ptr[0] == '*' && ptr[1] == '/') return ptr + 2; - ptr++; - } -} - -inline const char *skipCppStyleComment(const char *ptr) { - ptr += 2; - for (;;) { - if (ptr[0] == '\0' || ptr[0] == '\n') return ptr; - ptr++; - } -} - -inline const char *skipSpacesAndComments(const char *ptr) { - for (;;) { - switch (ptr[0]) { - case ' ': - case '\t': - case '\r': - case '\n': - ptr++; - continue; - case '/': - switch (ptr[1]) { - case '*': - ptr = skipCStyleComment(ptr); - break; - case '/': - ptr = skipCppStyleComment(ptr); - break; - default: - return ptr; - } - break; - default: - return ptr; - } - } -} -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DummyPrint.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DummyPrint.hpp deleted file mode 100644 index dfd5a327..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DummyPrint.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A dummy Print implementation used in JsonPrintable::measureLength() -class DummyPrint : public Print { - public: - virtual size_t write(uint8_t) { return 1; } -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DynamicStringBuilder.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DynamicStringBuilder.hpp deleted file mode 100644 index 07536f2e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DynamicStringBuilder.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" -#include "../String.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A Print implementation that allows to write in a String -class DynamicStringBuilder : public Print { - public: - DynamicStringBuilder(String &str) : _str(str) {} - - virtual size_t write(uint8_t c) { - // Need to cast to char, otherwise String will print a number (issue #120) - _str += static_cast(c); - return 1; - } - - private: - DynamicStringBuilder &operator=(const DynamicStringBuilder &); - - String &_str; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Encoding.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Encoding.hpp deleted file mode 100644 index 8dd7a44e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Encoding.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -class Encoding { - public: - // Optimized for code size on a 8-bit AVR - static char escapeChar(char c) { - const char *p = escapeTable(false); - while (p[0] && p[1] != c) { - p += 2; - } - return p[0]; - } - - // Optimized for code size on a 8-bit AVR - static char unescapeChar(char c) { - const char *p = escapeTable(true); - for (;;) { - if (p[0] == '\0') return c; - if (p[0] == c) return p[1]; - p += 2; - } - } - - private: - static const char *escapeTable(bool excludeIdenticals) { - return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0]; - } -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/IndentedPrint.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/IndentedPrint.hpp deleted file mode 100644 index 94dd6f33..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/IndentedPrint.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Decorator on top of Print to allow indented output. -// This class is used by JsonPrintable::prettyPrintTo() but can also be used -// for your own purpose, like logging. -class IndentedPrint : public Print { - public: - explicit IndentedPrint(Print &p) : sink(&p) { - level = 0; - tabSize = 2; - isNewLine = true; - } - - virtual size_t write(uint8_t c) { - size_t n = 0; - if (isNewLine) n += writeTabs(); - n += sink->write(c); - isNewLine = c == '\n'; - return n; - } - - // Adds one level of indentation - void indent() { - if (level < MAX_LEVEL) level++; - } - - // Removes one level of indentation - void unindent() { - if (level > 0) level--; - } - - // Set the number of space printed for each level of indentation - void setTabSize(uint8_t n) { - if (n < MAX_TAB_SIZE) tabSize = n & MAX_TAB_SIZE; - } - - private: - Print *sink; - uint8_t level : 4; - uint8_t tabSize : 3; - bool isNewLine : 1; - - size_t writeTabs() { - size_t n = 0; - for (int i = 0; i < level * tabSize; i++) n += sink->write(' '); - return n; - } - - static const int MAX_LEVEL = 15; // because it's only 4 bits - static const int MAX_TAB_SIZE = 7; // because it's only 3 bits -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonBufferAllocated.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonBufferAllocated.hpp deleted file mode 100644 index 97328faf..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonBufferAllocated.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" - -namespace ArduinoJson { -namespace Internals { - -class JsonBufferAllocated { - public: - void *operator new(size_t n, JsonBuffer *jsonBuffer) throw() { - if (!jsonBuffer) return NULL; - return jsonBuffer->alloc(n); - } - - void operator delete(void *, JsonBuffer *) throw() {} -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonFloat.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonFloat.hpp deleted file mode 100644 index b6dc20f0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonFloat.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" - -namespace ArduinoJson { -namespace Internals { - -#if ARDUINOJSON_USE_DOUBLE -typedef double JsonFloat; -#else -typedef float JsonFloat; -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonInteger.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonInteger.hpp deleted file mode 100644 index 4b64f5c5..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonInteger.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" - -namespace ArduinoJson { -namespace Internals { - -#if ARDUINOJSON_USE_LONG_LONG -typedef long long JsonInteger; -typedef unsigned long long JsonUInt; -#elif ARDUINOJSON_USE_INT64 -typedef __int64 JsonInteger; -typedef unsigned _int64 JsonUInt; -#else -typedef long JsonInteger; -typedef unsigned long JsonUInt; -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.hpp deleted file mode 100644 index 3bd0f937..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" -#include "../JsonVariant.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Parse JSON string to create JsonArrays and JsonObjects -// This internal class is not indended to be used directly. -// Instead, use JsonBuffer.parseArray() or .parseObject() -class JsonParser { - public: - JsonParser(JsonBuffer *buffer, char *json, uint8_t nestingLimit) - : _buffer(buffer), - _readPtr(json ? json : ""), - _writePtr(json), - _nestingLimit(nestingLimit) {} - - JsonArray &parseArray(); - JsonObject &parseObject(); - - JsonVariant parseVariant() { - JsonVariant result; - parseAnythingTo(&result); - return result; - } - - private: - bool skip(char charToSkip); - - const char *parseString(); - bool parseAnythingTo(JsonVariant *destination); - FORCE_INLINE bool parseAnythingToUnsafe(JsonVariant *destination); - - inline bool parseArrayTo(JsonVariant *destination); - inline bool parseObjectTo(JsonVariant *destination); - inline bool parseStringTo(JsonVariant *destination); - - static inline bool isInRange(char c, char min, char max) { - return min <= c && c <= max; - } - - static inline bool isLetterOrNumber(char c) { - return isInRange(c, '0', '9') || isInRange(c, 'a', 'z') || - isInRange(c, 'A', 'Z') || c == '+' || c == '-' || c == '.'; - } - - static inline bool isQuote(char c) { - return c == '\'' || c == '\"'; - } - - JsonBuffer *_buffer; - const char *_readPtr; - char *_writePtr; - uint8_t _nestingLimit; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.ipp deleted file mode 100644 index 6a4e1b85..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.ipp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Comments.hpp" -#include "JsonParser.hpp" - -inline bool ArduinoJson::Internals::JsonParser::skip(char charToSkip) { - const char *ptr = skipSpacesAndComments(_readPtr); - if (*ptr != charToSkip) return false; - ptr++; - _readPtr = skipSpacesAndComments(ptr); - return true; -} - -inline bool ArduinoJson::Internals::JsonParser::parseAnythingTo( - JsonVariant *destination) { - if (_nestingLimit == 0) return false; - _nestingLimit--; - bool success = parseAnythingToUnsafe(destination); - _nestingLimit++; - return success; -} - -inline bool ArduinoJson::Internals::JsonParser::parseAnythingToUnsafe( - JsonVariant *destination) { - _readPtr = skipSpacesAndComments(_readPtr); - - switch (*_readPtr) { - case '[': - return parseArrayTo(destination); - - case '{': - return parseObjectTo(destination); - - default: - return parseStringTo(destination); - } -} - -inline ArduinoJson::JsonArray & -ArduinoJson::Internals::JsonParser::parseArray() { - // Create an empty array - JsonArray &array = _buffer->createArray(); - - // Check opening braket - if (!skip('[')) goto ERROR_MISSING_BRACKET; - if (skip(']')) goto SUCCESS_EMPTY_ARRAY; - - // Read each value - for (;;) { - // 1 - Parse value - JsonVariant value; - if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE; - if (!array.add(value)) goto ERROR_NO_MEMORY; - - // 2 - More values? - if (skip(']')) goto SUCCES_NON_EMPTY_ARRAY; - if (!skip(',')) goto ERROR_MISSING_COMMA; - } - -SUCCESS_EMPTY_ARRAY: -SUCCES_NON_EMPTY_ARRAY: - return array; - -ERROR_INVALID_VALUE: -ERROR_MISSING_BRACKET: -ERROR_MISSING_COMMA: -ERROR_NO_MEMORY: - return JsonArray::invalid(); -} - -inline bool ArduinoJson::Internals::JsonParser::parseArrayTo( - JsonVariant *destination) { - JsonArray &array = parseArray(); - if (!array.success()) return false; - - *destination = array; - return true; -} - -inline ArduinoJson::JsonObject & -ArduinoJson::Internals::JsonParser::parseObject() { - // Create an empty object - JsonObject &object = _buffer->createObject(); - - // Check opening brace - if (!skip('{')) goto ERROR_MISSING_BRACE; - if (skip('}')) goto SUCCESS_EMPTY_OBJECT; - - // Read each key value pair - for (;;) { - // 1 - Parse key - const char *key = parseString(); - if (!key) goto ERROR_INVALID_KEY; - if (!skip(':')) goto ERROR_MISSING_COLON; - - // 2 - Parse value - JsonVariant value; - if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE; - if (!object.set(key, value)) goto ERROR_NO_MEMORY; - - // 3 - More keys/values? - if (skip('}')) goto SUCCESS_NON_EMPTY_OBJECT; - if (!skip(',')) goto ERROR_MISSING_COMMA; - } - -SUCCESS_EMPTY_OBJECT: -SUCCESS_NON_EMPTY_OBJECT: - return object; - -ERROR_INVALID_KEY: -ERROR_INVALID_VALUE: -ERROR_MISSING_BRACE: -ERROR_MISSING_COLON: -ERROR_MISSING_COMMA: -ERROR_NO_MEMORY: - return JsonObject::invalid(); -} - -inline bool ArduinoJson::Internals::JsonParser::parseObjectTo( - JsonVariant *destination) { - JsonObject &object = parseObject(); - if (!object.success()) return false; - - *destination = object; - return true; -} - -inline const char *ArduinoJson::Internals::JsonParser::parseString() { - const char *readPtr = _readPtr; - char *writePtr = _writePtr; - - char c = *readPtr; - - if (isQuote(c)) { // quotes - char stopChar = c; - for (;;) { - c = *++readPtr; - if (c == '\0') break; - - if (c == stopChar) { - readPtr++; - break; - } - - if (c == '\\') { - // replace char - c = Encoding::unescapeChar(*++readPtr); - if (c == '\0') break; - } - - *writePtr++ = c; - } - } else { // no quotes - for (;;) { - if (!isLetterOrNumber(c)) break; - *writePtr++ = c; - c = *++readPtr; - } - } - // end the string here - *writePtr++ = '\0'; - - const char *startPtr = _writePtr; - - // update end ptr - _readPtr = readPtr; - _writePtr = writePtr; - - // return pointer to unquoted string - return startPtr; -} - -inline bool ArduinoJson::Internals::JsonParser::parseStringTo( - JsonVariant *destination) { - bool hasQuotes = isQuote(_readPtr[0]); - const char *value = parseString(); - if (value == NULL) return false; - if (hasQuotes) { - *destination = value; - } else { - *destination = RawJson(value); - } - return true; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonPrintable.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonPrintable.hpp deleted file mode 100644 index 45b6a942..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonPrintable.hpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "DummyPrint.hpp" -#include "DynamicStringBuilder.hpp" -#include "IndentedPrint.hpp" -#include "JsonSerializer.hpp" -#include "JsonWriter.hpp" -#include "Prettyfier.hpp" -#include "StaticStringBuilder.hpp" - -#if ARDUINOJSON_ENABLE_STD_STREAM -#include "StreamPrintAdapter.hpp" -#endif - -namespace ArduinoJson { -namespace Internals { - -// Implements all the overloads of printTo() and prettyPrintTo() -// Caution: this class use a template parameter to avoid virtual methods. -// This is a bit curious but allows to reduce the size of JsonVariant, JsonArray -// and JsonObject. -template -class JsonPrintable { - public: - size_t printTo(Print &print) const { - JsonWriter writer(print); - JsonSerializer::serialize(downcast(), writer); - return writer.bytesWritten(); - } - -#if ARDUINOJSON_ENABLE_STD_STREAM - std::ostream &printTo(std::ostream &os) const { - StreamPrintAdapter adapter(os); - printTo(adapter); - return os; - } -#endif - - size_t printTo(char *buffer, size_t bufferSize) const { - StaticStringBuilder sb(buffer, bufferSize); - return printTo(sb); - } - - size_t printTo(String &str) const { - DynamicStringBuilder sb(str); - return printTo(sb); - } - - size_t prettyPrintTo(IndentedPrint &print) const { - Prettyfier p(print); - return printTo(p); - } - - size_t prettyPrintTo(char *buffer, size_t bufferSize) const { - StaticStringBuilder sb(buffer, bufferSize); - return prettyPrintTo(sb); - } - - size_t prettyPrintTo(Print &print) const { - IndentedPrint indentedPrint = IndentedPrint(print); - return prettyPrintTo(indentedPrint); - } - - size_t prettyPrintTo(String &str) const { - DynamicStringBuilder sb(str); - return prettyPrintTo(sb); - } - - size_t measureLength() const { - DummyPrint dp; - return printTo(dp); - } - - size_t measurePrettyLength() const { - DummyPrint dp; - return prettyPrintTo(dp); - } - - private: - const T &downcast() const { - return *static_cast(this); - } -}; - -#if ARDUINOJSON_ENABLE_STD_STREAM -template -inline std::ostream &operator<<(std::ostream &os, const JsonPrintable &v) { - return v.printTo(os); -} -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.hpp deleted file mode 100644 index 1b00c654..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonWriter.hpp" - -namespace ArduinoJson { - -class JsonArray; -class JsonArraySubscript; -class JsonObject; -template -class JsonObjectSubscript; -class JsonVariant; - -namespace Internals { - -class JsonSerializer { - public: - static void serialize(const JsonArray &, JsonWriter &); - static void serialize(const JsonArraySubscript &, JsonWriter &); - static void serialize(const JsonObject &, JsonWriter &); - template - static void serialize(const JsonObjectSubscript &, JsonWriter &); - static void serialize(const JsonVariant &, JsonWriter &); -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.ipp deleted file mode 100644 index 5b8343b0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.ipp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonArray.hpp" -#include "../JsonArraySubscript.hpp" -#include "../JsonObject.hpp" -#include "../JsonObjectSubscript.hpp" -#include "../JsonVariant.hpp" -#include "JsonSerializer.hpp" - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonArray& array, JsonWriter& writer) { - writer.beginArray(); - - JsonArray::const_iterator it = array.begin(); - while (it != array.end()) { - serialize(*it, writer); - - ++it; - if (it == array.end()) break; - - writer.writeComma(); - } - - writer.endArray(); -} - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonArraySubscript& arraySubscript, JsonWriter& writer) { - serialize(arraySubscript.as(), writer); -} - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonObject& object, JsonWriter& writer) { - writer.beginObject(); - - JsonObject::const_iterator it = object.begin(); - while (it != object.end()) { - writer.writeString(it->key); - writer.writeColon(); - serialize(it->value, writer); - - ++it; - if (it == object.end()) break; - - writer.writeComma(); - } - - writer.endObject(); -} - -template -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonObjectSubscript& objectSubscript, JsonWriter& writer) { - serialize(objectSubscript.template as(), writer); -} - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonVariant& variant, JsonWriter& writer) { - switch (variant._type) { - case JSON_UNDEFINED: - return; - - case JSON_ARRAY: - serialize(*variant._content.asArray, writer); - return; - - case JSON_OBJECT: - serialize(*variant._content.asObject, writer); - return; - - case JSON_STRING: - writer.writeString(variant._content.asString); - return; - - case JSON_UNPARSED: - writer.writeRaw(variant._content.asString); - return; - - case JSON_NEGATIVE_INTEGER: - writer.writeRaw('-'); - case JSON_POSITIVE_INTEGER: - writer.writeInteger(variant._content.asInteger); - return; - - case JSON_BOOLEAN: - writer.writeBoolean(variant._content.asInteger != 0); - return; - - default: - uint8_t decimals = - static_cast(variant._type - JSON_FLOAT_0_DECIMALS); - writer.writeFloat(variant._content.asFloat, decimals); - } -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantAs.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantAs.hpp deleted file mode 100644 index 97c968ed..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantAs.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Internals { - -// A metafunction that returns the type of the value returned by -// JsonVariant::as() -template -struct JsonVariantAs { - typedef T type; -}; - -template <> -struct JsonVariantAs { - typedef const char* type; -}; - -template <> -struct JsonVariantAs { - typedef JsonArray& type; -}; - -template <> -struct JsonVariantAs { - typedef const JsonArray& type; -}; - -template <> -struct JsonVariantAs { - typedef JsonObject& type; -}; - -template <> -struct JsonVariantAs { - typedef const JsonObject& type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantContent.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantContent.hpp deleted file mode 100644 index 5cd75ab7..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantContent.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonFloat.hpp" -#include "JsonInteger.hpp" - -namespace ArduinoJson { - -// Forward declarations -class JsonArray; -class JsonObject; - -namespace Internals { -// A union that defines the actual content of a JsonVariant. -// The enum JsonVariantType determines which member is in use. -union JsonVariantContent { - JsonFloat asFloat; // used for double and float - JsonUInt asInteger; // used for bool, char, short, int and longs - const char* asString; // asString can be null - JsonArray* asArray; // asArray cannot be null - JsonObject* asObject; // asObject cannot be null -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantType.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantType.hpp deleted file mode 100644 index 5bb7ef7b..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantType.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -class JsonArray; -class JsonObject; - -namespace Internals { - -// Enumerated type to know the current type of a JsonVariant. -// The value determines which member of JsonVariantContent is used. -enum JsonVariantType { - JSON_UNDEFINED, // JsonVariant has not been initialized - JSON_UNPARSED, // JsonVariant contains an unparsed string - JSON_STRING, // JsonVariant stores a const char* - JSON_BOOLEAN, // JsonVariant stores a bool - JSON_POSITIVE_INTEGER, // JsonVariant stores an unsigned long - JSON_NEGATIVE_INTEGER, // JsonVariant stores an unsigned long that must be - // negated - JSON_ARRAY, // JsonVariant stores a pointer to a JsonArray - JSON_OBJECT, // JsonVariant stores a pointer to a JsonObject - - // The following values are reserved for float values - // Multiple values are used for double, depending on the number of decimal - // digits that must be printed in the JSON output. - // This little trick allow to save one extra member in JsonVariant - JSON_FLOAT_0_DECIMALS - // JSON_FLOAT_1_DECIMAL - // JSON_FLOAT_2_DECIMALS - // ... -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonWriter.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonWriter.hpp deleted file mode 100644 index c832b15a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonWriter.hpp +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Polyfills/attributes.hpp" -#include "../Polyfills/math.hpp" -#include "../Polyfills/normalize.hpp" -#include "../Print.hpp" -#include "Encoding.hpp" -#include "JsonFloat.hpp" -#include "JsonInteger.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Writes the JSON tokens to a Print implementation -// This class is used by: -// - JsonArray::writeTo() -// - JsonObject::writeTo() -// - JsonVariant::writeTo() -// Its derived by PrettyJsonWriter that overrides some members to add -// indentation. -class JsonWriter { - public: - explicit JsonWriter(Print &sink) : _sink(sink), _length(0) {} - - // Returns the number of bytes sent to the Print implementation. - // This is very handy for implementations of printTo() that must return the - // number of bytes written. - size_t bytesWritten() const { - return _length; - } - - void beginArray() { - writeRaw('['); - } - void endArray() { - writeRaw(']'); - } - - void beginObject() { - writeRaw('{'); - } - void endObject() { - writeRaw('}'); - } - - void writeColon() { - writeRaw(':'); - } - void writeComma() { - writeRaw(','); - } - - void writeBoolean(bool value) { - writeRaw(value ? "true" : "false"); - } - - void writeString(const char *value) { - if (!value) { - writeRaw("null"); - } else { - writeRaw('\"'); - while (*value) writeChar(*value++); - writeRaw('\"'); - } - } - - void writeChar(char c) { - char specialChar = Encoding::escapeChar(c); - if (specialChar) { - writeRaw('\\'); - writeRaw(specialChar); - } else { - writeRaw(c); - } - } - - void writeFloat(JsonFloat value, uint8_t digits = 2) { - if (Polyfills::isNaN(value)) return writeRaw("NaN"); - - if (value < 0.0) { - writeRaw('-'); - value = -value; - } - - if (Polyfills::isInfinity(value)) return writeRaw("Infinity"); - - short powersOf10; - if (value > 1000 || value < 0.001) { - powersOf10 = Polyfills::normalize(value); - } else { - powersOf10 = 0; - } - - // Round up last digit (so that print(1.999, 2) prints as "2.00") - value += getRoundingBias(digits); - - // Extract the integer part of the value and print it - JsonUInt int_part = static_cast(value); - JsonFloat remainder = value - static_cast(int_part); - writeInteger(int_part); - - // Print the decimal point, but only if there are digits beyond - if (digits > 0) { - writeRaw('.'); - } - - // Extract digits from the remainder one at a time - while (digits-- > 0) { - // Extract digit - remainder *= 10.0; - char currentDigit = char(remainder); - remainder -= static_cast(currentDigit); - - // Print - writeRaw(char('0' + currentDigit)); - } - - if (powersOf10 < 0) { - writeRaw("e-"); - writeInteger(-powersOf10); - } - - if (powersOf10 > 0) { - writeRaw('e'); - writeInteger(powersOf10); - } - } - - void writeInteger(JsonUInt value) { - char buffer[22]; - char *ptr = buffer + sizeof(buffer) - 1; - - *ptr = 0; - do { - *--ptr = static_cast(value % 10 + '0'); - value /= 10; - } while (value); - - writeRaw(ptr); - } - - void writeRaw(const char *s) { - _length += _sink.print(s); - } - void writeRaw(char c) { - _length += _sink.write(c); - } - - protected: - Print &_sink; - size_t _length; - - private: - JsonWriter &operator=(const JsonWriter &); // cannot be assigned - - static JsonFloat getLastDigit(uint8_t digits) { - // Designed as a compromise between code size and speed - switch (digits) { - case 0: - return 1e-0; - case 1: - return 1e-1; - case 2: - return 1e-2; - case 3: - return 1e-3; - default: - return getLastDigit(uint8_t(digits - 4)) * 1e-4; - } - } - - FORCE_INLINE static JsonFloat getRoundingBias(uint8_t digits) { - return 0.5 * getLastDigit(digits); - } -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/List.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/List.hpp deleted file mode 100644 index 6072292e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/List.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" -#include "ListConstIterator.hpp" -#include "ListIterator.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A singly linked list of T. -// The linked list is composed of ListNode. -// It is derived by JsonArray and JsonObject -template -class List { - public: - typedef T value_type; - typedef ListNode node_type; - typedef ListIterator iterator; - typedef ListConstIterator const_iterator; - - // Creates an empty List attached to a JsonBuffer. - // The JsonBuffer allows to allocate new nodes. - // When buffer is NULL, the List is not able to grow and success() returns - // false. This is used to identify bad memory allocations and parsing - // failures. - explicit List(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {} - - // Returns true if the object is valid - // Would return false in the following situation: - // - the memory allocation failed (StaticJsonBuffer was too small) - // - the JSON parsing failed - bool success() const { - return _buffer != NULL; - } - - // Returns the numbers of elements in the list. - // For a JsonObject, it would return the number of key-value pairs - size_t size() const { - size_t nodeCount = 0; - for (node_type *node = _firstNode; node; node = node->next) nodeCount++; - return nodeCount; - } - - iterator begin() { - return iterator(_firstNode); - } - iterator end() { - return iterator(NULL); - } - - const_iterator begin() const { - return const_iterator(_firstNode); - } - const_iterator end() const { - return const_iterator(NULL); - } - - protected: - node_type *addNewNode() { - node_type *newNode = new (_buffer) node_type(); - - if (_firstNode) { - node_type *lastNode = _firstNode; - while (lastNode->next) lastNode = lastNode->next; - lastNode->next = newNode; - } else { - _firstNode = newNode; - } - - return newNode; - } - - void removeNode(node_type *nodeToRemove) { - if (!nodeToRemove) return; - if (nodeToRemove == _firstNode) { - _firstNode = nodeToRemove->next; - } else { - for (node_type *node = _firstNode; node; node = node->next) - if (node->next == nodeToRemove) node->next = nodeToRemove->next; - } - } - - JsonBuffer *_buffer; - node_type *_firstNode; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListConstIterator.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListConstIterator.hpp deleted file mode 100644 index f6b7ca53..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListConstIterator.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "ListNode.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A read-only forward itertor for List -template -class ListConstIterator { - public: - explicit ListConstIterator(const ListNode *node = NULL) : _node(node) {} - - const T &operator*() const { return _node->content; } - const T *operator->() { return &_node->content; } - - bool operator==(const ListConstIterator &other) const { - return _node == other._node; - } - - bool operator!=(const ListConstIterator &other) const { - return _node != other._node; - } - - ListConstIterator &operator++() { - if (_node) _node = _node->next; - return *this; - } - - private: - const ListNode *_node; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListIterator.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListIterator.hpp deleted file mode 100644 index 17342971..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListIterator.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "ListNode.hpp" -#include "ListConstIterator.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A read-write forward iterator for List -template -class ListIterator { - public: - explicit ListIterator(ListNode *node = NULL) : _node(node) {} - - T &operator*() const { return _node->content; } - T *operator->() { return &_node->content; } - - bool operator==(const ListIterator &other) const { - return _node == other._node; - } - - bool operator!=(const ListIterator &other) const { - return _node != other._node; - } - - ListIterator &operator++() { - if (_node) _node = _node->next; - return *this; - } - - operator ListConstIterator() const { return ListConstIterator(_node); } - - private: - ListNode *_node; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListNode.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListNode.hpp deleted file mode 100644 index 3c94662d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListNode.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include // for NULL - -#include "JsonBufferAllocated.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A node for a singly-linked list. -// Used by List and its iterators. -template -struct ListNode : public Internals::JsonBufferAllocated { - ListNode() : next(NULL) {} - - ListNode *next; - T content; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Parse.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Parse.hpp deleted file mode 100644 index 0068d91f..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Parse.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include - -namespace ArduinoJson { -namespace Internals { -template -TFloat parse(const char *); - -template <> -inline float parse(const char *s) { - return static_cast(strtod(s, NULL)); -} - -template <> -inline double parse(const char *s) { - return strtod(s, NULL); -} - -template <> -inline long parse(const char *s) { - return strtol(s, NULL, 10); -} - -template <> -inline unsigned long parse(const char *s) { - return strtoul(s, NULL, 10); -} - -template <> -inline int parse(const char *s) { - return atoi(s); -} - -#if ARDUINOJSON_USE_LONG_LONG -template <> -inline long long parse(const char *s) { - return strtoll(s, NULL, 10); -} - -template <> -inline unsigned long long parse(const char *s) { - return strtoull(s, NULL, 10); -} -#endif - -#if ARDUINOJSON_USE_INT64 -template <> -inline __int64 parse<__int64>(const char *s) { - return _strtoi64(s, NULL, 10); -} - -template <> -inline unsigned __int64 parse(const char *s) { - return _strtoui64(s, NULL, 10); -} -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Prettyfier.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Prettyfier.hpp deleted file mode 100644 index f3609e92..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Prettyfier.hpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "IndentedPrint.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Converts a compact JSON string into an indented one. -class Prettyfier : public Print { - public: - explicit Prettyfier(IndentedPrint& p) : _sink(p) { - _previousChar = 0; - _inString = false; - } - - virtual size_t write(uint8_t c) { - size_t n = _inString ? handleStringChar(c) : handleMarkupChar(c); - _previousChar = c; - return n; - } - - private: - Prettyfier& operator=(const Prettyfier&); // cannot be assigned - - bool inEmptyBlock() { - return _previousChar == '{' || _previousChar == '['; - } - - size_t handleStringChar(uint8_t c) { - bool isQuote = c == '"' && _previousChar != '\\'; - - if (isQuote) _inString = false; - - return _sink.write(c); - } - - size_t handleMarkupChar(uint8_t c) { - switch (c) { - case '{': - case '[': - return writeBlockOpen(c); - - case '}': - case ']': - return writeBlockClose(c); - - case ':': - return writeColon(); - - case ',': - return writeComma(); - - case '"': - return writeQuoteOpen(); - - default: - return writeNormalChar(c); - } - } - - size_t writeBlockClose(uint8_t c) { - size_t n = 0; - n += unindentIfNeeded(); - n += _sink.write(c); - return n; - } - - size_t writeBlockOpen(uint8_t c) { - size_t n = 0; - n += indentIfNeeded(); - n += _sink.write(c); - return n; - } - - size_t writeColon() { - size_t n = 0; - n += _sink.write(':'); - n += _sink.write(' '); - return n; - } - - size_t writeComma() { - size_t n = 0; - n += _sink.write(','); - n += _sink.println(); - return n; - } - - size_t writeQuoteOpen() { - _inString = true; - size_t n = 0; - n += indentIfNeeded(); - n += _sink.write('"'); - return n; - } - - size_t writeNormalChar(uint8_t c) { - size_t n = 0; - n += indentIfNeeded(); - n += _sink.write(c); - return n; - } - - size_t indentIfNeeded() { - if (!inEmptyBlock()) return 0; - - _sink.indent(); - return _sink.println(); - } - - size_t unindentIfNeeded() { - if (inEmptyBlock()) return 0; - - _sink.unindent(); - return _sink.println(); - } - - uint8_t _previousChar; - IndentedPrint& _sink; - bool _inString; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ReferenceType.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ReferenceType.hpp deleted file mode 100644 index a5cf507a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ReferenceType.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Internals { - -// A type that is meant to be used by reference only (JsonArray and JsonObject) -class ReferenceType { - public: - bool operator==(const ReferenceType& other) const { - // two JsonArray are equal if they are the same instance - // (we don't compare the content) - return this == &other; - } - - bool operator!=(const ReferenceType& other) const { return this != &other; } - - protected: - ReferenceType() {} - - private: - // copy constructor is private - ReferenceType(const ReferenceType&); - - // copy operator is private - ReferenceType& operator=(const ReferenceType&); -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StaticStringBuilder.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StaticStringBuilder.hpp deleted file mode 100644 index 8fdcf88a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StaticStringBuilder.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A Print implementation that allows to write in a char[] -class StaticStringBuilder : public Print { - public: - StaticStringBuilder(char *buf, size_t size) - : buffer(buf), capacity(size - 1), length(0) { - buffer[0] = '\0'; - } - - virtual size_t write(uint8_t c) { - if (length >= capacity) return 0; - - buffer[length++] = c; - buffer[length] = '\0'; - return 1; - } - - private: - char *buffer; - size_t capacity; - size_t length; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StreamPrintAdapter.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StreamPrintAdapter.hpp deleted file mode 100644 index 0f17291d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StreamPrintAdapter.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" - -#if ARDUINOJSON_ENABLE_STD_STREAM - -#include "../Print.hpp" - -#include - -namespace ArduinoJson { -namespace Internals { - -class StreamPrintAdapter : public Print { - public: - explicit StreamPrintAdapter(std::ostream& os) : _os(os) {} - - virtual size_t write(uint8_t c) { - _os << static_cast(c); - return 1; - } - - private: - // cannot be assigned - StreamPrintAdapter& operator=(const StreamPrintAdapter&); - - std::ostream& _os; -}; -} -} - -#endif // ARDUINOJSON_ENABLE_STD_STREAM diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.hpp deleted file mode 100644 index b9c03662..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.hpp +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/JsonBufferAllocated.hpp" -#include "Internals/JsonPrintable.hpp" -#include "Internals/List.hpp" -#include "Internals/ReferenceType.hpp" -#include "JsonVariant.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsReference.hpp" -#include "TypeTraits/IsSame.hpp" - -// Returns the size (in bytes) of an array with n elements. -// Can be very handy to determine the size of a StaticJsonBuffer. -#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \ - (sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(JsonArray::node_type)) - -namespace ArduinoJson { - -// Forward declarations -class JsonObject; -class JsonBuffer; -class JsonArraySubscript; - -// An array of JsonVariant. -// -// The constructor is private, instances must be created via -// JsonBuffer::createArray() or JsonBuffer::parseArray(). -// A JsonArray can be serialized to a JSON string via JsonArray::printTo(). -// It can also be deserialized from a JSON string via JsonBuffer::parseArray(). -class JsonArray : public Internals::JsonPrintable, - public Internals::ReferenceType, - public Internals::List, - public Internals::JsonBufferAllocated { - public: - // A meta-function that returns true if type T can be used in - // JsonArray::set() - template - struct CanSet { - static const bool value = JsonVariant::IsConstructibleFrom::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value; - }; - - // Create an empty JsonArray attached to the specified JsonBuffer. - // You should not call this constructor directly. - // Instead, use JsonBuffer::createArray() or JsonBuffer::parseArray(). - explicit JsonArray(JsonBuffer *buffer) - : Internals::List(buffer) {} - - // Gets the value at the specified index - JsonVariant operator[](size_t index) const { - return get(index); - } - - // Gets or sets the value at specified index - JsonArraySubscript operator[](size_t index); - - // Adds the specified value at the end of the array. - // - // bool add(bool); - // bool add(char); - // bool add(long); - // bool add(int); - // bool add(short); - // bool add(float value); - // bool add(double value); - // bool add(const char*); - template - bool add( - T value, - typename TypeTraits::EnableIf< - CanSet::value && !TypeTraits::IsReference::value>::type * = 0) { - return addNode(value); - } - // bool add(const String&) - // bool add(const JsonVariant&); - // bool add(JsonArray&); - // bool add(JsonObject&); - template - bool add(const T &value, - typename TypeTraits::EnableIf::value>::type * = 0) { - return addNode(const_cast(value)); - } - // bool add(float value, uint8_t decimals); - // bool add(double value, uint8_t decimals); - template - bool add(T value, uint8_t decimals, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type * = 0) { - return addNode(JsonVariant(value, decimals)); - } - - // Sets the value at specified index. - // - // bool set(size_t index, bool value); - // bool set(size_t index, long value); - // bool set(size_t index, int value); - // bool set(size_t index, short value); - template - bool set( - size_t index, T value, - typename TypeTraits::EnableIf< - CanSet::value && !TypeTraits::IsReference::value>::type * = 0) { - return setNodeAt(index, value); - } - // bool set(size_t index, const String&) - // bool set(size_t index, const JsonVariant&); - // bool set(size_t index, JsonArray&); - // bool set(size_t index, JsonObject&); - template - bool set(size_t index, const T &value, - typename TypeTraits::EnableIf::value>::type * = 0) { - return setNodeAt(index, const_cast(value)); - } - // bool set(size_t index, float value, uint8_t decimals = 2); - // bool set(size_t index, double value, uint8_t decimals = 2); - template - bool set(size_t index, T value, uint8_t decimals, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type * = 0) { - return setNodeAt(index, JsonVariant(value, decimals)); - } - - // Gets the value at the specified index. - JsonVariant get(size_t index) const { - node_type *node = getNodeAt(index); - return node ? node->content : JsonVariant(); - } - - // Gets the value at the specified index. - template - typename Internals::JsonVariantAs::type get(size_t index) const { - node_type *node = getNodeAt(index); - return node ? node->content.as() : JsonVariant::defaultValue(); - } - - // Check the type of the value at specified index. - template - bool is(size_t index) const { - node_type *node = getNodeAt(index); - return node ? node->content.is() : false; - } - - // Creates a JsonArray and adds a reference at the end of the array. - // It's a shortcut for JsonBuffer::createArray() and JsonArray::add() - JsonArray &createNestedArray(); - - // Creates a JsonObject and adds a reference at the end of the array. - // It's a shortcut for JsonBuffer::createObject() and JsonArray::add() - JsonObject &createNestedObject(); - - // Removes element at specified index. - void removeAt(size_t index) { - removeNode(getNodeAt(index)); - } - - // Returns a reference an invalid JsonArray. - // This object is meant to replace a NULL pointer. - // This is used when memory allocation or JSON parsing fail. - static JsonArray &invalid() { - static JsonArray instance(NULL); - return instance; - } - - // Imports a 1D array - template - bool copyFrom(T(&array)[N]) { - return copyFrom(array, N); - } - - // Imports a 1D array - template - bool copyFrom(T *array, size_t len) { - bool ok = true; - for (size_t i = 0; i < len; i++) { - ok &= add(array[i]); - } - return ok; - } - - // Imports a 2D array - template - bool copyFrom(T(&array)[N1][N2]) { - bool ok = true; - for (size_t i = 0; i < N1; i++) { - JsonArray &nestedArray = createNestedArray(); - for (size_t j = 0; j < N2; j++) { - ok &= nestedArray.add(array[i][j]); - } - } - return ok; - } - - // Exports a 1D array - template - size_t copyTo(T(&array)[N]) const { - return copyTo(array, N); - } - - // Exports a 1D array - template - size_t copyTo(T *array, size_t len) const { - size_t i = 0; - for (const_iterator it = begin(); it != end() && i < len; ++it) - array[i++] = *it; - return i; - } - - // Exports a 2D array - template - void copyTo(T(&array)[N1][N2]) const { - size_t i = 0; - for (const_iterator it = begin(); it != end() && i < N1; ++it) { - it->asArray().copyTo(array[i++]); - } - } - - private: - node_type *getNodeAt(size_t index) const { - node_type *node = _firstNode; - while (node && index--) node = node->next; - return node; - } - - template - bool setNodeAt(size_t index, TValue value) { - node_type *node = getNodeAt(index); - return node != NULL && setNodeValue(node, value); - } - - template - bool addNode(TValue value) { - node_type *node = addNewNode(); - return node != NULL && setNodeValue(node, value); - } - - template - bool setNodeValue(node_type *node, T value) { - node->content = value; - return true; - } -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.ipp deleted file mode 100644 index 08257ecd..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.ipp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonArray.hpp" -#include "JsonArraySubscript.hpp" -#include "JsonObject.hpp" - -namespace ArduinoJson { - -inline JsonVariant::JsonVariant(JsonArray &array) { - if (array.success()) { - _type = Internals::JSON_ARRAY; - _content.asArray = &array; - } else { - _type = Internals::JSON_UNDEFINED; - } -} - -inline JsonVariant::JsonVariant(JsonObject &object) { - if (object.success()) { - _type = Internals::JSON_OBJECT; - _content.asObject = &object; - } else { - _type = Internals::JSON_UNDEFINED; - } -} - -template <> -inline bool JsonArray::setNodeValue(node_type *node, String &value) { - const char *copy = _buffer->strdup(value); - if (!copy) return false; - node->content = copy; - return true; -} - -template <> -inline JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -template <> -inline JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -template <> -inline const JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -template <> -inline const JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -inline JsonArray &JsonVariant::asArray() const { - if (_type == Internals::JSON_ARRAY) return *_content.asArray; - return JsonArray::invalid(); -} - -inline JsonArray &JsonArray::createNestedArray() { - if (!_buffer) return JsonArray::invalid(); - JsonArray &array = _buffer->createArray(); - add(array); - return array; -} - -inline JsonArray &JsonObject::createNestedArray(JsonObjectKey key) { - if (!_buffer) return JsonArray::invalid(); - JsonArray &array = _buffer->createArray(); - setNodeAt(key, array); - return array; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArraySubscript.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArraySubscript.hpp deleted file mode 100644 index f622a6c8..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArraySubscript.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" -#include "JsonVariantBase.hpp" - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) -#endif - -namespace ArduinoJson { -class JsonArraySubscript : public JsonVariantBase { - public: - FORCE_INLINE JsonArraySubscript(JsonArray& array, size_t index) - : _array(array), _index(index) {} - - JsonArraySubscript& operator=(const JsonArraySubscript& src) { - _array.set(_index, src); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonArraySubscript>::type& - operator=(const T& src) { - _array.set(_index, const_cast(src)); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonArraySubscript>::type& - operator=(T src) { - _array.set(_index, src); - return *this; - } - - FORCE_INLINE bool success() const { - return _index < _array.size(); - } - - FORCE_INLINE operator JsonVariant() const { - return _array.get(_index); - } - - template - FORCE_INLINE typename Internals::JsonVariantAs::type as() const { - return _array.get(_index); - } - - template - FORCE_INLINE bool is() const { - return _array.is(_index); - } - - template - void set(TValue value) { - _array.set(_index, value); - } - - private: - JsonArray& _array; - const size_t _index; -}; - -#if ARDUINOJSON_ENABLE_STD_STREAM -inline std::ostream& operator<<(std::ostream& os, - const JsonArraySubscript& source) { - return source.printTo(os); -} -#endif - -inline JsonArraySubscript JsonArray::operator[](size_t index) { - return JsonArraySubscript(*this, index); -} - -template -inline const JsonArraySubscript JsonVariantBase::operator[]( - int index) const { - return asArray()[index]; -} - -} // namespace ArduinoJson - -#ifdef _MSC_VER -#pragma warning(pop) -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.hpp deleted file mode 100644 index eb61069a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include // for size_t -#include // for uint8_t -#include - -#include "JsonVariant.hpp" -#include "String.hpp" - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnon-virtual-dtor" -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#endif - -namespace ArduinoJson { -class JsonArray; -class JsonObject; - -// Entry point for using the library. -// -// Handle the memory management (done in derived classes) and calls the parser. -// This abstract class is implemented by StaticJsonBuffer which implements a -// fixed memory allocation. -class JsonBuffer { - public: - // CAUTION: NO VIRTUAL DESTRUCTOR! - // If we add a virtual constructor the Arduino compiler will add malloc() and - // free() to the binary, adding 706 useless bytes. - // virtual ~JsonBuffer() {} - - // Allocates an empty JsonArray. - // - // Returns a reference to the new JsonArray or JsonArray::invalid() if the - // allocation fails. - JsonArray &createArray(); - - // Allocates an empty JsonObject. - // - // Returns a reference to the new JsonObject or JsonObject::invalid() if the - // allocation fails. - JsonObject &createObject(); - - // Allocates and populate a JsonArray from a JSON string. - // - // The First argument is a pointer to the JSON string, the memory must be - // writable - // because the parser will insert null-terminators and replace escaped chars. - // - // The second argument set the nesting limit (see comment on DEFAULT_LIMIT) - // - // Returns a reference to the new JsonObject or JsonObject::invalid() if the - // allocation fails. - JsonArray &parseArray(char *json, uint8_t nestingLimit = DEFAULT_LIMIT); - - // Same with a const char*. - // With this overload, the JsonBuffer will make a copy of the string - JsonArray &parseArray(const char *json, uint8_t nesting = DEFAULT_LIMIT) { - return parseArray(strdup(json), nesting); - } - - // Same as above with a String class - JsonArray &parseArray(const String &json, uint8_t nesting = DEFAULT_LIMIT) { - return parseArray(json.c_str(), nesting); - } - - // Allocates and populate a JsonObject from a JSON string. - // - // The First argument is a pointer to the JSON string, the memory must be - // writable - // because the parser will insert null-terminators and replace escaped chars. - // - // The second argument set the nesting limit (see comment on DEFAULT_LIMIT) - // - // Returns a reference to the new JsonObject or JsonObject::invalid() if the - // allocation fails. - JsonObject &parseObject(char *json, uint8_t nestingLimit = DEFAULT_LIMIT); - - // Same with a const char*. - // With this overload, the JsonBuffer will make a copy of the string - JsonObject &parseObject(const char *json, uint8_t nesting = DEFAULT_LIMIT) { - return parseObject(strdup(json), nesting); - } - - // Same as above with a String class - JsonObject &parseObject(const String &json, uint8_t nesting = DEFAULT_LIMIT) { - return parseObject(json.c_str(), nesting); - } - - // Generalized version of parseArray() and parseObject(), also works for - // integral types. - JsonVariant parse(char *json, uint8_t nestingLimit = DEFAULT_LIMIT); - - // Same with a const char*. - // With this overload, the JsonBuffer will make a copy of the string - JsonVariant parse(const char *json, uint8_t nesting = DEFAULT_LIMIT) { - return parse(strdup(json), nesting); - } - - // Same as above with a String class - JsonVariant parse(const String &json, uint8_t nesting = DEFAULT_LIMIT) { - return parse(json.c_str(), nesting); - } - - // Duplicate a string - char *strdup(const char *src) { - return src ? strdup(src, strlen(src)) : NULL; - } - char *strdup(const String &src) { return strdup(src.c_str(), src.length()); } - - // Allocates n bytes in the JsonBuffer. - // Return a pointer to the allocated memory or NULL if allocation fails. - virtual void *alloc(size_t size) = 0; - - protected: - // Preserve aligment if nessary - static FORCE_INLINE size_t round_size_up(size_t bytes) { -#if ARDUINOJSON_ENABLE_ALIGNMENT - const size_t x = sizeof(void *) - 1; - return (bytes + x) & ~x; -#else - return bytes; -#endif - } - - private: - char *strdup(const char *, size_t); - - // Default value of nesting limit of parseArray() and parseObject(). - // - // The nesting limit is a contain on the level of nesting allowed in the - // JSON - // string. - // If set to 0, only a flat array or objects can be parsed. - // If set to 1, the object can contain nested arrays or objects but only 1 - // level deep. - // And bigger values will allow more level of nesting. - // - // The purpose of this feature is to prevent stack overflow that could - // lead to - // a security risk. - static const uint8_t DEFAULT_LIMIT = 10; -}; -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.ipp deleted file mode 100644 index ed89bd9e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.ipp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/JsonParser.hpp" - -inline ArduinoJson::JsonArray &ArduinoJson::JsonBuffer::createArray() { - JsonArray *ptr = new (this) JsonArray(this); - return ptr ? *ptr : JsonArray::invalid(); -} - -inline ArduinoJson::JsonObject &ArduinoJson::JsonBuffer::createObject() { - JsonObject *ptr = new (this) JsonObject(this); - return ptr ? *ptr : JsonObject::invalid(); -} - -inline ArduinoJson::JsonArray &ArduinoJson::JsonBuffer::parseArray( - char *json, uint8_t nestingLimit) { - Internals::JsonParser parser(this, json, nestingLimit); - return parser.parseArray(); -} - -inline ArduinoJson::JsonObject &ArduinoJson::JsonBuffer::parseObject( - char *json, uint8_t nestingLimit) { - Internals::JsonParser parser(this, json, nestingLimit); - return parser.parseObject(); -} - -inline ArduinoJson::JsonVariant ArduinoJson::JsonBuffer::parse( - char *json, uint8_t nestingLimit) { - Internals::JsonParser parser(this, json, nestingLimit); - return parser.parseVariant(); -} - -inline char *ArduinoJson::JsonBuffer::strdup(const char *source, - size_t length) { - size_t size = length + 1; - char *dest = static_cast(alloc(size)); - if (dest != NULL) memcpy(dest, source, size); - return dest; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.hpp deleted file mode 100644 index 8daf1029..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.hpp +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "String.hpp" -#include "Internals/JsonBufferAllocated.hpp" -#include "Internals/JsonPrintable.hpp" -#include "Internals/List.hpp" -#include "Internals/ReferenceType.hpp" -#include "JsonPair.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsReference.hpp" -#include "TypeTraits/IsSame.hpp" - -// Returns the size (in bytes) of an object with n elements. -// Can be very handy to determine the size of a StaticJsonBuffer. -#define JSON_OBJECT_SIZE(NUMBER_OF_ELEMENTS) \ - (sizeof(JsonObject) + (NUMBER_OF_ELEMENTS) * sizeof(JsonObject::node_type)) - -namespace ArduinoJson { - -// Forward declarations -class JsonArray; -class JsonBuffer; - -// A dictionary of JsonVariant indexed by string (char*) -// -// The constructor is private, instances must be created via -// JsonBuffer::createObject() or JsonBuffer::parseObject(). -// A JsonObject can be serialized to a JSON string via JsonObject::printTo(). -// It can also be deserialized from a JSON string via JsonBuffer::parseObject(). -class JsonObject : public Internals::JsonPrintable, - public Internals::ReferenceType, - public Internals::List, - public Internals::JsonBufferAllocated { - public: - // A meta-function that returns true if type T can be used in - // JsonObject::set() - template - struct CanSet { - static const bool value = JsonVariant::IsConstructibleFrom::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value; - }; - - // Create an empty JsonArray attached to the specified JsonBuffer. - // You should not use this constructor directly. - // Instead, use JsonBuffer::createObject() or JsonBuffer.parseObject(). - explicit JsonObject(JsonBuffer* buffer) : Internals::List(buffer) {} - - // Gets or sets the value associated with the specified key. - JsonObjectSubscript operator[](const char* key); - JsonObjectSubscript operator[](const String& key); - - // Gets the value associated with the specified key. - JsonVariant operator[](JsonObjectKey key) const { - return get(key); - } - - // Sets the specified key with the specified value. - // bool set(TKey key, bool value); - // bool set(TKey key, char value); - // bool set(TKey key, long value); - // bool set(TKey key, int value); - // bool set(TKey key, short value); - // bool set(TKey key, float value); - // bool set(TKey key, double value); - // bool set(TKey key, const char* value); - // bool set(TKey key, RawJson value); - template - bool set( - JsonObjectKey key, T value, - typename TypeTraits::EnableIf< - CanSet::value && !TypeTraits::IsReference::value>::type* = 0) { - return setNodeAt(key, value); - } - // bool set(Key, String&); - // bool set(Key, JsonArray&); - // bool set(Key, JsonObject&); - // bool set(Key, JsonVariant&); - template - bool set(JsonObjectKey key, const T& value, - typename TypeTraits::EnableIf::value>::type* = 0) { - return setNodeAt(key, const_cast(value)); - } - // bool set(Key, float value, uint8_t decimals); - // bool set(Key, double value, uint8_t decimals); - template - bool set(JsonObjectKey key, TValue value, uint8_t decimals, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type* = 0) { - return setNodeAt(key, JsonVariant(value, decimals)); - } - - // Gets the value associated with the specified key. - JsonVariant get(JsonObjectKey key) const { - node_type* node = getNodeAt(key.c_str()); - return node ? node->content.value : JsonVariant(); - } - - // Gets the value associated with the specified key. - template - typename Internals::JsonVariantAs::type get(JsonObjectKey key) const { - node_type* node = getNodeAt(key.c_str()); - return node ? node->content.value.as() : JsonVariant::defaultValue(); - } - - // Checks the type of the value associated with the specified key. - template - bool is(JsonObjectKey key) const { - node_type* node = getNodeAt(key.c_str()); - return node ? node->content.value.is() : false; - } - - // Creates and adds a JsonArray. - // This is a shortcut for JsonBuffer::createArray() and JsonObject::add(). - JsonArray& createNestedArray(JsonObjectKey key); - - // Creates and adds a JsonObject. - // This is a shortcut for JsonBuffer::createObject() and JsonObject::add(). - JsonObject& createNestedObject(JsonObjectKey key); - - // Tells weither the specified key is present and associated with a value. - bool containsKey(JsonObjectKey key) const { - return getNodeAt(key.c_str()) != NULL; - } - - // Removes the specified key and the associated value. - void remove(JsonObjectKey key) { - removeNode(getNodeAt(key.c_str())); - } - - // Returns a reference an invalid JsonObject. - // This object is meant to replace a NULL pointer. - // This is used when memory allocation or JSON parsing fail. - static JsonObject& invalid() { - static JsonObject instance(NULL); - return instance; - } - - private: - // Returns the list node that matches the specified key. - node_type* getNodeAt(const char* key) const { - for (node_type* node = _firstNode; node; node = node->next) { - if (!strcmp(node->content.key, key)) return node; - } - return NULL; - } - - template - bool setNodeAt(JsonObjectKey key, T value) { - node_type* node = getNodeAt(key.c_str()); - if (!node) { - node = addNewNode(); - if (!node || !setNodeKey(node, key)) return false; - } - return setNodeValue(node, value); - } - - bool setNodeKey(node_type* node, JsonObjectKey key) { - if (key.needs_copy()) { - node->content.key = _buffer->strdup(key.c_str()); - if (node->content.key == NULL) return false; - } else { - node->content.key = key.c_str(); - } - return true; - } - - template - bool setNodeValue(node_type* node, T value) { - node->content.value = value; - return true; - } -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.ipp deleted file mode 100644 index d421ca94..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.ipp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonArray.hpp" -#include "JsonObject.hpp" -#include "JsonObjectSubscript.hpp" - -namespace ArduinoJson { - -template <> -inline bool JsonObject::setNodeValue(node_type *node, String &value) { - const char *dup = _buffer->strdup(value); - node->content.value = dup; - return dup != NULL; -} - -template <> -inline bool JsonObject::setNodeValue(node_type *node, const String &value) { - const char *dup = _buffer->strdup(value); - node->content.value = dup; - return dup != NULL; -} - -template <> -inline const JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -template <> -inline const JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -template <> -inline JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -template <> -inline JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -inline JsonObject &JsonVariant::asObject() const { - if (_type == Internals::JSON_OBJECT) return *_content.asObject; - return JsonObject::invalid(); -} - -inline JsonObject &JsonObject::createNestedObject(JsonObjectKey key) { - if (!_buffer) return JsonObject::invalid(); - JsonObject &array = _buffer->createObject(); - setNodeAt(key, array); - return array; -} - -inline JsonObject &JsonArray::createNestedObject() { - if (!_buffer) return JsonObject::invalid(); - JsonObject &object = _buffer->createObject(); - add(object); - return object; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectKey.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectKey.hpp deleted file mode 100644 index b713f39e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectKey.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "String.hpp" - -namespace ArduinoJson { - -// Represents a key in a JsonObject -class JsonObjectKey { - public: - JsonObjectKey(const char* key) : _value(key), _needs_copy(false) {} - JsonObjectKey(const String& key) : _value(key.c_str()), _needs_copy(true) {} - - const char* c_str() const { return _value; } - bool needs_copy() const { return _needs_copy; } - - private: - const char* _value; - bool _needs_copy; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectSubscript.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectSubscript.hpp deleted file mode 100644 index 0f7a71bb..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectSubscript.hpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" -#include "JsonVariantBase.hpp" -#include "TypeTraits/EnableIf.hpp" - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) -#endif - -namespace ArduinoJson { - -template -class JsonObjectSubscript : public JsonVariantBase > { - public: - FORCE_INLINE JsonObjectSubscript(JsonObject& object, TKey key) - : _object(object), _key(key) {} - - JsonObjectSubscript& operator=(const JsonObjectSubscript& src) { - _object.set(_key, src); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonObjectSubscript >::type& - operator=(const T& src) { - _object.set(_key, const_cast(src)); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonObjectSubscript >::type& - operator=(T src) { - _object.set(_key, src); - return *this; - } - - FORCE_INLINE bool success() const { - return _object.containsKey(_key); - } - - FORCE_INLINE operator JsonVariant() const { - return _object.get(_key); - } - - template - FORCE_INLINE typename Internals::JsonVariantAs::type as() const { - return _object.get(_key); - } - - template - FORCE_INLINE bool is() const { - return _object.is(_key); - } - - template - FORCE_INLINE bool set(TValue value) { - return _object.set(_key, value); - } - - template - FORCE_INLINE bool set(TValue value, uint8_t decimals) { - return _object.set(_key, value, decimals); - } - - FORCE_INLINE JsonVariant get() { - return _object.get(_key); - } - - private: - JsonObject& _object; - TKey _key; -}; - -#if ARDUINOJSON_ENABLE_STD_STREAM -inline std::ostream& operator<<( - std::ostream& os, const JsonObjectSubscript& source) { - return source.printTo(os); -} - -inline std::ostream& operator<<( - std::ostream& os, const JsonObjectSubscript& source) { - return source.printTo(os); -} -#endif - -inline JsonObjectSubscript JsonObject::operator[]( - const char* key) { - return JsonObjectSubscript(*this, key); -} - -inline JsonObjectSubscript JsonObject::operator[]( - const String& key) { - return JsonObjectSubscript(*this, key); -} - -template -inline const JsonObjectSubscript JsonVariantBase:: -operator[](const char* key) const { - return asObject()[key]; -} - -template -inline const JsonObjectSubscript JsonVariantBase:: -operator[](const String& key) const { - return asObject()[key]; -} - -} // namespace ArduinoJson - -#ifdef _MSC_VER -#pragma warning(pop) -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonPair.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonPair.hpp deleted file mode 100644 index 49ebed8d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonPair.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonObjectKey.hpp" -#include "JsonVariant.hpp" - -namespace ArduinoJson { - -// A key value pair for JsonObject. -struct JsonPair { - const char* key; - JsonVariant value; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.hpp deleted file mode 100644 index f4093376..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.hpp +++ /dev/null @@ -1,376 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include -#include // for uint8_t - -#include "Internals/JsonPrintable.hpp" -#include "Internals/JsonVariantContent.hpp" -#include "Internals/JsonVariantType.hpp" -#include "JsonVariantBase.hpp" -#include "RawJson.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsIntegral.hpp" -#include "TypeTraits/IsSame.hpp" -#include "TypeTraits/RemoveConst.hpp" -#include "TypeTraits/RemoveReference.hpp" - -namespace ArduinoJson { - -// Forward declarations. -class JsonArray; -class JsonObject; - -// A variant that can be a any value serializable to a JSON value. -// -// It can be set to: -// - a boolean -// - a char, short, int or a long (signed or unsigned) -// - a string (const char*) -// - a reference to a JsonArray or JsonObject -class JsonVariant : public JsonVariantBase { - friend void Internals::JsonSerializer::serialize(const JsonVariant &, - JsonWriter &); - - public: - template - struct IsConstructibleFrom; - - // Creates an uninitialized JsonVariant - JsonVariant() : _type(Internals::JSON_UNDEFINED) {} - - // Create a JsonVariant containing a boolean value. - // It will be serialized as "true" or "false" in JSON. - JsonVariant(bool value) { - using namespace Internals; - _type = JSON_BOOLEAN; - _content.asInteger = static_cast(value); - } - - // Create a JsonVariant containing a floating point value. - // The second argument specifies the number of decimal digits to write in - // the JSON string. - // JsonVariant(double value, uint8_t decimals); - // JsonVariant(float value, uint8_t decimals); - template - JsonVariant(T value, uint8_t decimals = 2, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type * = 0) { - using namespace Internals; - _type = static_cast(JSON_FLOAT_0_DECIMALS + decimals); - _content.asFloat = static_cast(value); - } - - // Create a JsonVariant containing an integer value. - // JsonVariant(signed short) - // JsonVariant(signed int) - // JsonVariant(signed long) - template - JsonVariant(T value, - typename TypeTraits::EnableIf< - TypeTraits::IsSignedIntegral::value>::type * = 0) { - using namespace Internals; - if (value >= 0) { - _type = JSON_POSITIVE_INTEGER; - _content.asInteger = static_cast(value); - } else { - _type = JSON_NEGATIVE_INTEGER; - _content.asInteger = static_cast(-value); - } - } - // JsonVariant(unsigned short) - // JsonVariant(unsigned int) - // JsonVariant(unsigned long) - template - JsonVariant(T value, - typename TypeTraits::EnableIf< - TypeTraits::IsUnsignedIntegral::value>::type * = 0) { - using namespace Internals; - _type = JSON_POSITIVE_INTEGER; - _content.asInteger = static_cast(value); - } - - // Create a JsonVariant containing a string. - JsonVariant(const char *value) { - _type = Internals::JSON_STRING; - _content.asString = value; - } - - // Create a JsonVariant containing an unparsed string - JsonVariant(RawJson value) { - _type = Internals::JSON_UNPARSED; - _content.asString = value; - } - - // Create a JsonVariant containing a reference to an array. - JsonVariant(JsonArray &array); - - // Create a JsonVariant containing a reference to an object. - JsonVariant(JsonObject &object); - - // Get the variant as the specified type. - // - // short as() const; - // int as() const; - // long as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return static_cast(asInteger()); - } - // - // short as() const; - // int as() const; - // long as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return static_cast(asUnsignedInteger()); - } - // - // double as() const; - // float as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return static_cast(asFloat()); - } - // - // const String as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return toString(); - } - // - // const char* as() const; - // const char* as() const; - template - typename TypeTraits::EnableIf::value || - TypeTraits::IsSame::value, - const char *>::type - as() const { - return asString(); - } - // - // const bool as() const - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return asInteger() != 0; - } - // - // JsonArray& as const; - // JsonArray& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - JsonArray>::value, - JsonArray &>::type - as() const { - return asArray(); - } - // - // const JsonArray& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - const JsonArray>::value, - const JsonArray &>::type - as() const { - return asArray(); - } - // - // JsonObject& as const; - // JsonObject& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - JsonObject>::value, - JsonObject &>::type - as() const { - return asObject(); - } - // - // JsonObject& as const; - // JsonObject& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - const JsonObject>::value, - const JsonObject &>::type - as() const { - return asObject(); - } - // - // JsonVariant as const; - template - typename TypeTraits::EnableIf::value, - T>::type - as() const { - return *this; - } - - // Tells weither the variant has the specified type. - // Returns true if the variant has type type T, false otherwise. - // - // short as() const; - // int as() const; - // long as() const; - template - const typename TypeTraits::EnableIf::value, - bool>::type - is() const { - return isInteger(); - } - // - // double is() const; - // float is() const; - template - const typename TypeTraits::EnableIf::value, - bool>::type - is() const { - return isFloat(); - } - // - // const bool is() const - template - const typename TypeTraits::EnableIf::value, - bool>::type - is() const { - return isBoolean(); - } - // - // bool is() const; - // bool is() const; - template - typename TypeTraits::EnableIf::value || - TypeTraits::IsSame::value, - bool>::type - is() const { - return isString(); - } - // - // bool is const; - // bool is const; - // bool is const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame< - typename TypeTraits::RemoveConst< - typename TypeTraits::RemoveReference::type>::type, - JsonArray>::value, - bool>::type - is() const { - return isArray(); - } - // - // bool is const; - // bool is const; - // bool is const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame< - typename TypeTraits::RemoveConst< - typename TypeTraits::RemoveReference::type>::type, - JsonObject>::value, - bool>::type - is() const { - return isObject(); - } - - // Returns true if the variant has a value - bool success() const { - return _type != Internals::JSON_UNDEFINED; - } - - // Value returned if the variant has an incompatible type - template - static typename Internals::JsonVariantAs::type defaultValue() { - return T(); - } - - // DEPRECATED: use as() instead - const char *asString() const; - - // DEPRECATED: use as() instead - JsonArray &asArray() const; - - // DEPRECATED: use as() instead - JsonObject &asObject() const; - - private: - // It's not allowed to store a char - template - JsonVariant(T value, typename TypeTraits::EnableIf< - TypeTraits::IsSame::value>::type * = 0); - - String toString() const; - Internals::JsonFloat asFloat() const; - Internals::JsonInteger asInteger() const; - Internals::JsonUInt asUnsignedInteger() const; - bool isBoolean() const; - bool isFloat() const; - bool isInteger() const; - bool isArray() const { - return _type == Internals::JSON_ARRAY; - } - bool isObject() const { - return _type == Internals::JSON_OBJECT; - } - bool isString() const { - return _type == Internals::JSON_STRING || - (_type == Internals::JSON_UNPARSED && _content.asString && - !strcmp("null", _content.asString)); - } - - // The current type of the variant - Internals::JsonVariantType _type; - - // The various alternatives for the value of the variant. - Internals::JsonVariantContent _content; -}; - -inline JsonVariant float_with_n_digits(float value, uint8_t digits) { - return JsonVariant(value, digits); -} - -inline JsonVariant double_with_n_digits(double value, uint8_t digits) { - return JsonVariant(value, digits); -} - -template -struct JsonVariant::IsConstructibleFrom { - static const bool value = - TypeTraits::IsIntegral::value || - TypeTraits::IsFloatingPoint::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.ipp deleted file mode 100644 index f0c0d33b..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.ipp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" -#include "JsonVariant.hpp" -#include "Internals/Parse.hpp" -#include "JsonArray.hpp" -#include "JsonObject.hpp" - -#include // for strcmp -#include // for errno -#include // for strtol, strtod - -namespace ArduinoJson { - -inline Internals::JsonInteger JsonVariant::asInteger() const { - using namespace Internals; - switch (_type) { - case JSON_UNDEFINED: - return 0; - case JSON_POSITIVE_INTEGER: - case JSON_BOOLEAN: - return _content.asInteger; - case JSON_NEGATIVE_INTEGER: - return -static_cast(_content.asInteger); - case JSON_STRING: - case JSON_UNPARSED: - if (!_content.asString) return 0; - if (!strcmp("true", _content.asString)) return 1; - return parse(_content.asString); - default: - return static_cast(_content.asFloat); - } -} - -inline Internals::JsonUInt JsonVariant::asUnsignedInteger() const { - using namespace Internals; - switch (_type) { - case JSON_UNDEFINED: - return 0; - case JSON_POSITIVE_INTEGER: - case JSON_BOOLEAN: - case JSON_NEGATIVE_INTEGER: - return _content.asInteger; - case JSON_STRING: - case JSON_UNPARSED: - if (!_content.asString) return 0; - if (!strcmp("true", _content.asString)) return 1; - return parse(_content.asString); - default: - return static_cast(_content.asFloat); - } -} - -inline const char *JsonVariant::asString() const { - using namespace Internals; - if (_type == JSON_UNPARSED && _content.asString && - !strcmp("null", _content.asString)) - return NULL; - if (_type == JSON_STRING || _type == JSON_UNPARSED) return _content.asString; - return NULL; -} - -inline Internals::JsonFloat JsonVariant::asFloat() const { - using namespace Internals; - switch (_type) { - case JSON_UNDEFINED: - return 0; - case JSON_POSITIVE_INTEGER: - case JSON_BOOLEAN: - return static_cast(_content.asInteger); - case JSON_NEGATIVE_INTEGER: - return -static_cast(_content.asInteger); - case JSON_STRING: - case JSON_UNPARSED: - return _content.asString ? parse(_content.asString) : 0; - default: - return _content.asFloat; - } -} - -inline String JsonVariant::toString() const { - using namespace Internals; - String s; - if ((_type == JSON_STRING || _type == JSON_UNPARSED) && - _content.asString != NULL) - s = _content.asString; - else - printTo(s); - return s; -} - -inline bool JsonVariant::isBoolean() const { - using namespace Internals; - if (_type == JSON_BOOLEAN) return true; - - if (_type != JSON_UNPARSED || _content.asString == NULL) return false; - - return !strcmp(_content.asString, "true") || - !strcmp(_content.asString, "false"); -} - -inline bool JsonVariant::isInteger() const { - using namespace Internals; - if (_type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER) - return true; - - if (_type != JSON_UNPARSED || _content.asString == NULL) return false; - - char *end; - errno = 0; - strtol(_content.asString, &end, 10); - - return *end == '\0' && errno == 0; -} - -inline bool JsonVariant::isFloat() const { - using namespace Internals; - if (_type >= JSON_FLOAT_0_DECIMALS) return true; - - if (_type != JSON_UNPARSED || _content.asString == NULL) return false; - - char *end; - errno = 0; - strtod(_content.asString, &end); - - return *end == '\0' && errno == 0 && !is(); -} - -#if ARDUINOJSON_ENABLE_STD_STREAM -inline std::ostream &operator<<(std::ostream &os, const JsonVariant &source) { - return source.printTo(os); -} -#endif - -} // namespace ArduinoJson diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariantBase.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariantBase.hpp deleted file mode 100644 index 14fc0cd8..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariantBase.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/JsonVariantAs.hpp" -#include "JsonObjectKey.hpp" -#include "Polyfills/attributes.hpp" - -namespace ArduinoJson { - -// Forward declarations. -class JsonArraySubscript; -template -class JsonObjectSubscript; - -template -class JsonVariantBase : public Internals::JsonPrintable { - public: - // DEPRECATED: use as() instead - FORCE_INLINE const char *asString() const { - return as(); - } - - // Gets the variant as an array. - // Returns a reference to the JsonArray or JsonArray::invalid() if the - // variant - // is not an array. - FORCE_INLINE operator JsonArray &() const { - return as(); - } - - // DEPRECATED: use as() instead - FORCE_INLINE JsonArray &asArray() const { - return as(); - } - - // Gets the variant as an object. - // Returns a reference to the JsonObject or JsonObject::invalid() if the - // variant is not an object. - FORCE_INLINE operator JsonObject &() const { - return as(); - } - - // DEPRECATED: use as() instead - FORCE_INLINE JsonObject &asObject() const { - return as(); - } - - template - FORCE_INLINE operator T() const { - return as(); - } - - template - FORCE_INLINE const typename Internals::JsonVariantAs::type as() const { - return impl()->template as(); - } - - // Mimics an array or an object. - // Returns the size of the array or object if the variant has that type. - // Returns 0 if the variant is neither an array nor an object - size_t size() const { - return asArray().size() + asObject().size(); - } - - // Mimics an array. - // Returns the element at specified index if the variant is an array. - // Returns JsonVariant::invalid() if the variant is not an array. - FORCE_INLINE const JsonArraySubscript operator[](int index) const; - - // Mimics an object. - // Returns the value associated with the specified key if the variant is - // an object. - // Return JsonVariant::invalid() if the variant is not an object. - FORCE_INLINE const JsonObjectSubscript operator[]( - const char *key) const; - FORCE_INLINE const JsonObjectSubscript operator[]( - const String &key) const; - - private: - const TImpl *impl() const { - return static_cast(this); - } -}; - -template -inline bool operator==(const JsonVariantBase &left, TComparand right) { - return left.template as() == right; -} - -template -inline bool operator==(TComparand left, const JsonVariantBase &right) { - return left == right.template as(); -} - -template -inline bool operator!=(const JsonVariantBase &left, TComparand right) { - return left.template as() != right; -} - -template -inline bool operator!=(TComparand left, const JsonVariantBase &right) { - return left != right.template as(); -} - -template -inline bool operator<=(const JsonVariantBase &left, TComparand right) { - return left.template as() <= right; -} - -template -inline bool operator<=(TComparand left, const JsonVariantBase &right) { - return left <= right.template as(); -} - -template -inline bool operator>=(const JsonVariantBase &left, TComparand right) { - return left.template as() >= right; -} - -template -inline bool operator>=(TComparand left, const JsonVariantBase &right) { - return left >= right.template as(); -} - -template -inline bool operator<(const JsonVariantBase &left, TComparand right) { - return left.template as() < right; -} - -template -inline bool operator<(TComparand left, const JsonVariantBase &right) { - return left < right.template as(); -} - -template -inline bool operator>(const JsonVariantBase &left, TComparand right) { - return left.template as() > right; -} - -template -inline bool operator>(TComparand left, const JsonVariantBase &right) { - return left > right.template as(); -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/attributes.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/attributes.hpp deleted file mode 100644 index c428fe1a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/attributes.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#ifdef _MSC_VER -#define FORCE_INLINE __forceinline -#define NO_INLINE __declspec(noinline) -#else -#define FORCE_INLINE __attribute__((always_inline)) -#define NO_INLINE __attribute__((noinline)) -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/math.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/math.hpp deleted file mode 100644 index 3535c486..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/math.hpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -// If Visual Studo <= 2012 -#if defined(_MSC_VER) && _MSC_VER <= 1700 - -#include - -namespace ArduinoJson { -namespace Polyfills { -template -bool isNaN(T x) { - return _isnan(x) != 0; -} - -template -bool isInfinity(T x) { - return !_finite(x); -} -} -} - -#else - -#include - -// GCC warning: "conversion to 'float' from 'double' may alter its value" -#ifdef __GNUC__ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) -#pragma GCC diagnostic ignored "-Wfloat-conversion" -#else -#pragma GCC diagnostic ignored "-Wconversion" -#endif -#endif - -// Workaround for libs that #undef isnan or isinf -// https://github.com/bblanchon/ArduinoJson/issues/284 -#if !defined(isnan) || !defined(isinf) -namespace std {} -#endif - -namespace ArduinoJson { -namespace Polyfills { - -template -bool isNaN(T x) { -// Workaround for libs that #undef isnan -// https://github.com/bblanchon/ArduinoJson/issues/284 -#ifndef isnan - using namespace std; -#endif - - return isnan(x); -} - -#if defined(_GLIBCXX_HAVE_ISNANL) && _GLIBCXX_HAVE_ISNANL -template <> -inline bool isNaN(double x) { - return isnanl(x); -} -#endif - -#if defined(_GLIBCXX_HAVE_ISNANF) && _GLIBCXX_HAVE_ISNANF -template <> -inline bool isNaN(float x) { - return isnanf(x); -} -#endif - -template -bool isInfinity(T x) { -// Workaround for libs that #undef isinf -// https://github.com/bblanchon/ArduinoJson/issues/284 -#ifndef isinf - using namespace std; -#endif - - return isinf(x); -} - -#if defined(_GLIBCXX_HAVE_ISINFL) && _GLIBCXX_HAVE_ISINFL -template <> -inline bool isInfinity(double x) { - return isinfl(x); -} -#endif - -#if defined(_GLIBCXX_HAVE_ISINFF) && _GLIBCXX_HAVE_ISINFF -template <> -inline bool isInfinity(float x) { - return isinff(x); -} -#endif - -#if defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif -} -} -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/normalize.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/normalize.hpp deleted file mode 100644 index 9b0f6bb9..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/normalize.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Polyfills { - -#ifdef ARDUINO - -// on embedded platform, favor code size over speed - -template -short normalize(T& value) { - short powersOf10 = 0; - while (value && value < 1) { - powersOf10--; - value *= 10; - } - while (value > 10) { - powersOf10++; - value /= 10; - } - return powersOf10; -} - -#else - -// on non-embedded platform, favor speed over code size - -template -short normalize(T& value) { - if (value == 0.0) return 0; - - short powersOf10 = static_cast(floor(log10(value))); - value /= pow(T(10), powersOf10); - - return powersOf10; -} - -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Print.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Print.hpp deleted file mode 100644 index 73a6d33a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Print.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#ifndef ARDUINO - -#include -#include - -namespace ArduinoJson { -// This class reproduces Arduino's Print class -class Print { - public: - virtual ~Print() {} - - virtual size_t write(uint8_t) = 0; - - size_t print(const char* s) { - size_t n = 0; - while (*s) { - n += write(static_cast(*s++)); - } - return n; - } - - size_t println() { - size_t n = 0; - n += write('\r'); - n += write('\n'); - return n; - } -}; -} - -#else - -#include - -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/RawJson.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/RawJson.hpp deleted file mode 100644 index 9b1f40dd..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/RawJson.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { - -// A special type of data that can be used to insert pregenerated JSON portions. -class RawJson { - public: - explicit RawJson(const char* str) : _str(str) {} - operator const char*() const { return _str; } - - private: - const char* _str; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/StaticJsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/StaticJsonBuffer.hpp deleted file mode 100644 index 783eea27..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/StaticJsonBuffer.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonBuffer.hpp" - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnon-virtual-dtor" -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#endif - -namespace ArduinoJson { - -// Implements a JsonBuffer with fixed memory allocation. -// The template paramenter CAPACITY specifies the capacity of the buffer in -// bytes. -template -class StaticJsonBuffer : public JsonBuffer { - public: - explicit StaticJsonBuffer() : _size(0) {} - - size_t capacity() const { - return CAPACITY; - } - size_t size() const { - return _size; - } - - virtual void* alloc(size_t bytes) { - if (_size + bytes > CAPACITY) return NULL; - void* p = &_buffer[_size]; - _size += round_size_up(bytes); - return p; - } - - private: - uint8_t _buffer[CAPACITY]; - size_t _size; -}; -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/String.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/String.hpp deleted file mode 100644 index 3c030f55..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/String.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" - -#if ARDUINOJSON_USE_ARDUINO_STRING - -#include - -#else - -#include - -namespace ArduinoJson { -typedef std::string String; -} - -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/EnableIf.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/EnableIf.hpp deleted file mode 100644 index 408e8bb0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/EnableIf.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that return the type T if Condition is true. -template -struct EnableIf {}; - -template -struct EnableIf { - typedef T type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsFloatingPoint.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsFloatingPoint.hpp deleted file mode 100644 index 42a13ec6..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsFloatingPoint.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is a floating point type -template -struct IsFloatingPoint { - static const bool value = IsSame::value || IsSame::value; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsIntegral.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsIntegral.hpp deleted file mode 100644 index fab6b2c7..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsIntegral.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" -#include "IsSignedIntegral.hpp" -#include "IsUnsignedIntegral.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is an integral type. -template -struct IsIntegral { - static const bool value = TypeTraits::IsSignedIntegral::value || - TypeTraits::IsUnsignedIntegral::value || - TypeTraits::IsSame::value; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsReference.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsReference.hpp deleted file mode 100644 index 436a25db..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsReference.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is a reference -template -struct IsReference { - static const bool value = false; -}; - -template -struct IsReference { - static const bool value = true; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSame.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSame.hpp deleted file mode 100644 index 0b68d3c3..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSame.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if types T and U are the same. -template -struct IsSame { - static const bool value = false; -}; - -template -struct IsSame { - static const bool value = true; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSignedIntegral.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSignedIntegral.hpp deleted file mode 100644 index 0430a8a0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSignedIntegral.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is an integral type. -template -struct IsSignedIntegral { - static const bool value = TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || -#if ARDUINOJSON_USE_LONG_LONG - TypeTraits::IsSame::value || -#endif - -#if ARDUINOJSON_USE_INT64 - TypeTraits::IsSame::value || -#endif - false; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp deleted file mode 100644 index 690c6a34..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is an integral type. -template -struct IsUnsignedIntegral { - static const bool value = TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || -#if ARDUINOJSON_USE_LONG_LONG - TypeTraits::IsSame::value || -#endif - -#if ARDUINOJSON_USE_INT64 - TypeTraits::IsSame::value || -#endif - false; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveConst.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveConst.hpp deleted file mode 100644 index cf7b3af2..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveConst.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that return the type T without the const modifier -template -struct RemoveConst { - typedef T type; -}; -template -struct RemoveConst { - typedef T type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveReference.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveReference.hpp deleted file mode 100644 index d77eb85e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveReference.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that return the type T without the reference modifier. -template -struct RemoveReference { - typedef T type; -}; -template -struct RemoveReference { - typedef T type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/keywords.txt b/src/third-party/arduino-json-5.6.7/keywords.txt deleted file mode 100644 index 913b6aa6..00000000 --- a/src/third-party/arduino-json-5.6.7/keywords.txt +++ /dev/null @@ -1,14 +0,0 @@ -JsonArray KEYWORD1 -JsonObject KEYWORD1 -JsonVariant KEYWORD1 -StaticJsonBuffer KEYWORD1 -add KEYWORD2 -createArray KEYWORD2 -createNestedArray KEYWORD2 -createNestedObject KEYWORD2 -createObject KEYWORD2 -parseArray KEYWORD2 -parseObject KEYWORD2 -prettyPrintTo KEYWORD2 -printTo KEYWORD2 -success KEYWORD2 diff --git a/src/third-party/arduino-json-5.6.7/library.properties b/src/third-party/arduino-json-5.6.7/library.properties deleted file mode 100644 index 57989b0c..00000000 --- a/src/third-party/arduino-json-5.6.7/library.properties +++ /dev/null @@ -1,9 +0,0 @@ -name=ArduinoJson -version=5.6.7 -author=Benoit Blanchon -maintainer=Benoit Blanchon -sentence=An efficient and elegant JSON library for Arduino. -paragraph=Like this project? Please star it on GitHub! -category=Data Processing -url=https://github.com/bblanchon/ArduinoJson -architectures=*