Compare commits

...

11 Commits

15 changed files with 76 additions and 84 deletions

View File

@ -1,17 +1,20 @@
sudo: false
language: c++
compiler:
- gcc
- clang
before_install:
- pip install --user cpp-coveralls
- mkdir -p /tmp/cmake
- curl https://cmake.org/files/v3.4/cmake-3.4.0-Linux-x86_64.tar.gz | tar xz -C /tmp/cmake --strip 1
- export PATH=/tmp/cmake/bin:$PATH
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
- sleep 3
- export DISPLAY=:1.0
- wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
- tar xf arduino-1.6.5-linux64.tar.xz
- sudo mv arduino-1.6.5 /usr/local/share/arduino
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
- sudo ln -s $PWD /usr/local/share/arduino/libraries/ArduinoJson
- sudo pip install cpp-coveralls
- mkdir -p /tmp/arduino
- curl http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz | tar xJ -C /tmp/arduino --strip 1
- export PATH=$PATH:/tmp/arduino/
- ln -s $PWD /tmp/arduino/libraries/ArduinoJson
script:
- cmake -DCOVERAGE=true . && make && make test
- arduino --verify --board arduino:avr:uno $PWD/examples/JsonParserExample/JsonParserExample.ino

View File

@ -1,10 +1,27 @@
ArduinoJson: change log
=======================
v5.0.7
------
* Made library easier to use from a CMake project: simply `add_subdirectory(ArduinoJson/src)`
* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161)
**BREAKING CHANGES**:
- `JsonVariant(true).as<String>()` now returns `"true"` instead of `"1"`
- `JsonVariant(false).as<String>()` now returns `"false"` instead of `"0"`
v5.0.6
------
* Added parameter to `DynamicJsonBuffer` constructor to set initial size (issue #152)
* Fixed warning about library category in Arduino 1.6.6 (issue #147)
* Examples: Added a loop to wait for serial port to be ready (issue #156)
v5.0.5
------
* Add overload `JsonObjectSuscript::set(value, decimals)` (issue #143)
* Added overload `JsonObjectSuscript::set(value, decimals)` (issue #143)
* Use `float` instead of `double` to reduce the size of `JsonVariant` (issue #134)
v5.0.4

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.4)
cmake_minimum_required(VERSION 2.8.12)
project(ArduinoJson)
enable_testing()
@ -7,10 +7,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS -W4)
endif()
if(${COVERAGE})
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
endif()

View File

@ -98,6 +98,18 @@ From GitHub user `zacsketches`:
> I am just starting an ESP8266 clock project and now I can output JSON from my server script and interpret it painlessly.
Donators
--------
Special thanks to the following persons and companies who made generous donations to the library author:
* Robert Murphy
* Surge Communications
* Alex Scott
* Firepick Services LLC
* A B Doodkorte
* Scott Smith
---
Found this library useful? Please star this project or [help me back with a donation!](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donate%40benoitblanchon%2efr&lc=GB&item_name=Benoit%20Blanchon&item_number=Arduino%20JSON&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted) :smile:

View File

@ -10,7 +10,9 @@ using namespace ArduinoJson::Internals;
void setup() {
Serial.begin(9600);
// delay(1000); <--needed for some boards (like Teensy)
while (!Serial) {
// wait serial port initialization
}
IndentedPrint serial(Serial);
serial.setTabSize(4);

View File

@ -8,7 +8,9 @@
void setup() {
Serial.begin(9600);
// delay(1000); <--needed for some boards (like Teensy)
while (!Serial) {
// wait serial port initialization
}
StaticJsonBuffer<200> jsonBuffer;

View File

@ -8,7 +8,9 @@
void setup() {
Serial.begin(9600);
// delay(1000); <--needed for some boards (like Teensy)
while (!Serial) {
// wait serial port initialization
}
StaticJsonBuffer<200> jsonBuffer;

View File

@ -9,16 +9,7 @@
#ifndef ARDUINO
#include <string>
// This class reproduces Arduino's String class
class String : public std::string {
public:
String(const char *cstr = "") : std::string(cstr) {}
String(const String &str) : std::string(str) {}
explicit String(long);
explicit String(int);
explicit String(double, unsigned char decimalPlaces = 2);
};
typedef std::string String;
#else

View File

@ -31,7 +31,8 @@ class BlockJsonBuffer : public JsonBuffer {
};
public:
BlockJsonBuffer() : _head(NULL) {}
BlockJsonBuffer(size_t initialSize = 256)
: _head(NULL), _nextBlockSize(initialSize) {}
~BlockJsonBuffer() {
Block* currentBlock = _head;
@ -55,8 +56,6 @@ class BlockJsonBuffer : public JsonBuffer {
}
private:
static const size_t FIRST_BLOCK_CAPACITY = 32;
bool canAllocInHead(size_t bytes) const {
return _head != NULL && _head->size + bytes <= _head->capacity;
}
@ -68,10 +67,10 @@ class BlockJsonBuffer : public JsonBuffer {
}
void* allocInNewBlock(size_t bytes) {
size_t capacity = FIRST_BLOCK_CAPACITY;
if (_head != NULL) capacity = _head->capacity * 2;
size_t capacity = _nextBlockSize;
if (bytes > capacity) capacity = bytes;
if (!addNewBlock(capacity)) return NULL;
_nextBlockSize *= 2;
return allocInHead(bytes);
}
@ -86,8 +85,9 @@ class BlockJsonBuffer : public JsonBuffer {
return true;
}
Block* _head;
TAllocator _allocator;
Block* _head;
size_t _nextBlockSize;
};
}
}

View File

@ -1,8 +1,9 @@
name=ArduinoJson
version=5.0.5
version=5.0.7
author=Benoit Blanchon <blog.benoitblanchon.fr>
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
sentence=An efficient and elegant JSON library for Arduino.
paragraph=Like this project? Please star it on GitHub!
category=Data Processing
url=https://github.com/bblanchon/ArduinoJson
architectures=*

View File

@ -1,31 +0,0 @@
// Copyright Benoit Blanchon 2014-2015
// MIT License
//
// Arduino JSON library
// https://github.com/bblanchon/ArduinoJson
#ifndef ARDUINO
#include "../../include/ArduinoJson/Arduino/String.hpp"
#include <stdio.h> // for sprintf()
String::String(double value, unsigned char digits) {
char tmp[32];
sprintf(tmp, "%.*f", digits, value);
*this = tmp;
}
String::String(long value) {
char tmp[32];
sprintf(tmp, "%ld", value);
*this = tmp;
}
String::String(int value) {
char tmp[32];
sprintf(tmp, "%d", value);
*this = tmp;
}
#endif

View File

@ -48,4 +48,12 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
)
endif()
if(MSVC)
add_definitions(
-D_CRT_SECURE_NO_WARNINGS
-W4)
endif()
add_library(ArduinoJson ${CPP_FILES} ${HPP_FILES} ${IPP_FILES})
target_include_directories(ArduinoJson INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../include)

View File

@ -20,22 +20,22 @@ template <typename TFloat>
static TFloat parse(const char *);
template <>
FORCE_INLINE float parse<float>(const char *s) {
float parse<float>(const char *s) {
return static_cast<float>(strtod(s, NULL));
}
template <>
FORCE_INLINE double parse<double>(const char *s) {
double parse<double>(const char *s) {
return strtod(s, NULL);
}
template <>
FORCE_INLINE long parse<long>(const char *s) {
long parse<long>(const char *s) {
return strtol(s, NULL, 10);
}
template <>
FORCE_INLINE int parse<int>(const char *s) {
int parse<int>(const char *s) {
return atoi(s);
}
@ -76,20 +76,12 @@ JsonInteger JsonVariant::asInteger() const {
template <>
String JsonVariant::as<String>() const {
String s;
if ((_type == JSON_STRING || _type == JSON_UNPARSED) &&
_content.asString != NULL)
return String(_content.asString);
if (_type == JSON_INTEGER || _type == JSON_BOOLEAN)
return String(_content.asInteger);
if (_type >= JSON_FLOAT_0_DECIMALS) {
uint8_t decimals = static_cast<uint8_t>(_type - JSON_FLOAT_0_DECIMALS);
return String(_content.asFloat, decimals);
}
String s;
printTo(s);
s = _content.asString;
else
printTo(s);
return s;
}

View File

@ -1,10 +1,8 @@
set(GTEST_DIR ../third-party/gtest-1.7.0)
file(GLOB_RECURSE INC_FILES ../include/*.h)
file(GLOB TESTS_FILES *.hpp *.cpp)
include_directories(
../include
${GTEST_DIR}
${GTEST_DIR}/include)
@ -17,7 +15,6 @@ endif()
add_executable(ArduinoJsonTests
${TESTS_FILES}
${INC_FILES}
${GTEST_DIR}/src/gtest-all.cc
${GTEST_DIR}/src/gtest_main.cc)

View File

@ -57,7 +57,7 @@ TEST(JsonVariant_As_Tests, FalseAsLong) {
TEST(JsonVariant_As_Tests, FalseAsString) {
JsonVariant variant = false;
ASSERT_EQ(String("0"), variant.as<String>());
ASSERT_EQ(String("false"), variant.as<String>());
}
TEST(JsonVariant_As_Tests, TrueAsBool) {
@ -77,7 +77,7 @@ TEST(JsonVariant_As_Tests, TrueAsLong) {
TEST(JsonVariant_As_Tests, TrueAsString) {
JsonVariant variant = true;
ASSERT_EQ(String("1"), variant.as<String>());
ASSERT_EQ(String("true"), variant.as<String>());
}
TEST(JsonVariant_As_Tests, LongAsBool) {