├── .gitattributes
├── .gitignore
├── .idea
├── IOT-ESP8266-Google-Home.iml
├── deployment.xml
├── inspectionProfiles
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── vcs.xml
└── workspace.xml
├── API.ai
└── matrix-ai.zip
├── ArduinoJson
├── ArduinoJson.h
├── ArduinoJson.hpp
└── ArduinoJson
│ ├── Configuration.hpp
│ ├── Data
│ ├── Encoding.hpp
│ ├── JsonBufferAllocated.hpp
│ ├── JsonFloat.hpp
│ ├── JsonInteger.hpp
│ ├── JsonVariantAs.hpp
│ ├── JsonVariantComparer.hpp
│ ├── JsonVariantContent.hpp
│ ├── JsonVariantDefault.hpp
│ ├── JsonVariantType.hpp
│ ├── List.hpp
│ ├── ListConstIterator.hpp
│ ├── ListIterator.hpp
│ ├── ListNode.hpp
│ ├── ReferenceType.hpp
│ └── ValueSetter.hpp
│ ├── Deserialization
│ ├── Comments.hpp
│ ├── JsonParser.hpp
│ ├── JsonParserImpl.hpp
│ └── StringWriter.hpp
│ ├── DynamicJsonBuffer.hpp
│ ├── JsonArray.hpp
│ ├── JsonArrayImpl.hpp
│ ├── JsonArraySubscript.hpp
│ ├── JsonBuffer.hpp
│ ├── JsonBufferBase.hpp
│ ├── JsonBufferImpl.hpp
│ ├── JsonObject.hpp
│ ├── JsonObjectImpl.hpp
│ ├── JsonObjectSubscript.hpp
│ ├── JsonPair.hpp
│ ├── JsonVariant.hpp
│ ├── JsonVariantBase.hpp
│ ├── JsonVariantComparisons.hpp
│ ├── JsonVariantImpl.hpp
│ ├── Polyfills
│ ├── attributes.hpp
│ ├── ctype.hpp
│ ├── isFloat.hpp
│ ├── isInteger.hpp
│ ├── math.hpp
│ ├── normalize.hpp
│ ├── parseFloat.hpp
│ └── parseInteger.hpp
│ ├── RawJson.hpp
│ ├── Serialization
│ ├── DummyPrint.hpp
│ ├── DynamicStringBuilder.hpp
│ ├── IndentedPrint.hpp
│ ├── JsonPrintable.hpp
│ ├── JsonSerializer.hpp
│ ├── JsonSerializerImpl.hpp
│ ├── JsonWriter.hpp
│ ├── Prettyfier.hpp
│ ├── StaticStringBuilder.hpp
│ └── StreamPrintAdapter.hpp
│ ├── StaticJsonBuffer.hpp
│ ├── StringTraits
│ ├── ArduinoStream.hpp
│ ├── CharPointer.hpp
│ ├── FlashString.hpp
│ ├── StdStream.hpp
│ ├── StdString.hpp
│ └── StringTraits.hpp
│ └── TypeTraits
│ ├── EnableIf.hpp
│ ├── FloatTraits.hpp
│ ├── IsArray.hpp
│ ├── IsBaseOf.hpp
│ ├── IsChar.hpp
│ ├── IsConst.hpp
│ ├── IsFloatingPoint.hpp
│ ├── IsIntegral.hpp
│ ├── IsSame.hpp
│ ├── IsSignedIntegral.hpp
│ ├── IsUnsignedIntegral.hpp
│ ├── RemoveConst.hpp
│ └── RemoveReference.hpp
├── ESP8266
└── WebSocketClient
│ └── ESP8266_WebSocketClient
│ └── ESP8266_WebSocketClient.ino
├── Procfile
├── README.md
├── app.json
├── app.py
├── arduinoWebSockets
├── .gitignore
├── LICENSE
├── README.md
├── examples
│ ├── Nginx
│ │ └── esp8266.ssl.reverse.proxy.conf
│ ├── ParticleWebSocketClient
│ │ └── application.cpp
│ ├── WebSocketClient
│ │ └── WebSocketClient.ino
│ ├── WebSocketClientAVR
│ │ └── WebSocketClientAVR.ino
│ ├── WebSocketClientSSL
│ │ └── WebSocketClientSSL.ino
│ ├── WebSocketClientSocketIO
│ │ └── WebSocketClientSocketIO.ino
│ ├── WebSocketServer
│ │ ├── WebSocketServer.ino
│ │ ├── WebSocketServerFragmentation.ino
│ │ └── WebSocketServerHttpHeaderValidation.ino
│ └── WebSocketServer_LEDcontrol
│ │ └── WebSocketServer_LEDcontrol.ino
├── library.json
├── library.properties
├── src
│ ├── WebSockets.cpp
│ ├── WebSockets.h
│ ├── WebSocketsClient.cpp
│ ├── WebSocketsClient.h
│ ├── WebSocketsServer.cpp
│ ├── WebSocketsServer.h
│ ├── libb64
│ │ ├── AUTHORS
│ │ ├── LICENSE
│ │ ├── cdecode.c
│ │ ├── cdecode_inc.h
│ │ ├── cencode.c
│ │ └── cencode_inc.h
│ └── libsha1
│ │ ├── libsha1.c
│ │ └── libsha1.h
└── tests
│ ├── webSocket.html
│ └── webSocketServer
│ ├── index.js
│ └── package.json
├── matrix-ai.zip
├── requirements.txt
└── runtime.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # Windows shortcuts
18 | *.lnk
19 |
20 | # =========================
21 | # Operating System Files
22 | # =========================
23 |
24 | # OSX
25 | # =========================
26 |
27 | .DS_Store
28 | .AppleDouble
29 | .LSOverride
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear in the root of a volume
35 | .DocumentRevisions-V100
36 | .fseventsd
37 | .Spotlight-V100
38 | .TemporaryItems
39 | .Trashes
40 | .VolumeIcon.icns
41 |
42 | # Directories potentially created on remote AFP share
43 | .AppleDB
44 | .AppleDesktop
45 | Network Trash Folder
46 | Temporary Items
47 | .apdisk
48 | test-env/
49 |
--------------------------------------------------------------------------------
/.idea/IOT-ESP8266-Google-Home.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/deployment.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/API.ai/matrix-ai.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nassir-malik/IOT-ESP8266-Google-Home/d72b859894849fed2add3f75cdfd59edcd0fc461/API.ai/matrix-ai.zip
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson.h:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "ArduinoJson.hpp"
11 |
12 | using namespace ArduinoJson;
13 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "ArduinoJson/DynamicJsonBuffer.hpp"
11 | #include "ArduinoJson/JsonArray.hpp"
12 | #include "ArduinoJson/JsonObject.hpp"
13 | #include "ArduinoJson/JsonVariantComparisons.hpp"
14 | #include "ArduinoJson/StaticJsonBuffer.hpp"
15 |
16 | #include "ArduinoJson/Deserialization/JsonParserImpl.hpp"
17 | #include "ArduinoJson/JsonArrayImpl.hpp"
18 | #include "ArduinoJson/JsonBufferImpl.hpp"
19 | #include "ArduinoJson/JsonObjectImpl.hpp"
20 | #include "ArduinoJson/JsonVariantImpl.hpp"
21 | #include "ArduinoJson/Serialization/JsonSerializerImpl.hpp"
22 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Configuration.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | // enable deprecated functions by default
11 | #ifndef ARDUINOJSON_ENABLE_DEPRECATED
12 | #define ARDUINOJSON_ENABLE_DEPRECATED 1
13 | #endif
14 |
15 | #ifdef ARDUINO // assume this is an embedded platform
16 |
17 | // store using float instead of double to reduce the memory usage (issue #134)
18 | #ifndef ARDUINOJSON_USE_DOUBLE
19 | #define ARDUINOJSON_USE_DOUBLE 0
20 | #endif
21 |
22 | // store using a long because it usually match the size of a float.
23 | #ifndef ARDUINOJSON_USE_LONG_LONG
24 | #define ARDUINOJSON_USE_LONG_LONG 0
25 | #endif
26 | #ifndef ARDUINOJSON_USE_INT64
27 | #define ARDUINOJSON_USE_INT64 0
28 | #endif
29 |
30 | // Arduino has its own implementation of String to replace std::string
31 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
32 | #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
33 | #endif
34 |
35 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
36 | #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 1
37 | #endif
38 |
39 | // On AVR archiecture, we can use PROGMEM
40 | #ifndef ARDUINOJSON_ENABLE_PROGMEM
41 | #ifdef PROGMEM
42 | #define ARDUINOJSON_ENABLE_PROGMEM 1
43 | #else
44 | #define ARDUINOJSON_ENABLE_PROGMEM 0
45 | #endif
46 | #endif
47 |
48 | // Arduino doesn't have std::string
49 | #ifndef ARDUINOJSON_ENABLE_STD_STRING
50 | #define ARDUINOJSON_ENABLE_STD_STRING 0
51 | #endif
52 |
53 | // Arduino doesn't support STL stream
54 | #ifndef ARDUINOJSON_ENABLE_STD_STREAM
55 | #define ARDUINOJSON_ENABLE_STD_STREAM 0
56 | #endif
57 |
58 | #ifndef ARDUINOJSON_ENABLE_ALIGNMENT
59 | #ifdef ARDUINO_ARCH_AVR
60 | // alignment isn't needed for 8-bit AVR
61 | #define ARDUINOJSON_ENABLE_ALIGNMENT 0
62 | #else
63 | // but must processor needs pointer to be align on word size
64 | #define ARDUINOJSON_ENABLE_ALIGNMENT 1
65 | #endif
66 | #endif
67 |
68 | // low value to prevent stack overflow
69 | #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
70 | #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 10
71 | #endif
72 |
73 | #else // assume this is a computer
74 |
75 | // on a computer we have plenty of memory so we can use doubles
76 | #ifndef ARDUINOJSON_USE_DOUBLE
77 | #define ARDUINOJSON_USE_DOUBLE 1
78 | #endif
79 |
80 | // use long long when available
81 | #ifndef ARDUINOJSON_USE_LONG_LONG
82 | #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
83 | #define ARDUINOJSON_USE_LONG_LONG 1
84 | #else
85 | #define ARDUINOJSON_USE_LONG_LONG 0
86 | #endif
87 | #endif
88 |
89 | // use _int64 on old versions of Visual Studio
90 | #ifndef ARDUINOJSON_USE_INT64
91 | #if defined(_MSC_VER) && _MSC_VER <= 1700
92 | #define ARDUINOJSON_USE_INT64 1
93 | #else
94 | #define ARDUINOJSON_USE_INT64 0
95 | #endif
96 | #endif
97 |
98 | // on a computer, we can use std::string
99 | #ifndef ARDUINOJSON_ENABLE_STD_STRING
100 | #define ARDUINOJSON_ENABLE_STD_STRING 1
101 | #endif
102 |
103 | // on a computer, there is no reason to beleive Arduino String is available
104 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STRING
105 | #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
106 | #endif
107 |
108 | // PROGMEM is only available on AVR architecture
109 | #ifndef ARDUINOJSON_ENABLE_PROGMEM
110 | #define ARDUINOJSON_ENABLE_PROGMEM 0
111 | #endif
112 |
113 | // on a computer, we can assume that the STL is there
114 | #ifndef ARDUINOJSON_ENABLE_STD_STREAM
115 | #define ARDUINOJSON_ENABLE_STD_STREAM 1
116 | #endif
117 |
118 | // on a computer, there is no reason to beleive Arduino Stream is available
119 | #ifndef ARDUINOJSON_ENABLE_ARDUINO_STREAM
120 | #define ARDUINOJSON_ENABLE_ARDUINO_STREAM 0
121 | #endif
122 |
123 | #ifndef ARDUINOJSON_ENABLE_ALIGNMENT
124 | // even if not required, most cpu's are faster with aligned pointers
125 | #define ARDUINOJSON_ENABLE_ALIGNMENT 1
126 | #endif
127 |
128 | // on a computer, we should have a lot of space on the stack
129 | #ifndef ARDUINOJSON_DEFAULT_NESTING_LIMIT
130 | #define ARDUINOJSON_DEFAULT_NESTING_LIMIT 50
131 | #endif
132 |
133 | #endif
134 |
135 | #if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64
136 | #error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together
137 | #endif
138 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/Encoding.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | namespace ArduinoJson {
11 | namespace Internals {
12 |
13 | class Encoding {
14 | public:
15 | // Optimized for code size on a 8-bit AVR
16 | static char escapeChar(char c) {
17 | const char *p = escapeTable(false);
18 | while (p[0] && p[1] != c) {
19 | p += 2;
20 | }
21 | return p[0];
22 | }
23 |
24 | // Optimized for code size on a 8-bit AVR
25 | static char unescapeChar(char c) {
26 | const char *p = escapeTable(true);
27 | for (;;) {
28 | if (p[0] == '\0') return c;
29 | if (p[0] == c) return p[1];
30 | p += 2;
31 | }
32 | }
33 |
34 | private:
35 | static const char *escapeTable(bool excludeIdenticals) {
36 | return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0];
37 | }
38 | };
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonBufferAllocated.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "../JsonBuffer.hpp"
11 |
12 | namespace ArduinoJson {
13 | namespace Internals {
14 |
15 | class JsonBufferAllocated {
16 | public:
17 | void *operator new(size_t n, JsonBuffer *jsonBuffer) throw() {
18 | if (!jsonBuffer) return NULL;
19 | return jsonBuffer->alloc(n);
20 | }
21 |
22 | void operator delete(void *, JsonBuffer *)throw() {}
23 | };
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonFloat.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "../Configuration.hpp"
11 |
12 | namespace ArduinoJson {
13 | namespace Internals {
14 |
15 | #if ARDUINOJSON_USE_DOUBLE
16 | typedef double JsonFloat;
17 | #else
18 | typedef float JsonFloat;
19 | #endif
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonInteger.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "../Configuration.hpp"
11 |
12 | namespace ArduinoJson {
13 | namespace Internals {
14 |
15 | #if ARDUINOJSON_USE_LONG_LONG
16 | typedef long long JsonInteger;
17 | typedef unsigned long long JsonUInt;
18 | #elif ARDUINOJSON_USE_INT64
19 | typedef __int64 JsonInteger;
20 | typedef unsigned _int64 JsonUInt;
21 | #else
22 | typedef long JsonInteger;
23 | typedef unsigned long JsonUInt;
24 | #endif
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonVariantAs.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | namespace ArduinoJson {
11 | namespace Internals {
12 |
13 | // A metafunction that returns the type of the value returned by
14 | // JsonVariant::as()
15 | template
16 | struct JsonVariantAs {
17 | typedef T type;
18 | };
19 |
20 | template <>
21 | struct JsonVariantAs {
22 | typedef const char* type;
23 | };
24 |
25 | template <>
26 | struct JsonVariantAs {
27 | typedef JsonArray& type;
28 | };
29 |
30 | template <>
31 | struct JsonVariantAs {
32 | typedef const JsonArray& type;
33 | };
34 |
35 | template <>
36 | struct JsonVariantAs {
37 | typedef JsonObject& type;
38 | };
39 |
40 | template <>
41 | struct JsonVariantAs {
42 | typedef const JsonObject& type;
43 | };
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonVariantComparer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "../JsonVariantBase.hpp"
11 | #include "../StringTraits/StringTraits.hpp"
12 | #include "../TypeTraits/EnableIf.hpp"
13 |
14 | namespace ArduinoJson {
15 | namespace Internals {
16 | template
17 | struct JsonVariantComparer {};
18 |
19 | template
20 | struct JsonVariantComparer<
21 | TString,
22 | typename TypeTraits::EnableIf::value>::type> {
23 | template
24 | static bool equals(const JsonVariantBase &variant,
25 | const TString &comparand) {
26 | const char *value = variant.template as();
27 | return Internals::StringTraits::equals(comparand, value);
28 | }
29 | };
30 |
31 | template
32 | struct JsonVariantComparer<
33 | TComparand, typename TypeTraits::EnableIf<
34 | !TypeTraits::IsVariant::value &&
35 | !TypeTraits::IsString::value>::type> {
36 | template
37 | static bool equals(const JsonVariantBase &variant,
38 | const TComparand &comparand) {
39 | return variant.template as() == comparand;
40 | }
41 | };
42 |
43 | template
44 | struct JsonVariantComparer::value>::type> {
47 | template
48 | static bool equals(const JsonVariantBase &left,
49 | const TVariant2 &right) {
50 | if (left.template is() && right.template is())
51 | return left.template as() == right.template as();
52 | if (left.template is() && right.template is())
53 | return left.template as() ==
54 | right.template as();
55 | if (left.template is() && right.template is())
56 | return left.template as() == right.template as();
57 | if (left.template is() && right.template is())
58 | return left.template as() == right.template as();
59 | if (left.template is() && right.template is())
60 | return left.template as() == right.template as();
61 | if (left.template is() && right.template is())
62 | return strcmp(left.template as(), right.template as()) ==
63 | 0;
64 |
65 | return false;
66 | }
67 | };
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonVariantContent.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "JsonFloat.hpp"
11 | #include "JsonInteger.hpp"
12 |
13 | namespace ArduinoJson {
14 |
15 | // Forward declarations
16 | class JsonArray;
17 | class JsonObject;
18 |
19 | namespace Internals {
20 | // A union that defines the actual content of a JsonVariant.
21 | // The enum JsonVariantType determines which member is in use.
22 | union JsonVariantContent {
23 | JsonFloat asFloat; // used for double and float
24 | JsonUInt asInteger; // used for bool, char, short, int and longs
25 | const char* asString; // asString can be null
26 | JsonArray* asArray; // asArray cannot be null
27 | JsonObject* asObject; // asObject cannot be null
28 | };
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonVariantDefault.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | namespace ArduinoJson {
11 | namespace Internals {
12 |
13 | template
14 | struct JsonVariantDefault {
15 | static T get() {
16 | return T();
17 | }
18 | };
19 |
20 | template
21 | struct JsonVariantDefault : JsonVariantDefault {};
22 |
23 | template
24 | struct JsonVariantDefault : JsonVariantDefault {};
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/JsonVariantType.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | namespace ArduinoJson {
11 | class JsonArray;
12 | class JsonObject;
13 |
14 | namespace Internals {
15 |
16 | // Enumerated type to know the current type of a JsonVariant.
17 | // The value determines which member of JsonVariantContent is used.
18 | enum JsonVariantType {
19 | JSON_UNDEFINED, // JsonVariant has not been initialized
20 | JSON_UNPARSED, // JsonVariant contains an unparsed string
21 | JSON_STRING, // JsonVariant stores a const char*
22 | JSON_BOOLEAN, // JsonVariant stores a bool
23 | JSON_POSITIVE_INTEGER, // JsonVariant stores an unsigned long
24 | JSON_NEGATIVE_INTEGER, // JsonVariant stores an unsigned long that must be
25 | // negated
26 | JSON_ARRAY, // JsonVariant stores a pointer to a JsonArray
27 | JSON_OBJECT, // JsonVariant stores a pointer to a JsonObject
28 |
29 | // The following values are reserved for float values
30 | // Multiple values are used for double, depending on the number of decimal
31 | // digits that must be printed in the JSON output.
32 | // This little trick allow to save one extra member in JsonVariant
33 | JSON_FLOAT_0_DECIMALS
34 | // JSON_FLOAT_1_DECIMAL
35 | // JSON_FLOAT_2_DECIMALS
36 | // ...
37 | };
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/List.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "../JsonBuffer.hpp"
11 | #include "ListConstIterator.hpp"
12 | #include "ListIterator.hpp"
13 |
14 | namespace ArduinoJson {
15 | namespace Internals {
16 |
17 | // A singly linked list of T.
18 | // The linked list is composed of ListNode.
19 | // It is derived by JsonArray and JsonObject
20 | template
21 | class List {
22 | public:
23 | typedef T value_type;
24 | typedef ListNode node_type;
25 | typedef ListIterator iterator;
26 | typedef ListConstIterator const_iterator;
27 |
28 | // Creates an empty List attached to a JsonBuffer.
29 | // The JsonBuffer allows to allocate new nodes.
30 | // When buffer is NULL, the List is not able to grow and success() returns
31 | // false. This is used to identify bad memory allocations and parsing
32 | // failures.
33 | explicit List(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {}
34 |
35 | // Returns true if the object is valid
36 | // Would return false in the following situation:
37 | // - the memory allocation failed (StaticJsonBuffer was too small)
38 | // - the JSON parsing failed
39 | bool success() const {
40 | return _buffer != NULL;
41 | }
42 |
43 | // Returns the numbers of elements in the list.
44 | // For a JsonObject, it would return the number of key-value pairs
45 | size_t size() const {
46 | size_t nodeCount = 0;
47 | for (node_type *node = _firstNode; node; node = node->next) nodeCount++;
48 | return nodeCount;
49 | }
50 |
51 | iterator add() {
52 | node_type *newNode = new (_buffer) node_type();
53 |
54 | if (_firstNode) {
55 | node_type *lastNode = _firstNode;
56 | while (lastNode->next) lastNode = lastNode->next;
57 | lastNode->next = newNode;
58 | } else {
59 | _firstNode = newNode;
60 | }
61 |
62 | return iterator(newNode);
63 | }
64 |
65 | iterator begin() {
66 | return iterator(_firstNode);
67 | }
68 | iterator end() {
69 | return iterator(NULL);
70 | }
71 |
72 | const_iterator begin() const {
73 | return const_iterator(_firstNode);
74 | }
75 | const_iterator end() const {
76 | return const_iterator(NULL);
77 | }
78 |
79 | void remove(iterator it) {
80 | node_type *nodeToRemove = it._node;
81 | if (!nodeToRemove) return;
82 | if (nodeToRemove == _firstNode) {
83 | _firstNode = nodeToRemove->next;
84 | } else {
85 | for (node_type *node = _firstNode; node; node = node->next)
86 | if (node->next == nodeToRemove) node->next = nodeToRemove->next;
87 | }
88 | }
89 |
90 | protected:
91 | JsonBuffer *_buffer;
92 |
93 | private:
94 | node_type *_firstNode;
95 | };
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/ListConstIterator.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "ListNode.hpp"
11 |
12 | namespace ArduinoJson {
13 | namespace Internals {
14 |
15 | // A read-only forward itertor for List
16 | template
17 | class ListConstIterator {
18 | public:
19 | explicit ListConstIterator(const ListNode *node = NULL) : _node(node) {}
20 |
21 | const T &operator*() const {
22 | return _node->content;
23 | }
24 | const T *operator->() {
25 | return &_node->content;
26 | }
27 |
28 | bool operator==(const ListConstIterator &other) const {
29 | return _node == other._node;
30 | }
31 |
32 | bool operator!=(const ListConstIterator &other) const {
33 | return _node != other._node;
34 | }
35 |
36 | ListConstIterator &operator++() {
37 | if (_node) _node = _node->next;
38 | return *this;
39 | }
40 |
41 | ListConstIterator &operator+=(size_t distance) {
42 | while (_node && distance) {
43 | _node = _node->next;
44 | --distance;
45 | }
46 | return *this;
47 | }
48 |
49 | private:
50 | const ListNode *_node;
51 | };
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/ListIterator.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "ListConstIterator.hpp"
11 | #include "ListNode.hpp"
12 |
13 | namespace ArduinoJson {
14 | namespace Internals {
15 |
16 | template
17 | class List;
18 |
19 | // A read-write forward iterator for List
20 | template
21 | class ListIterator {
22 | friend class List;
23 |
24 | public:
25 | explicit ListIterator(ListNode *node = NULL) : _node(node) {}
26 |
27 | T &operator*() const {
28 | return _node->content;
29 | }
30 | T *operator->() {
31 | return &_node->content;
32 | }
33 |
34 | bool operator==(const ListIterator &other) const {
35 | return _node == other._node;
36 | }
37 |
38 | bool operator!=(const ListIterator &other) const {
39 | return _node != other._node;
40 | }
41 |
42 | ListIterator &operator++() {
43 | if (_node) _node = _node->next;
44 | return *this;
45 | }
46 |
47 | ListIterator &operator+=(size_t distance) {
48 | while (_node && distance) {
49 | _node = _node->next;
50 | --distance;
51 | }
52 | return *this;
53 | }
54 |
55 | operator ListConstIterator() const {
56 | return ListConstIterator(_node);
57 | }
58 |
59 | private:
60 | ListNode *_node;
61 | };
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/ListNode.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include // for NULL
11 |
12 | #include "JsonBufferAllocated.hpp"
13 |
14 | namespace ArduinoJson {
15 | namespace Internals {
16 |
17 | // A node for a singly-linked list.
18 | // Used by List and its iterators.
19 | template
20 | struct ListNode : public Internals::JsonBufferAllocated {
21 | ListNode() : next(NULL) {}
22 |
23 | ListNode *next;
24 | T content;
25 | };
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/ReferenceType.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | namespace ArduinoJson {
11 | namespace Internals {
12 |
13 | // A type that is meant to be used by reference only (JsonArray and JsonObject)
14 | class ReferenceType {
15 | public:
16 | bool operator==(const ReferenceType& other) const {
17 | // two JsonArray are equal if they are the same instance
18 | // (we don't compare the content)
19 | return this == &other;
20 | }
21 |
22 | bool operator!=(const ReferenceType& other) const {
23 | return this != &other;
24 | }
25 |
26 | protected:
27 | ReferenceType() {}
28 |
29 | private:
30 | // copy constructor is private
31 | ReferenceType(const ReferenceType&);
32 |
33 | // copy operator is private
34 | ReferenceType& operator=(const ReferenceType&);
35 | };
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Data/ValueSetter.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "../JsonBuffer.hpp"
11 | #include "../JsonVariant.hpp"
12 | #include "../StringTraits/StringTraits.hpp"
13 | #include "../TypeTraits/EnableIf.hpp"
14 |
15 | namespace ArduinoJson {
16 | namespace Internals {
17 |
18 | template
19 | struct ValueSetter {
20 | template
21 | static bool set(JsonBuffer*, TDestination& destination, TSourceRef source) {
22 | destination = source;
23 | return true;
24 | }
25 | };
26 |
27 | template
28 | struct ValueSetter::should_duplicate>::type> {
30 | template
31 | static bool set(JsonBuffer* buffer, TDestination& destination,
32 | TSourceRef source) {
33 | const char* copy = buffer->strdup(source);
34 | if (!copy) return false;
35 | destination = copy;
36 | return true;
37 | }
38 | };
39 |
40 | template
41 | struct ValueSetter::should_duplicate>::type> {
43 | template
44 | static bool set(JsonBuffer*, TDestination& destination, TSourceRef source) {
45 | // unsigned char* -> char*
46 | destination = reinterpret_cast(source);
47 | return true;
48 | }
49 | };
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Deserialization/Comments.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | namespace ArduinoJson {
11 | namespace Internals {
12 | template
13 | void skipSpacesAndComments(TInput& input) {
14 | for (;;) {
15 | switch (input.current()) {
16 | // spaces
17 | case ' ':
18 | case '\t':
19 | case '\r':
20 | case '\n':
21 | input.move();
22 | continue;
23 |
24 | // comments
25 | case '/':
26 | switch (input.next()) {
27 | // C-style block comment
28 | case '*':
29 | input.move(); // skip '/'
30 | // no need to skip '*'
31 | for (;;) {
32 | input.move();
33 | if (input.current() == '\0') return;
34 | if (input.current() == '*' && input.next() == '/') {
35 | input.move(); // skip '*'
36 | input.move(); // skip '/'
37 | break;
38 | }
39 | }
40 | break;
41 |
42 | // C++-style line comment
43 | case '/':
44 | // not need to skip "//"
45 | for (;;) {
46 | input.move();
47 | if (input.current() == '\0') return;
48 | if (input.current() == '\n') break;
49 | }
50 | break;
51 |
52 | // not a comment, just a '/'
53 | default:
54 | return;
55 | }
56 | break;
57 |
58 | default:
59 | return;
60 | }
61 | }
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Deserialization/JsonParser.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "../JsonBuffer.hpp"
11 | #include "../JsonVariant.hpp"
12 | #include "../TypeTraits/IsConst.hpp"
13 | #include "StringWriter.hpp"
14 |
15 | namespace ArduinoJson {
16 | namespace Internals {
17 |
18 | // Parse JSON string to create JsonArrays and JsonObjects
19 | // This internal class is not indended to be used directly.
20 | // Instead, use JsonBuffer.parseArray() or .parseObject()
21 | template
22 | class JsonParser {
23 | public:
24 | JsonParser(JsonBuffer *buffer, TReader reader, TWriter writer,
25 | uint8_t nestingLimit)
26 | : _buffer(buffer),
27 | _reader(reader),
28 | _writer(writer),
29 | _nestingLimit(nestingLimit) {}
30 |
31 | JsonArray &parseArray();
32 | JsonObject &parseObject();
33 |
34 | JsonVariant parseVariant() {
35 | JsonVariant result;
36 | parseAnythingTo(&result);
37 | return result;
38 | }
39 |
40 | private:
41 | JsonParser &operator=(const JsonParser &); // non-copiable
42 |
43 | static bool eat(TReader &, char charToSkip);
44 | FORCE_INLINE bool eat(char charToSkip) {
45 | return eat(_reader, charToSkip);
46 | }
47 |
48 | const char *parseString();
49 | bool parseAnythingTo(JsonVariant *destination);
50 | FORCE_INLINE bool parseAnythingToUnsafe(JsonVariant *destination);
51 |
52 | inline bool parseArrayTo(JsonVariant *destination);
53 | inline bool parseObjectTo(JsonVariant *destination);
54 | inline bool parseStringTo(JsonVariant *destination);
55 |
56 | static inline bool isInRange(char c, char min, char max) {
57 | return min <= c && c <= max;
58 | }
59 |
60 | static inline bool isLetterOrNumber(char c) {
61 | return isInRange(c, '0', '9') || isInRange(c, 'a', 'z') ||
62 | isInRange(c, 'A', 'Z') || c == '+' || c == '-' || c == '.';
63 | }
64 |
65 | static inline bool isQuote(char c) {
66 | return c == '\'' || c == '\"';
67 | }
68 |
69 | JsonBuffer *_buffer;
70 | TReader _reader;
71 | TWriter _writer;
72 | uint8_t _nestingLimit;
73 | };
74 |
75 | template
76 | struct JsonParserBuilder {
77 | typedef typename Internals::StringTraits::Reader InputReader;
78 | typedef JsonParser TParser;
79 |
80 | static TParser makeParser(TJsonBuffer *buffer, TString &json,
81 | uint8_t nestingLimit) {
82 | return TParser(buffer, InputReader(json), *buffer, nestingLimit);
83 | }
84 | };
85 |
86 | template
87 | struct JsonParserBuilder<
88 | TJsonBuffer, TChar *,
89 | typename TypeTraits::EnableIf::value>::type> {
90 | typedef typename Internals::StringTraits::Reader TReader;
91 | typedef StringWriter TWriter;
92 | typedef JsonParser TParser;
93 |
94 | static TParser makeParser(TJsonBuffer *buffer, TChar *json,
95 | uint8_t nestingLimit) {
96 | return TParser(buffer, TReader(json), TWriter(json), nestingLimit);
97 | }
98 | };
99 |
100 | template
101 | inline typename JsonParserBuilder::TParser makeParser(
102 | TJsonBuffer *buffer, TString &json, uint8_t nestingLimit) {
103 | return JsonParserBuilder::makeParser(buffer, json,
104 | nestingLimit);
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Deserialization/JsonParserImpl.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "Comments.hpp"
11 | #include "JsonParser.hpp"
12 |
13 | template
14 | inline bool ArduinoJson::Internals::JsonParser::eat(
15 | TReader &reader, char charToSkip) {
16 | skipSpacesAndComments(reader);
17 | if (reader.current() != charToSkip) return false;
18 | reader.move();
19 | return true;
20 | }
21 |
22 | template
23 | inline bool
24 | ArduinoJson::Internals::JsonParser::parseAnythingTo(
25 | JsonVariant *destination) {
26 | if (_nestingLimit == 0) return false;
27 | _nestingLimit--;
28 | bool success = parseAnythingToUnsafe(destination);
29 | _nestingLimit++;
30 | return success;
31 | }
32 |
33 | template
34 | inline bool
35 | ArduinoJson::Internals::JsonParser::parseAnythingToUnsafe(
36 | JsonVariant *destination) {
37 | skipSpacesAndComments(_reader);
38 |
39 | switch (_reader.current()) {
40 | case '[':
41 | return parseArrayTo(destination);
42 |
43 | case '{':
44 | return parseObjectTo(destination);
45 |
46 | default:
47 | return parseStringTo(destination);
48 | }
49 | }
50 |
51 | template
52 | inline ArduinoJson::JsonArray &
53 | ArduinoJson::Internals::JsonParser::parseArray() {
54 | // Create an empty array
55 | JsonArray &array = _buffer->createArray();
56 |
57 | // Check opening braket
58 | if (!eat('[')) goto ERROR_MISSING_BRACKET;
59 | if (eat(']')) goto SUCCESS_EMPTY_ARRAY;
60 |
61 | // Read each value
62 | for (;;) {
63 | // 1 - Parse value
64 | JsonVariant value;
65 | if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE;
66 | if (!array.add(value)) goto ERROR_NO_MEMORY;
67 |
68 | // 2 - More values?
69 | if (eat(']')) goto SUCCES_NON_EMPTY_ARRAY;
70 | if (!eat(',')) goto ERROR_MISSING_COMMA;
71 | }
72 |
73 | SUCCESS_EMPTY_ARRAY:
74 | SUCCES_NON_EMPTY_ARRAY:
75 | return array;
76 |
77 | ERROR_INVALID_VALUE:
78 | ERROR_MISSING_BRACKET:
79 | ERROR_MISSING_COMMA:
80 | ERROR_NO_MEMORY:
81 | return JsonArray::invalid();
82 | }
83 |
84 | template
85 | inline bool ArduinoJson::Internals::JsonParser::parseArrayTo(
86 | JsonVariant *destination) {
87 | JsonArray &array = parseArray();
88 | if (!array.success()) return false;
89 |
90 | *destination = array;
91 | return true;
92 | }
93 |
94 | template
95 | inline ArduinoJson::JsonObject &
96 | ArduinoJson::Internals::JsonParser::parseObject() {
97 | // Create an empty object
98 | JsonObject &object = _buffer->createObject();
99 |
100 | // Check opening brace
101 | if (!eat('{')) goto ERROR_MISSING_BRACE;
102 | if (eat('}')) goto SUCCESS_EMPTY_OBJECT;
103 |
104 | // Read each key value pair
105 | for (;;) {
106 | // 1 - Parse key
107 | const char *key = parseString();
108 | if (!key) goto ERROR_INVALID_KEY;
109 | if (!eat(':')) goto ERROR_MISSING_COLON;
110 |
111 | // 2 - Parse value
112 | JsonVariant value;
113 | if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE;
114 | if (!object.set(key, value)) goto ERROR_NO_MEMORY;
115 |
116 | // 3 - More keys/values?
117 | if (eat('}')) goto SUCCESS_NON_EMPTY_OBJECT;
118 | if (!eat(',')) goto ERROR_MISSING_COMMA;
119 | }
120 |
121 | SUCCESS_EMPTY_OBJECT:
122 | SUCCESS_NON_EMPTY_OBJECT:
123 | return object;
124 |
125 | ERROR_INVALID_KEY:
126 | ERROR_INVALID_VALUE:
127 | ERROR_MISSING_BRACE:
128 | ERROR_MISSING_COLON:
129 | ERROR_MISSING_COMMA:
130 | ERROR_NO_MEMORY:
131 | return JsonObject::invalid();
132 | }
133 |
134 | template
135 | inline bool ArduinoJson::Internals::JsonParser::parseObjectTo(
136 | JsonVariant *destination) {
137 | JsonObject &object = parseObject();
138 | if (!object.success()) return false;
139 |
140 | *destination = object;
141 | return true;
142 | }
143 |
144 | template
145 | inline const char *
146 | ArduinoJson::Internals::JsonParser::parseString() {
147 | typename TypeTraits::RemoveReference::type::String str =
148 | _writer.startString();
149 |
150 | skipSpacesAndComments(_reader);
151 | char c = _reader.current();
152 |
153 | if (isQuote(c)) { // quotes
154 | _reader.move();
155 | char stopChar = c;
156 | for (;;) {
157 | c = _reader.current();
158 | if (c == '\0') break;
159 | _reader.move();
160 |
161 | if (c == stopChar) break;
162 |
163 | if (c == '\\') {
164 | // replace char
165 | c = Encoding::unescapeChar(_reader.current());
166 | if (c == '\0') break;
167 | _reader.move();
168 | }
169 |
170 | str.append(c);
171 | }
172 | } else { // no quotes
173 | for (;;) {
174 | if (!isLetterOrNumber(c)) break;
175 | _reader.move();
176 | str.append(c);
177 | c = _reader.current();
178 | }
179 | }
180 |
181 | return str.c_str();
182 | }
183 |
184 | template
185 | inline bool ArduinoJson::Internals::JsonParser::parseStringTo(
186 | JsonVariant *destination) {
187 | bool hasQuotes = isQuote(_reader.current());
188 | const char *value = parseString();
189 | if (value == NULL) return false;
190 | if (hasQuotes) {
191 | *destination = value;
192 | } else {
193 | *destination = RawJson(value);
194 | }
195 | return true;
196 | }
197 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/Deserialization/StringWriter.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | namespace ArduinoJson {
11 | namespace Internals {
12 |
13 | template
14 | class StringWriter {
15 | public:
16 | class String {
17 | public:
18 | String(TChar** ptr) : _writePtr(ptr), _startPtr(*ptr) {}
19 |
20 | void append(TChar c) {
21 | *(*_writePtr)++ = c;
22 | }
23 |
24 | const char* c_str() const {
25 | *(*_writePtr)++ = 0;
26 | return reinterpret_cast(_startPtr);
27 | }
28 |
29 | private:
30 | TChar** _writePtr;
31 | TChar* _startPtr;
32 | };
33 |
34 | StringWriter(TChar* buffer) : _ptr(buffer) {}
35 |
36 | String startString() {
37 | return String(&_ptr);
38 | }
39 |
40 | private:
41 | TChar* _ptr;
42 | };
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/DynamicJsonBuffer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "JsonBufferBase.hpp"
11 |
12 | #include
13 |
14 | #if defined(__clang__)
15 | #pragma clang diagnostic push
16 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
17 | #elif defined(__GNUC__)
18 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
19 | #pragma GCC diagnostic push
20 | #endif
21 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
22 | #endif
23 |
24 | namespace ArduinoJson {
25 | class DefaultAllocator {
26 | public:
27 | void* allocate(size_t size) {
28 | return malloc(size);
29 | }
30 | void deallocate(void* pointer) {
31 | free(pointer);
32 | }
33 | };
34 |
35 | template
36 | class DynamicJsonBufferBase
37 | : public JsonBufferBase > {
38 | struct Block;
39 | struct EmptyBlock {
40 | Block* next;
41 | size_t capacity;
42 | size_t size;
43 | };
44 | struct Block : EmptyBlock {
45 | uint8_t data[1];
46 | };
47 |
48 | public:
49 | DynamicJsonBufferBase(size_t initialSize = 256)
50 | : _head(NULL), _nextBlockCapacity(initialSize) {}
51 |
52 | ~DynamicJsonBufferBase() {
53 | Block* currentBlock = _head;
54 |
55 | while (currentBlock != NULL) {
56 | Block* nextBlock = currentBlock->next;
57 | _allocator.deallocate(currentBlock);
58 | currentBlock = nextBlock;
59 | }
60 | }
61 |
62 | size_t size() const {
63 | size_t total = 0;
64 | for (const Block* b = _head; b; b = b->next) total += b->size;
65 | return total;
66 | }
67 |
68 | virtual void* alloc(size_t bytes) {
69 | alignNextAlloc();
70 | return canAllocInHead(bytes) ? allocInHead(bytes) : allocInNewBlock(bytes);
71 | }
72 |
73 | class String {
74 | public:
75 | String(DynamicJsonBufferBase* parent)
76 | : _parent(parent), _start(NULL), _length(0) {}
77 |
78 | void append(char c) {
79 | if (_parent->canAllocInHead(1)) {
80 | char* end = static_cast(_parent->allocInHead(1));
81 | *end = c;
82 | if (_length == 0) _start = end;
83 | } else {
84 | char* newStart =
85 | static_cast(_parent->allocInNewBlock(_length + 1));
86 | if (_start && newStart) memcpy(newStart, _start, _length);
87 | if (newStart) newStart[_length] = c;
88 | _start = newStart;
89 | }
90 | _length++;
91 | }
92 |
93 | const char* c_str() {
94 | append(0);
95 | return _start;
96 | }
97 |
98 | private:
99 | DynamicJsonBufferBase* _parent;
100 | char* _start;
101 | int _length;
102 | };
103 |
104 | String startString() {
105 | return String(this);
106 | }
107 |
108 | private:
109 | void alignNextAlloc() {
110 | if (_head) _head->size = this->round_size_up(_head->size);
111 | }
112 |
113 | bool canAllocInHead(size_t bytes) const {
114 | return _head != NULL && _head->size + bytes <= _head->capacity;
115 | }
116 |
117 | void* allocInHead(size_t bytes) {
118 | void* p = _head->data + _head->size;
119 | _head->size += bytes;
120 | return p;
121 | }
122 |
123 | void* allocInNewBlock(size_t bytes) {
124 | size_t capacity = _nextBlockCapacity;
125 | if (bytes > capacity) capacity = bytes;
126 | if (!addNewBlock(capacity)) return NULL;
127 | _nextBlockCapacity *= 2;
128 | return allocInHead(bytes);
129 | }
130 |
131 | bool addNewBlock(size_t capacity) {
132 | size_t bytes = sizeof(EmptyBlock) + capacity;
133 | Block* block = static_cast(_allocator.allocate(bytes));
134 | if (block == NULL) return false;
135 | block->capacity = capacity;
136 | block->size = 0;
137 | block->next = _head;
138 | _head = block;
139 | return true;
140 | }
141 |
142 | TAllocator _allocator;
143 | Block* _head;
144 | size_t _nextBlockCapacity;
145 | };
146 |
147 | #if defined(__clang__)
148 | #pragma clang diagnostic pop
149 | #elif defined(__GNUC__)
150 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
151 | #pragma GCC diagnostic pop
152 | #endif
153 | #endif
154 |
155 | // Implements a JsonBuffer with dynamic memory allocation.
156 | // You are strongly encouraged to consider using StaticJsonBuffer which is much
157 | // more suitable for embedded systems.
158 | typedef DynamicJsonBufferBase DynamicJsonBuffer;
159 | }
160 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonArray.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "Data/JsonBufferAllocated.hpp"
11 | #include "Data/List.hpp"
12 | #include "Data/ReferenceType.hpp"
13 | #include "Data/ValueSetter.hpp"
14 | #include "JsonVariant.hpp"
15 | #include "Serialization/JsonPrintable.hpp"
16 | #include "StringTraits/StringTraits.hpp"
17 | #include "TypeTraits/EnableIf.hpp"
18 | #include "TypeTraits/IsArray.hpp"
19 | #include "TypeTraits/IsFloatingPoint.hpp"
20 | #include "TypeTraits/IsSame.hpp"
21 |
22 | // Returns the size (in bytes) of an array with n elements.
23 | // Can be very handy to determine the size of a StaticJsonBuffer.
24 | #define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \
25 | (sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(JsonArray::node_type))
26 |
27 | namespace ArduinoJson {
28 |
29 | // Forward declarations
30 | class JsonObject;
31 | class JsonBuffer;
32 | class JsonArraySubscript;
33 |
34 | // An array of JsonVariant.
35 | //
36 | // The constructor is private, instances must be created via
37 | // JsonBuffer::createArray() or JsonBuffer::parseArray().
38 | // A JsonArray can be serialized to a JSON string via JsonArray::printTo().
39 | // It can also be deserialized from a JSON string via JsonBuffer::parseArray().
40 | class JsonArray : public Internals::JsonPrintable,
41 | public Internals::ReferenceType,
42 | public Internals::List,
43 | public Internals::JsonBufferAllocated {
44 | public:
45 | // Create an empty JsonArray attached to the specified JsonBuffer.
46 | // You should not call this constructor directly.
47 | // Instead, use JsonBuffer::createArray() or JsonBuffer::parseArray().
48 | explicit JsonArray(JsonBuffer *buffer)
49 | : Internals::List(buffer) {}
50 |
51 | // Gets the value at the specified index
52 | const JsonArraySubscript operator[](size_t index) const;
53 |
54 | // Gets or sets the value at specified index
55 | JsonArraySubscript operator[](size_t index);
56 |
57 | // Adds the specified value at the end of the array.
58 | //
59 | // bool add(TValue);
60 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant,
61 | // const std::string&, const String&,
62 | // const JsonArray&, const JsonObject&
63 | template
64 | typename TypeTraits::EnableIf::value, bool>::type add(
65 | const T &value) {
66 | return add_impl(value);
67 | }
68 | //
69 | // bool add(TValue);
70 | // TValue = const char*, const char[N], const FlashStringHelper*
71 | template
72 | bool add(const T *value) {
73 | return add_impl(value);
74 | }
75 | //
76 | // bool add(TValue value, uint8_t decimals);
77 | // TValue = float, double
78 | template
79 | bool add(T value, uint8_t decimals) {
80 | return add_impl(JsonVariant(value, decimals));
81 | }
82 |
83 | // Sets the value at specified index.
84 | //
85 | // bool add(size_t index, TValue);
86 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant,
87 | // const std::string&, const String&,
88 | // const JsonArray&, const JsonObject&
89 | template
90 | typename TypeTraits::EnableIf::value, bool>::type set(
91 | size_t index, const T &value) {
92 | return set_impl(index, value);
93 | }
94 | //
95 | // bool add(size_t index, TValue);
96 | // TValue = const char*, const char[N], const FlashStringHelper*
97 | template
98 | bool set(size_t index, const T *value) {
99 | return set_impl(index, value);
100 | }
101 | //
102 | // bool set(size_t index, TValue value, uint8_t decimals);
103 | // TValue = float, double
104 | template
105 | typename TypeTraits::EnableIf::value,
106 | bool>::type
107 | set(size_t index, T value, uint8_t decimals) {
108 | return set_impl(index, JsonVariant(value, decimals));
109 | }
110 |
111 | // Gets the value at the specified index.
112 | template
113 | typename Internals::JsonVariantAs::type get(size_t index) const {
114 | const_iterator it = begin() += index;
115 | return it != end() ? it->as() : Internals::JsonVariantDefault::get();
116 | }
117 |
118 | // Check the type of the value at specified index.
119 | template
120 | bool is(size_t index) const {
121 | const_iterator it = begin() += index;
122 | return it != end() ? it->is() : false;
123 | }
124 |
125 | // Creates a JsonArray and adds a reference at the end of the array.
126 | // It's a shortcut for JsonBuffer::createArray() and JsonArray::add()
127 | JsonArray &createNestedArray();
128 |
129 | // Creates a JsonObject and adds a reference at the end of the array.
130 | // It's a shortcut for JsonBuffer::createObject() and JsonArray::add()
131 | JsonObject &createNestedObject();
132 |
133 | // Removes element at specified index.
134 | void remove(size_t index) {
135 | remove(begin() += index);
136 | }
137 | using Internals::List::remove;
138 |
139 | // Returns a reference an invalid JsonArray.
140 | // This object is meant to replace a NULL pointer.
141 | // This is used when memory allocation or JSON parsing fail.
142 | static JsonArray &invalid() {
143 | static JsonArray instance(NULL);
144 | return instance;
145 | }
146 |
147 | // Imports a 1D array
148 | template
149 | bool copyFrom(T (&array)[N]) {
150 | return copyFrom(array, N);
151 | }
152 |
153 | // Imports a 1D array
154 | template
155 | bool copyFrom(T *array, size_t len) {
156 | bool ok = true;
157 | for (size_t i = 0; i < len; i++) {
158 | ok &= add(array[i]);
159 | }
160 | return ok;
161 | }
162 |
163 | // Imports a 2D array
164 | template
165 | bool copyFrom(T (&array)[N1][N2]) {
166 | bool ok = true;
167 | for (size_t i = 0; i < N1; i++) {
168 | JsonArray &nestedArray = createNestedArray();
169 | for (size_t j = 0; j < N2; j++) {
170 | ok &= nestedArray.add(array[i][j]);
171 | }
172 | }
173 | return ok;
174 | }
175 |
176 | // Exports a 1D array
177 | template
178 | size_t copyTo(T (&array)[N]) const {
179 | return copyTo(array, N);
180 | }
181 |
182 | // Exports a 1D array
183 | template
184 | size_t copyTo(T *array, size_t len) const {
185 | size_t i = 0;
186 | for (const_iterator it = begin(); it != end() && i < len; ++it)
187 | array[i++] = *it;
188 | return i;
189 | }
190 |
191 | // Exports a 2D array
192 | template
193 | void copyTo(T (&array)[N1][N2]) const {
194 | size_t i = 0;
195 | for (const_iterator it = begin(); it != end() && i < N1; ++it) {
196 | it->as().copyTo(array[i++]);
197 | }
198 | }
199 |
200 | #if ARDUINOJSON_ENABLE_DEPRECATED
201 | DEPRECATED("use remove() instead")
202 | FORCE_INLINE void removeAt(size_t index) {
203 | return remove(index);
204 | }
205 | #endif
206 |
207 | private:
208 | template
209 | bool set_impl(size_t index, TValueRef value) {
210 | iterator it = begin() += index;
211 | if (it == end()) return false;
212 | return Internals::ValueSetter::set(_buffer, *it, value);
213 | }
214 |
215 | template
216 | bool add_impl(TValueRef value) {
217 | iterator it = Internals::List::add();
218 | if (it == end()) return false;
219 | return Internals::ValueSetter::set(_buffer, *it, value);
220 | }
221 | };
222 |
223 | namespace Internals {
224 | template <>
225 | struct JsonVariantDefault {
226 | static JsonArray &get() {
227 | return JsonArray::invalid();
228 | }
229 | };
230 | }
231 | }
232 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonArrayImpl.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "JsonArray.hpp"
11 | #include "JsonArraySubscript.hpp"
12 | #include "JsonObject.hpp"
13 |
14 | namespace ArduinoJson {
15 |
16 | inline JsonArray &JsonArray::createNestedArray() {
17 | if (!_buffer) return JsonArray::invalid();
18 | JsonArray &array = _buffer->createArray();
19 | add(array);
20 | return array;
21 | }
22 |
23 | inline JsonObject &JsonArray::createNestedObject() {
24 | if (!_buffer) return JsonObject::invalid();
25 | JsonObject &object = _buffer->createObject();
26 | add(object);
27 | return object;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonArraySubscript.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "Configuration.hpp"
11 | #include "JsonVariantBase.hpp"
12 |
13 | #ifdef _MSC_VER
14 | #pragma warning(push)
15 | #pragma warning(disable : 4522)
16 | #endif
17 |
18 | namespace ArduinoJson {
19 | class JsonArraySubscript : public JsonVariantBase {
20 | public:
21 | FORCE_INLINE JsonArraySubscript(JsonArray& array, size_t index)
22 | : _array(array), _index(index) {}
23 |
24 | FORCE_INLINE JsonArraySubscript& operator=(const JsonArraySubscript& src) {
25 | _array.set(_index, src);
26 | return *this;
27 | }
28 |
29 | // Replaces the value
30 | //
31 | // operator=(TValue)
32 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant,
33 | // const std::string&, const String&,
34 | // const JsonArray&, const JsonObject&
35 | template
36 | FORCE_INLINE JsonArraySubscript& operator=(const T& src) {
37 | _array.set(_index, src);
38 | return *this;
39 | }
40 | //
41 | // operator=(TValue)
42 | // TValue = const char*, const char[N], const FlashStringHelper*
43 | template
44 | FORCE_INLINE JsonArraySubscript& operator=(const T* src) {
45 | _array.set(_index, src);
46 | return *this;
47 | }
48 |
49 | FORCE_INLINE bool success() const {
50 | return _index < _array.size();
51 | }
52 |
53 | template
54 | FORCE_INLINE typename Internals::JsonVariantAs::type as() const {
55 | return _array.get(_index);
56 | }
57 |
58 | template
59 | FORCE_INLINE bool is() const {
60 | return _array.is(_index);
61 | }
62 |
63 | // Replaces the value
64 | //
65 | // bool set(TValue)
66 | // TValue = bool, long, int, short, float, double, RawJson, JsonVariant,
67 | // const std::string&, const String&,
68 | // const JsonArray&, const JsonObject&
69 | template
70 | FORCE_INLINE bool set(const TValue& value) {
71 | return _array.set(_index, value);
72 | }
73 | //
74 | // bool set(TValue)
75 | // TValue = const char*, const char[N], const FlashStringHelper*
76 | template
77 | FORCE_INLINE bool set(const TValue* value) {
78 | return _array.set(_index, value);
79 | }
80 | //
81 | // bool set(TValue, uint8_t decimals);
82 | // TValue = float, double
83 | template
84 | FORCE_INLINE bool set(const TValue& value, uint8_t decimals) {
85 | return _array.set(_index, value, decimals);
86 | }
87 |
88 | private:
89 | JsonArray& _array;
90 | const size_t _index;
91 | };
92 |
93 | #if ARDUINOJSON_ENABLE_STD_STREAM
94 | inline std::ostream& operator<<(std::ostream& os,
95 | const JsonArraySubscript& source) {
96 | return source.printTo(os);
97 | }
98 | #endif
99 |
100 | inline JsonArraySubscript JsonArray::operator[](size_t index) {
101 | return JsonArraySubscript(*this, index);
102 | }
103 |
104 | inline const JsonArraySubscript JsonArray::operator[](size_t index) const {
105 | return JsonArraySubscript(*const_cast(this), index);
106 | }
107 |
108 | template
109 | inline JsonArraySubscript JsonVariantBase::operator[](int index) {
110 | return as()[index];
111 | }
112 |
113 | template
114 | inline const JsonArraySubscript JsonVariantBase::operator[](
115 | int index) const {
116 | return as()[index];
117 | }
118 |
119 | } // namespace ArduinoJson
120 |
121 | #ifdef _MSC_VER
122 | #pragma warning(pop)
123 | #endif
124 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonBuffer.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include // for size_t
11 | #include // for uint8_t
12 | #include
13 |
14 | #include "JsonVariant.hpp"
15 | #include "TypeTraits/EnableIf.hpp"
16 | #include "TypeTraits/IsArray.hpp"
17 |
18 | #if defined(__clang__)
19 | #pragma clang diagnostic push
20 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
21 | #elif defined(__GNUC__)
22 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
23 | #pragma GCC diagnostic push
24 | #endif
25 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
26 | #endif
27 |
28 | namespace ArduinoJson {
29 | class JsonArray;
30 | class JsonObject;
31 |
32 | // Entry point for using the library.
33 | //
34 | // Handle the memory management (done in derived classes) and calls the parser.
35 | // This abstract class is implemented by StaticJsonBuffer which implements a
36 | // fixed memory allocation.
37 | class JsonBuffer {
38 | public:
39 | // CAUTION: NO VIRTUAL DESTRUCTOR!
40 | // If we add a virtual constructor the Arduino compiler will add malloc() and
41 | // free() to the binary, adding 706 useless bytes.
42 | // virtual ~JsonBuffer() {}
43 |
44 | // Allocates an empty JsonArray.
45 | //
46 | // Returns a reference to the new JsonArray or JsonArray::invalid() if the
47 | // allocation fails.
48 | JsonArray &createArray();
49 |
50 | // Allocates an empty JsonObject.
51 | //
52 | // Returns a reference to the new JsonObject or JsonObject::invalid() if the
53 | // allocation fails.
54 | JsonObject &createObject();
55 |
56 | // Duplicates a string
57 | //
58 | // char* strdup(TValue);
59 | // TValue = const std::string&, const String&,
60 | template
61 | typename TypeTraits::EnableIf::value,
62 | char *>::type
63 | strdup(const TString &src) {
64 | return Internals::StringTraits::duplicate(src, this);
65 | }
66 | //
67 | // char* strdup(TValue);
68 | // TValue = const char*, const char[N], const FlashStringHelper*
69 | template
70 | char *strdup(const TString *src) {
71 | return Internals::StringTraits::duplicate(src, this);
72 | }
73 |
74 | // Allocates n bytes in the JsonBuffer.
75 | // Return a pointer to the allocated memory or NULL if allocation fails.
76 | virtual void *alloc(size_t size) = 0;
77 |
78 | protected:
79 | // Preserve aligment if necessary
80 | static FORCE_INLINE size_t round_size_up(size_t bytes) {
81 | #if ARDUINOJSON_ENABLE_ALIGNMENT
82 | const size_t x = sizeof(void *) - 1;
83 | return (bytes + x) & ~x;
84 | #else
85 | return bytes;
86 | #endif
87 | }
88 | };
89 | }
90 |
91 | #if defined(__clang__)
92 | #pragma clang diagnostic pop
93 | #elif defined(__GNUC__)
94 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
95 | #pragma GCC diagnostic pop
96 | #endif
97 | #endif
98 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonBufferBase.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "Deserialization/JsonParser.hpp"
11 |
12 | #if defined(__clang__)
13 | #pragma clang diagnostic push
14 | #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
15 | #elif defined(__GNUC__)
16 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
17 | #pragma GCC diagnostic push
18 | #endif
19 | #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
20 | #endif
21 |
22 | namespace ArduinoJson {
23 | template
24 | class JsonBufferBase : public JsonBuffer {
25 | public:
26 | // Allocates and populate a JsonArray from a JSON string.
27 | //
28 | // The First argument is a pointer to the JSON string, the memory must be
29 | // writable
30 | // because the parser will insert null-terminators and replace escaped chars.
31 | //
32 | // The second argument set the nesting limit
33 | //
34 | // Returns a reference to the new JsonObject or JsonObject::invalid() if the
35 | // allocation fails.
36 | // With this overload, the JsonBuffer will make a copy of the string
37 | //
38 | // JsonArray& parseArray(TString);
39 | // TString = const std::string&, const String&
40 | template
41 | typename TypeTraits::EnableIf::value,
42 | JsonArray &>::type
43 | parseArray(const TString &json,
44 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
45 | return Internals::makeParser(that(), json, nestingLimit).parseArray();
46 | }
47 | //
48 | // JsonArray& parseArray(TString);
49 | // TString = const char*, const char[N], const FlashStringHelper*
50 | template
51 | JsonArray &parseArray(
52 | TString *json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
53 | return Internals::makeParser(that(), json, nestingLimit).parseArray();
54 | }
55 | //
56 | // JsonArray& parseArray(TString);
57 | // TString = std::istream&, Stream&
58 | template
59 | JsonArray &parseArray(
60 | TString &json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
61 | return Internals::makeParser(that(), json, nestingLimit).parseArray();
62 | }
63 |
64 | // Allocates and populate a JsonObject from a JSON string.
65 | //
66 | // The First argument is a pointer to the JSON string, the memory must be
67 | // writable
68 | // because the parser will insert null-terminators and replace escaped chars.
69 | //
70 | // The second argument set the nesting limit
71 | //
72 | // Returns a reference to the new JsonObject or JsonObject::invalid() if the
73 | // allocation fails.
74 | //
75 | // JsonObject& parseObject(TString);
76 | // TString = const std::string&, const String&
77 | template
78 | typename TypeTraits::EnableIf::value,
79 | JsonObject &>::type
80 | parseObject(const TString &json,
81 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
82 | return Internals::makeParser(that(), json, nestingLimit).parseObject();
83 | }
84 | //
85 | // JsonObject& parseObject(TString);
86 | // TString = const char*, const char[N], const FlashStringHelper*
87 | template
88 | JsonObject &parseObject(
89 | TString *json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
90 | return Internals::makeParser(that(), json, nestingLimit).parseObject();
91 | }
92 | //
93 | // JsonObject& parseObject(TString);
94 | // TString = std::istream&, Stream&
95 | template
96 | JsonObject &parseObject(
97 | TString &json, uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
98 | return Internals::makeParser(that(), json, nestingLimit).parseObject();
99 | }
100 |
101 | // Generalized version of parseArray() and parseObject(), also works for
102 | // integral types.
103 | //
104 | // JsonVariant parse(TString);
105 | // TString = const std::string&, const String&
106 | template
107 | typename TypeTraits::EnableIf::value,
108 | JsonVariant>::type
109 | parse(const TString &json,
110 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
111 | return Internals::makeParser(that(), json, nestingLimit).parseVariant();
112 | }
113 | //
114 | // JsonVariant parse(TString);
115 | // TString = const char*, const char[N], const FlashStringHelper*
116 | template
117 | JsonVariant parse(TString *json,
118 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
119 | return Internals::makeParser(that(), json, nestingLimit).parseVariant();
120 | }
121 | //
122 | // JsonVariant parse(TString);
123 | // TString = std::istream&, Stream&
124 | template
125 | JsonVariant parse(TString &json,
126 | uint8_t nestingLimit = ARDUINOJSON_DEFAULT_NESTING_LIMIT) {
127 | return Internals::makeParser(that(), json, nestingLimit).parseVariant();
128 | }
129 |
130 | private:
131 | TDerived *that() {
132 | return static_cast(this);
133 | }
134 | };
135 | }
136 |
137 | #if defined(__clang__)
138 | #pragma clang diagnostic pop
139 | #elif defined(__GNUC__)
140 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
141 | #pragma GCC diagnostic pop
142 | #endif
143 | #endif
144 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonBufferImpl.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "Deserialization/JsonParser.hpp"
11 |
12 | inline ArduinoJson::JsonArray &ArduinoJson::JsonBuffer::createArray() {
13 | JsonArray *ptr = new (this) JsonArray(this);
14 | return ptr ? *ptr : JsonArray::invalid();
15 | }
16 |
17 | inline ArduinoJson::JsonObject &ArduinoJson::JsonBuffer::createObject() {
18 | JsonObject *ptr = new (this) JsonObject(this);
19 | return ptr ? *ptr : JsonObject::invalid();
20 | }
21 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonObjectImpl.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "JsonArray.hpp"
11 | #include "JsonObject.hpp"
12 | #include "JsonObjectSubscript.hpp"
13 |
14 | namespace ArduinoJson {
15 |
16 | template
17 | inline JsonArray &JsonObject::createNestedArray_impl(TStringRef key) {
18 | if (!_buffer) return JsonArray::invalid();
19 | JsonArray &array = _buffer->createArray();
20 | set(key, array);
21 | return array;
22 | }
23 |
24 | template
25 | inline JsonObject &JsonObject::createNestedObject_impl(TStringRef key) {
26 | if (!_buffer) return JsonObject::invalid();
27 | JsonObject &object = _buffer->createObject();
28 | set(key, object);
29 | return object;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonObjectSubscript.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "Configuration.hpp"
11 | #include "JsonVariantBase.hpp"
12 | #include "TypeTraits/EnableIf.hpp"
13 |
14 | #ifdef _MSC_VER
15 | #pragma warning(push)
16 | #pragma warning(disable : 4522)
17 | #endif
18 |
19 | namespace ArduinoJson {
20 |
21 | template
22 | class JsonObjectSubscript
23 | : public JsonVariantBase > {
24 | typedef JsonObjectSubscript this_type;
25 |
26 | public:
27 | FORCE_INLINE JsonObjectSubscript(JsonObject& object, TStringRef key)
28 | : _object(object), _key(key) {}
29 |
30 | FORCE_INLINE this_type& operator=(const this_type& src) {
31 | _object.set(_key, src);
32 | return *this;
33 | }
34 |
35 | // Set the specified value
36 | //
37 | // operator=(TValue);
38 | // TValue = bool, char, long, int, short, float, double,
39 | // const std::string&, const String&,
40 | // const JsonArray&, const JsonObject&
41 | template
42 | FORCE_INLINE
43 | typename TypeTraits::EnableIf::value,
44 | this_type&>::type
45 | operator=(const TValue& src) {
46 | _object.set(_key, src);
47 | return *this;
48 | }
49 | //
50 | // operator=(TValue);
51 | // TValue = const char*, const char[N], const FlashStringHelper*
52 | template
53 | FORCE_INLINE this_type& operator=(const TValue* src) {
54 | _object.set(_key, src);
55 | return *this;
56 | }
57 |
58 | FORCE_INLINE bool success() const {
59 | return _object.containsKey(_key);
60 | }
61 |
62 | template
63 | FORCE_INLINE typename Internals::JsonVariantAs::type as() const {
64 | return _object.get(_key);
65 | }
66 |
67 | template
68 | FORCE_INLINE bool is() const {
69 | return _object.is(_key);
70 | }
71 |
72 | // Sets the specified value.
73 | //
74 | // bool set(TValue);
75 | // TValue = bool, char, long, int, short, float, double, RawJson, JsonVariant,
76 | // const std::string&, const String&,
77 | // const JsonArray&, const JsonObject&
78 | template
79 | FORCE_INLINE
80 | typename TypeTraits::EnableIf::value,
81 | bool>::type
82 | set(const TValue& value) {
83 | return _object.set(_key, value);
84 | }
85 | //
86 | // bool set(TValue);
87 | // TValue = const char*, const char[N], const FlashStringHelper*
88 | template
89 | FORCE_INLINE bool set(const TValue* value) {
90 | return _object.set(_key, value);
91 | }
92 | //
93 | // bool set(TValue, uint8_t decimals);
94 | // TValue = float, double
95 | template
96 | FORCE_INLINE bool set(const TValue& value, uint8_t decimals) {
97 | return _object.set(_key, value, decimals);
98 | }
99 |
100 | private:
101 | JsonObject& _object;
102 | TStringRef _key;
103 | };
104 |
105 | #if ARDUINOJSON_ENABLE_STD_STREAM
106 | template
107 | inline std::ostream& operator<<(std::ostream& os,
108 | const JsonObjectSubscript& source) {
109 | return source.printTo(os);
110 | }
111 | #endif
112 | } // namespace ArduinoJson
113 |
114 | #ifdef _MSC_VER
115 | #pragma warning(pop)
116 | #endif
117 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonPair.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "JsonVariant.hpp"
11 |
12 | namespace ArduinoJson {
13 |
14 | // A key value pair for JsonObject.
15 | struct JsonPair {
16 | const char* key;
17 | JsonVariant value;
18 | };
19 | }
20 |
--------------------------------------------------------------------------------
/ArduinoJson/ArduinoJson/JsonVariantBase.hpp:
--------------------------------------------------------------------------------
1 | // Copyright Benoit Blanchon 2014-2017
2 | // MIT License
3 | //
4 | // Arduino JSON library
5 | // https://bblanchon.github.io/ArduinoJson/
6 | // If you like this project, please add a star!
7 |
8 | #pragma once
9 |
10 | #include "Data/JsonVariantAs.hpp"
11 | #include "Polyfills/attributes.hpp"
12 | #include "Serialization/JsonPrintable.hpp"
13 |
14 | namespace ArduinoJson {
15 |
16 | // Forward declarations.
17 | class JsonArraySubscript;
18 | template
19 | class JsonObjectSubscript;
20 |
21 | template
22 | class JsonVariantBase : public Internals::JsonPrintable {
23 | public:
24 | #if ARDUINOJSON_ENABLE_DEPRECATED
25 | DEPRECATED("use as() instead")
26 | FORCE_INLINE JsonArray &asArray() const {
27 | return as();
28 | }
29 |
30 | DEPRECATED("use as() instead")
31 | FORCE_INLINE JsonObject &asObject() const {
32 | return as();
33 | }
34 |
35 | DEPRECATED("use as() instead")
36 | FORCE_INLINE const char *asString() const {
37 | return as();
38 | }
39 | #endif
40 |
41 | // Gets the variant as an array.
42 | // Returns a reference to the JsonArray or JsonArray::invalid() if the
43 | // variant
44 | // is not an array.
45 | FORCE_INLINE operator JsonArray &() const {
46 | return as();
47 | }
48 |
49 | // Gets the variant as an object.
50 | // Returns a reference to the JsonObject or JsonObject::invalid() if the
51 | // variant is not an object.
52 | FORCE_INLINE operator JsonObject &() const {
53 | return as();
54 | }
55 |
56 | template
57 | FORCE_INLINE operator T() const {
58 | return as();
59 | }
60 |
61 | template
62 | FORCE_INLINE const typename Internals::JsonVariantAs::type as() const {
63 | return impl()->template as();
64 | }
65 |
66 | template
67 | FORCE_INLINE bool is() const {
68 | return impl()->template is();
69 | }
70 |
71 | // Mimics an array or an object.
72 | // Returns the size of the array or object if the variant has that type.
73 | // Returns 0 if the variant is neither an array nor an object
74 | size_t size() const {
75 | return as().size() + as().size();
76 | }
77 |
78 | // Mimics an array.
79 | // Returns the element at specified index if the variant is an array.
80 | // Returns JsonVariant::invalid() if the variant is not an array.
81 | FORCE_INLINE const JsonArraySubscript operator[](int index) const;
82 | FORCE_INLINE JsonArraySubscript operator[](int index);
83 |
84 | // Mimics an object.
85 | // Returns the value associated with the specified key if the variant is
86 | // an object.
87 | // Return JsonVariant::invalid() if the variant is not an object.
88 | //
89 | // const JsonObjectSubscript operator[](TKey) const;
90 | // TKey = const std::string&, const String&
91 | template
92 | FORCE_INLINE typename TypeTraits::EnableIf<
93 | Internals::StringTraits::has_equals,
94 | const JsonObjectSubscript >::type
95 | operator[](const TString &key) const {
96 | return as()[key];
97 | }
98 | //
99 | // const JsonObjectSubscript operator[](TKey) const;
100 | // TKey = const std::string&, const String&
101 | template
102 | FORCE_INLINE typename TypeTraits::EnableIf<
103 | Internals::StringTraits::has_equals,
104 | JsonObjectSubscript >::type
105 | operator[](const TString &key) {
106 | return as()[key];
107 | }
108 | //
109 | // JsonObjectSubscript operator[](TKey);
110 | // TKey = const char*, const char[N], const FlashStringHelper*
111 | template
112 | FORCE_INLINE typename TypeTraits::EnableIf<
113 | Internals::StringTraits::has_equals,
114 | JsonObjectSubscript >::type
115 | operator[](const TString *key) {
116 | return as