forked from bblanchon/ArduinoJson
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
d3bc52951a | |||
2f7232859e | |||
4a7232ac99 | |||
72d78432c9 | |||
f6cd42d916 | |||
542dff2a08 | |||
e75e843c88 | |||
146a76247c | |||
f28157cab7 | |||
1ce16ce449 |
@ -104,10 +104,8 @@ matrix:
|
||||
osx_image: xcode7.3
|
||||
compiler: clang
|
||||
env: SCRIPT=cmake-osx
|
||||
- env: SCRIPT=arduino VERSION=1.5.8 BOARD=arduino:avr:uno
|
||||
- env: SCRIPT=arduino VERSION=1.6.7 BOARD=arduino:avr:uno
|
||||
- env: SCRIPT=arduino VERSION=1.6.8 BOARD=arduino:avr:uno
|
||||
- env: SCRIPT=arduino VERSION=1.6.9 BOARD=arduino:avr:uno
|
||||
- env: SCRIPT=arduino VERSION=1.6.12 BOARD=arduino:avr:uno
|
||||
- env: SCRIPT=platformio BOARD=uno
|
||||
- env: SCRIPT=platformio BOARD=due
|
||||
- env: SCRIPT=platformio BOARD=esp01
|
||||
|
12
CHANGELOG.md
12
CHANGELOG.md
@ -1,6 +1,18 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v5.7.2
|
||||
------
|
||||
|
||||
* Made PROGMEM available on more platforms (issue #381)
|
||||
* Fixed PROGMEM causing an exception on ESP8266 (issue #383)
|
||||
|
||||
v5.7.1
|
||||
------
|
||||
|
||||
* Added support for PROGMEM (issue #76)
|
||||
* Fixed compilation error when index is not an `int` (issue #381)
|
||||
|
||||
v5.7.0
|
||||
------
|
||||
|
||||
|
@ -103,6 +103,9 @@ From GitHub user `zacsketches`:
|
||||
[From Twitter user `@hemalchevli`](https://twitter.com/hemalchevli/status/715788439397011456):
|
||||
> ArduinoJson library should be used as a benchmark/reference for making libraries. Truly elegant.
|
||||
|
||||
[From GitHub user `sticilface`](https://github.com/bblanchon/ArduinoJson/issues/381#issuecomment-260203594):
|
||||
> its a great lib:) and i use it in everything!
|
||||
|
||||
Donators
|
||||
--------
|
||||
|
||||
@ -123,6 +126,7 @@ Special thanks to the following persons and companies who made generous donation
|
||||
* Kestutis Liaugminas <img alt='Lithuania' src='https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/svg/1f1f1-1f1f9.svg' width='18' height='18'>
|
||||
* Darlington Adibe <img alt='Nigeria' src='https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/svg/1f1f3-1f1ec.svg' width='18' height='18'>
|
||||
* Yoeri Kroon <img alt='Netherlands' src='https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/svg/1f1f3-1f1f1.svg' width='18' height='18'>
|
||||
* Andrew Melvin <img alt='United Kingdom' src='https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/svg/1f1ec-1f1e7.svg' width='18' height='18'>
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 5.7.0.{build}
|
||||
version: 5.7.2.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- CMAKE_GENERATOR: Visual Studio 14 2015
|
||||
|
51
examples/ProgmemExample/ProgmemExample.ino
Normal file
51
examples/ProgmemExample/ProgmemExample.ino
Normal file
@ -0,0 +1,51 @@
|
||||
// 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.h>
|
||||
|
||||
// About
|
||||
// -----
|
||||
// This example shows the different ways you can use PROGMEM with ArduinoJson.
|
||||
// Please don't see this as an invitation to use PROGMEM.
|
||||
// On the contrary, you should always use char[] when possible, it's much more
|
||||
// efficient in term of code size, speed and memory usage.
|
||||
|
||||
void setup() {
|
||||
#ifdef PROGMEM
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
|
||||
// You can use a Flash String as your JSON input.
|
||||
// WARNING: the content of the Flash String will be duplicated in the
|
||||
// JsonBuffer.
|
||||
JsonObject& root =
|
||||
jsonBuffer.parseObject(F("{\"sensor\":\"gps\",\"time\":1351824120,"
|
||||
"\"data\":[48.756080,2.302038]}"));
|
||||
|
||||
// You can use a Flash String to get an element of a JsonObject
|
||||
// No duplication is done.
|
||||
long time = root[F("time")];
|
||||
|
||||
// You can use a Flash String to set an element of a JsonObject
|
||||
// WARNING: the content of the Flash String will be duplicated in the
|
||||
// JsonBuffer.
|
||||
root[F("time")] = time;
|
||||
|
||||
// You can set a Flash String to a JsonObject or JsonArray:
|
||||
// WARNING: the content of the Flash String will be duplicated in the
|
||||
// JsonBuffer.
|
||||
root["sensor"] = F("gps");
|
||||
|
||||
#else
|
||||
|
||||
#warning PROGMEM is only supported on AVR architecture
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// not used in this example
|
||||
}
|
@ -27,6 +27,15 @@
|
||||
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1
|
||||
#endif
|
||||
|
||||
// On AVR archiecture, we can use PROGMEM
|
||||
#ifndef ARDUINOJSON_ENABLE_PROGMEM
|
||||
#ifdef PROGMEM
|
||||
#define ARDUINOJSON_ENABLE_PROGMEM 1
|
||||
#else
|
||||
#define ARDUINOJSON_ENABLE_PROGMEM 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Arduino doesn't have std::string
|
||||
#ifndef ARDUINOJSON_ENABLE_STD_STRING
|
||||
#define ARDUINOJSON_ENABLE_STD_STRING 0
|
||||
@ -87,6 +96,11 @@
|
||||
#define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
|
||||
#endif
|
||||
|
||||
// PROGMEM is only available on AVR architecture
|
||||
#ifndef ARDUINOJSON_ENABLE_PROGMEM
|
||||
#define ARDUINOJSON_ENABLE_PROGMEM 0
|
||||
#endif
|
||||
|
||||
// on a computer, we can assume that the STL is there
|
||||
#ifndef ARDUINOJSON_ENABLE_STD_STREAM
|
||||
#define ARDUINOJSON_ENABLE_STD_STREAM 1
|
||||
|
@ -44,6 +44,7 @@ struct CharPtrFuncs {
|
||||
}
|
||||
|
||||
static const bool has_append = false;
|
||||
static const bool has_equals = true;
|
||||
static const bool should_duplicate = false;
|
||||
};
|
||||
|
||||
@ -56,6 +57,9 @@ struct StringFuncs<char*> : CharPtrFuncs {};
|
||||
template <size_t N>
|
||||
struct StringFuncs<char[N]> : CharPtrFuncs {};
|
||||
|
||||
template <size_t N>
|
||||
struct StringFuncs<const char[N]> : CharPtrFuncs {};
|
||||
|
||||
template <typename TString>
|
||||
struct StdStringFuncs {
|
||||
template <typename Buffer>
|
||||
@ -76,6 +80,7 @@ struct StdStringFuncs {
|
||||
}
|
||||
|
||||
static const bool has_append = true;
|
||||
static const bool has_equals = true;
|
||||
static const bool should_duplicate = true;
|
||||
};
|
||||
|
||||
@ -90,5 +95,27 @@ struct StringFuncs<StringSumHelper> : StdStringFuncs<StringSumHelper> {};
|
||||
template <>
|
||||
struct StringFuncs<std::string> : StdStringFuncs<std::string> {};
|
||||
#endif
|
||||
|
||||
#if ARDUINOJSON_ENABLE_PROGMEM
|
||||
template <>
|
||||
struct StringFuncs<const __FlashStringHelper*> {
|
||||
static bool equals(const __FlashStringHelper* str, const char* expected) {
|
||||
return strcmp_P(expected, (PGM_P)str) == 0;
|
||||
}
|
||||
|
||||
template <typename Buffer>
|
||||
static char* duplicate(const __FlashStringHelper* str, Buffer* buffer) {
|
||||
if (!str) return NULL;
|
||||
size_t size = strlen_P((PGM_P)str) + 1;
|
||||
void* dup = buffer->alloc(size);
|
||||
if (dup != NULL) memcpy_P(dup, (PGM_P)str, size);
|
||||
return static_cast<char*>(dup);
|
||||
}
|
||||
|
||||
static const bool has_append = false;
|
||||
static const bool has_equals = true;
|
||||
static const bool should_duplicate = true;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -84,13 +84,6 @@ template <typename TString>
|
||||
inline JsonObjectSubscript<TString> JsonObject::operator[](const TString& key) {
|
||||
return JsonObjectSubscript<TString>(*this, key);
|
||||
}
|
||||
|
||||
template <typename TImplem>
|
||||
template <class TString>
|
||||
inline const JsonObjectSubscript<TString> JsonVariantBase<TImplem>::operator[](
|
||||
const TString& key) const {
|
||||
return asObject()[key];
|
||||
}
|
||||
} // namespace ArduinoJson
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
@ -77,8 +77,12 @@ class JsonVariantBase : public Internals::JsonPrintable<TImpl> {
|
||||
// an object.
|
||||
// Return JsonVariant::invalid() if the variant is not an object.
|
||||
template <typename TString>
|
||||
FORCE_INLINE const JsonObjectSubscript<TString> operator[](
|
||||
const TString &key) const;
|
||||
FORCE_INLINE
|
||||
typename TypeTraits::EnableIf<Internals::StringFuncs<TString>::has_equals,
|
||||
const JsonObjectSubscript<TString> >::type
|
||||
operator[](const TString &key) const {
|
||||
return asObject()[key];
|
||||
}
|
||||
|
||||
private:
|
||||
const TImpl *impl() const {
|
||||
|
@ -2,6 +2,7 @@ JsonArray KEYWORD1
|
||||
JsonObject KEYWORD1
|
||||
JsonVariant KEYWORD1
|
||||
StaticJsonBuffer KEYWORD1
|
||||
DynamicJsonBuffer KEYWORD1
|
||||
add KEYWORD2
|
||||
createArray KEYWORD2
|
||||
createNestedArray KEYWORD2
|
||||
|
@ -6,7 +6,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "5.7.0",
|
||||
"version": "5.7.2",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "http://blog.benoitblanchon.fr"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ArduinoJson
|
||||
version=5.7.0
|
||||
version=5.7.2
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=An efficient and elegant JSON library for Arduino.
|
||||
|
@ -1,143 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ArduinoJson - JsonBuffer size calculator</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1>JsonBuffer size calculator</h1>
|
||||
</div>
|
||||
<div id='error' class="alert alert-danger" role="alert">
|
||||
Please paste your JSON in the "input" box
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h2>Input</h2>
|
||||
<textarea class="form-control" rows=30 id='input'></textarea><br>
|
||||
</div>
|
||||
<div id='results' class="col-md-6" style='display:none'>
|
||||
<h2>Result</h2>
|
||||
<h3>Expression</h3>
|
||||
<p><code id='resultexpr'></code></p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<th>Platform</th>
|
||||
<th>Size (in bytes)</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>AVR 8-bit</td>
|
||||
<td id='sizeavr8'></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ESP8266</td>
|
||||
<td id='sizeesp8266'></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>x86</td>
|
||||
<td id='sizex86'></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>x64</td>
|
||||
<td id='sizex64'></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript">
|
||||
function Recipe() {
|
||||
var arrays = [];
|
||||
var objects = [];
|
||||
|
||||
this.addJsonArray = function(size) {
|
||||
if (arrays[size])
|
||||
arrays[size]++;
|
||||
else
|
||||
arrays[size] = 1;
|
||||
}
|
||||
|
||||
this.addJsonObject = function(size) {
|
||||
if (objects[size])
|
||||
objects[size]++;
|
||||
else
|
||||
objects[size] = 1;
|
||||
}
|
||||
|
||||
this.getExpression = function() {
|
||||
var elements = [];
|
||||
for (var size in arrays) {
|
||||
var count = arrays[size];
|
||||
if (count > 1)
|
||||
elements.push(count + "*JSON_ARRAY_SIZE("+size+")");
|
||||
else
|
||||
elements.push("JSON_ARRAY_SIZE("+size+")");
|
||||
}
|
||||
for (var size in objects) {
|
||||
var count = objects[size];
|
||||
if (count > 1)
|
||||
elements.push(count + "*JSON_OBJECT_SIZE("+size+")");
|
||||
else
|
||||
elements.push("JSON_OBJECT_SIZE("+size+")");
|
||||
}
|
||||
return elements.join(" + ");
|
||||
}
|
||||
}
|
||||
|
||||
function scanJson(recipe, obj) {
|
||||
if (obj instanceof Array) {
|
||||
recipe.addJsonArray(obj.length);
|
||||
for (var i = 0; i<obj.length; i++)
|
||||
scanJson(recipe, obj[i]);
|
||||
}
|
||||
else if (obj instanceof Object) {
|
||||
recipe.addJsonObject(Object.keys(obj).length);
|
||||
for (var key in obj)
|
||||
scanJson(recipe, obj[key]);
|
||||
}
|
||||
}
|
||||
|
||||
input.oninput = function(e) {
|
||||
results.style.display = 'none';
|
||||
error.style.visibility = 'hidden';
|
||||
|
||||
try {
|
||||
var recipe = new Recipe();
|
||||
scanJson(recipe, JSON.parse(input.value));
|
||||
var expression = recipe.getExpression();
|
||||
|
||||
resultexpr.innerText = expression;
|
||||
sizeavr8.innerText = eval(
|
||||
"function JSON_ARRAY_SIZE(n) { return 4 + 8*n }" +
|
||||
"function JSON_OBJECT_SIZE(n) { return 4 + 10*n }" +
|
||||
expression
|
||||
);
|
||||
sizeesp8266.innerText = eval(
|
||||
"function JSON_ARRAY_SIZE(n) { return 8 + 12*n }" +
|
||||
"function JSON_OBJECT_SIZE(n) { return 8 + 16*n }" +
|
||||
expression
|
||||
);
|
||||
sizex86.innerText = eval(
|
||||
"function JSON_ARRAY_SIZE(n) { return 12 + 24*n }" +
|
||||
"function JSON_OBJECT_SIZE(n) { return 12 + 32*n }" +
|
||||
expression
|
||||
);
|
||||
sizex64.innerText = eval(
|
||||
"function JSON_ARRAY_SIZE(n) { return 24 + 24*n }" +
|
||||
"function JSON_OBJECT_SIZE(n) { return 24 + 32*n }" +
|
||||
expression
|
||||
);
|
||||
results.style.display = 'block';
|
||||
}
|
||||
catch (ex) {
|
||||
error.innerText = "ERROR: " + ex.message;
|
||||
error.style.visibility = 'visible';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</html>
|
@ -5,8 +5,8 @@
|
||||
// https://github.com/bblanchon/ArduinoJson
|
||||
// If you like this project, please add a star!
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
class JsonVariant_Subscript_Tests : public ::testing::Test {
|
||||
protected:
|
||||
@ -24,6 +24,9 @@ TEST_F(JsonVariant_Subscript_Tests, Array) {
|
||||
EXPECT_EQ(2, _variant.size());
|
||||
EXPECT_STREQ("element at index 0", _variant[0].asString());
|
||||
EXPECT_STREQ("element at index 1", _variant[1].asString());
|
||||
EXPECT_STREQ(
|
||||
"element at index 0",
|
||||
_variant[static_cast<unsigned char>(0)].asString()); // issue #381
|
||||
EXPECT_FALSE(_variant[-1].success());
|
||||
EXPECT_FALSE(_variant[3].success());
|
||||
EXPECT_FALSE(_variant["0"].success());
|
||||
|
Reference in New Issue
Block a user