mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-02 21:31:00 +02:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
6757f35a3a | |||
ffb9b6d1ba | |||
e401498e4a | |||
d30e940b3b | |||
05ea5e04c8 | |||
a7ef99d0fe | |||
f2a8b52c2c | |||
409ca7ee4e |
5
.mbedignore
Normal file
5
.mbedignore
Normal file
@ -0,0 +1,5 @@
|
||||
.github/
|
||||
examples/
|
||||
scripts/
|
||||
test/
|
||||
third-party/
|
@ -1,6 +1,13 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v5.6.6
|
||||
------
|
||||
|
||||
* Fixed `-Wparentheses` warning introduced in v5.6.5 (PR #335 by @nuket)
|
||||
* Added `.mbedignore` for ARM mbdeb (PR #334 by @nuket)
|
||||
* Fixed `JsonVariant::success()` which didn't propagate `JsonArray::success()` nor `JsonObject::success()` (issue #342).
|
||||
|
||||
v5.6.5
|
||||
------
|
||||
|
||||
|
@ -86,9 +86,6 @@ From Arduino's Forum user `jflaplante`:
|
||||
> I tried aJson json-arduino before trying your library. I always ran into memory problem after a while.
|
||||
> I have no such problem so far with your library. It is working perfectly with my web services.
|
||||
|
||||
From Arduino's Forum user `gbathree`:
|
||||
> Thanks so much - this is an awesome library! If you want to see what we're doing with it - the project is located at www.photosynq.org.
|
||||
|
||||
From StackOverflow user `thegreendroid`:
|
||||
> It has a really elegant, simple API and it works like a charm on embedded and Windows/Linux platforms. We recently started using this on an embedded project and I can vouch for its quality.
|
||||
|
||||
@ -124,6 +121,7 @@ Special thanks to the following persons and companies who made generous donation
|
||||
* Nick Koumaris <img alt='Greece' src='https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/svg/1f1ec-1f1f7.svg' width='18' height='18'>
|
||||
* Jon Williams <img alt='USA' src='https://cdnjs.cloudflare.com/ajax/libs/emojione/2.1.4/assets/svg/1f1fa-1f1f8.svg' width='18' height='18'>
|
||||
* 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'>
|
||||
|
||||
---
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 5.6.5.{build}
|
||||
version: 5.6.6.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- CMAKE_GENERATOR: Visual Studio 14 2015
|
||||
|
@ -8,11 +8,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "JsonArray.hpp"
|
||||
#include "JsonObject.hpp"
|
||||
#include "JsonArraySubscript.hpp"
|
||||
#include "JsonObject.hpp"
|
||||
|
||||
namespace ArduinoJson {
|
||||
|
||||
inline JsonVariant::JsonVariant(JsonArray &array) {
|
||||
if (array.success()) {
|
||||
_type = Internals::JSON_ARRAY;
|
||||
_content.asArray = &array;
|
||||
} else {
|
||||
_type = Internals::JSON_UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
inline JsonVariant::JsonVariant(JsonObject &object) {
|
||||
if (object.success()) {
|
||||
_type = Internals::JSON_OBJECT;
|
||||
_content.asObject = &object;
|
||||
} else {
|
||||
_type = Internals::JSON_UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool JsonArray::setNodeValue(node_type *node, String &value) {
|
||||
const char *copy = _buffer->strdup(value);
|
||||
|
@ -107,16 +107,10 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
|
||||
}
|
||||
|
||||
// Create a JsonVariant containing a reference to an array.
|
||||
JsonVariant(JsonArray &array) {
|
||||
_type = Internals::JSON_ARRAY;
|
||||
_content.asArray = &array;
|
||||
}
|
||||
JsonVariant(JsonArray &array);
|
||||
|
||||
// Create a JsonVariant containing a reference to an object.
|
||||
JsonVariant(JsonObject &object) {
|
||||
_type = Internals::JSON_OBJECT;
|
||||
_content.asObject = &object;
|
||||
}
|
||||
JsonVariant(JsonObject &object);
|
||||
|
||||
// Get the variant as the specified type.
|
||||
//
|
||||
@ -330,8 +324,8 @@ class JsonVariant : public JsonVariantBase<JsonVariant> {
|
||||
}
|
||||
bool isString() const {
|
||||
return _type == Internals::JSON_STRING ||
|
||||
_type == Internals::JSON_UNPARSED && _content.asString &&
|
||||
!strcmp("null", _content.asString);
|
||||
(_type == Internals::JSON_UNPARSED && _content.asString &&
|
||||
!strcmp("null", _content.asString));
|
||||
}
|
||||
|
||||
// The current type of the variant
|
||||
|
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "Json",
|
||||
"name": "ArduinoJson",
|
||||
"keywords": "json, rest, http, web",
|
||||
"description": "An elegant and efficient JSON library for embedded systems",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/bblanchon/ArduinoJson.git"
|
||||
},
|
||||
"version": "5.6.5",
|
||||
"version": "5.6.6",
|
||||
"authors": {
|
||||
"name": "Benoit Blanchon",
|
||||
"url": "http://blog.benoitblanchon.fr"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ArduinoJson
|
||||
version=5.6.5
|
||||
version=5.6.6
|
||||
author=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
|
||||
sentence=An efficient and elegant JSON library for Arduino.
|
||||
|
108
scripts/buffer-size-calculator.html
Normal file
108
scripts/buffer-size-calculator.html
Normal file
@ -0,0 +1,108 @@
|
||||
<!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 getExpression(obj) {
|
||||
var elements = [];
|
||||
if (obj instanceof Array) {
|
||||
elements.push("JSON_ARRAY_SIZE(" + obj.length + ")");
|
||||
for (var i = 0; i<obj.length; i++) {
|
||||
elements.push(getExpression(obj[i]))
|
||||
}
|
||||
}
|
||||
else if (obj instanceof Object) {
|
||||
elements.push("JSON_OBJECT_SIZE(" + Object.keys(obj).length + ")");
|
||||
for (var key in obj) {
|
||||
elements.push(getExpression(obj[key]))
|
||||
}
|
||||
}
|
||||
return elements.filter(function(x){return x.length > 0}).join(" + ");
|
||||
}
|
||||
|
||||
input.oninput = function(e) {
|
||||
results.style.display = 'none';
|
||||
error.style.visibility = 'hidden';
|
||||
|
||||
try {
|
||||
var obj = JSON.parse(input.value);
|
||||
var expression = getExpression(obj);
|
||||
|
||||
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>
|
@ -1,6 +1,6 @@
|
||||
# Copyright Benoit Blanchon 2014-2016
|
||||
# MIT License
|
||||
#
|
||||
#
|
||||
# Arduino JSON library
|
||||
# https://github.com/bblanchon/ArduinoJson
|
||||
# If you like this project, please add a star!
|
||||
@ -25,7 +25,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
-Wformat=2
|
||||
-Winit-self
|
||||
-Wmissing-include-dirs
|
||||
-Wno-parentheses
|
||||
-Wparentheses
|
||||
-Wno-sign-conversion
|
||||
-Wno-unused
|
||||
-Wno-variadic-macros
|
||||
|
@ -34,26 +34,33 @@ void assertIs(JsonArray& value) {
|
||||
ASSERT_TRUE(variant.is<TTo>());
|
||||
}
|
||||
|
||||
TEST(SUITE, ArrayIsArry) {
|
||||
assertIs<JsonArray&>(JsonArray::invalid());
|
||||
TEST(SUITE, ArrayIsArray) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
assertIs<JsonArray&>(jsonBuffer.createArray());
|
||||
}
|
||||
TEST(SUITE, ArrayIsBool) {
|
||||
assertIsNot<bool>(JsonArray::invalid());
|
||||
TEST(SUITE, ArrayIsNotBool) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
assertIsNot<bool>(jsonBuffer.createArray());
|
||||
}
|
||||
TEST(SUITE, ArrayIsDouble) {
|
||||
assertIsNot<double>(JsonArray::invalid());
|
||||
TEST(SUITE, ArrayIsNotDouble) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
assertIsNot<double>(jsonBuffer.createArray());
|
||||
}
|
||||
TEST(SUITE, ArrayIsFloat) {
|
||||
assertIsNot<float>(JsonArray::invalid());
|
||||
TEST(SUITE, ArrayIsNotFloat) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
assertIsNot<float>(jsonBuffer.createArray());
|
||||
}
|
||||
TEST(SUITE, ArrayIsInt) {
|
||||
assertIsNot<int>(JsonArray::invalid());
|
||||
TEST(SUITE, ArrayIsNotInt) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
assertIsNot<int>(jsonBuffer.createArray());
|
||||
}
|
||||
TEST(SUITE, ArrayIsLong) {
|
||||
assertIsNot<long>(JsonArray::invalid());
|
||||
TEST(SUITE, ArrayIsNotLong) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
assertIsNot<long>(jsonBuffer.createArray());
|
||||
}
|
||||
TEST(SUITE, ArrayIsString) {
|
||||
assertIsNot<const char*>(JsonArray::invalid());
|
||||
TEST(SUITE, ArrayIsNotString) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
assertIsNot<const char*>(jsonBuffer.createArray());
|
||||
}
|
||||
|
||||
TEST(SUITE, BoolIsArray) {
|
||||
|
43
test/JsonVariant_Success_Tests.cpp
Normal file
43
test/JsonVariant_Success_Tests.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// 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>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(JsonVariant_Success_Tests, ReturnsFalse_WhenUndefined) {
|
||||
JsonVariant variant;
|
||||
EXPECT_FALSE(variant.success());
|
||||
}
|
||||
|
||||
TEST(JsonVariant_Success_Tests, ReturnsTrue_WhenInteger) {
|
||||
JsonVariant variant = 0;
|
||||
EXPECT_TRUE(variant.success());
|
||||
}
|
||||
|
||||
TEST(JsonVariant_Success_Tests, ReturnsTrue_WhenEmptyArray) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
|
||||
JsonVariant variant = jsonBuffer.createArray();
|
||||
EXPECT_TRUE(variant.success());
|
||||
}
|
||||
|
||||
TEST(JsonVariant_Success_Tests, ReturnsTrue_WhenEmptyObject) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
|
||||
JsonVariant variant = jsonBuffer.createObject();
|
||||
EXPECT_TRUE(variant.success());
|
||||
}
|
||||
|
||||
TEST(JsonVariant_Success_Tests, ReturnsFalse_WhenInvalidArray) {
|
||||
JsonVariant variant = JsonArray::invalid();
|
||||
EXPECT_FALSE(variant.success());
|
||||
}
|
||||
|
||||
TEST(JsonVariant_Success_Tests, ReturnsFalse_WhenInvalidObject) {
|
||||
JsonVariant variant = JsonObject::invalid();
|
||||
EXPECT_FALSE(variant.success());
|
||||
}
|
Reference in New Issue
Block a user