diff --git a/scripts/publish.sh b/scripts/publish.sh index 56695f93..a9d95db1 100644 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -47,3 +47,7 @@ update_version_in_source commit_new_version add_tag push + +scripts/build-arduino-package.sh +scripts/build-single-header.sh +scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" diff --git a/scripts/wandbox/JsonGeneratorExample.cpp b/scripts/wandbox/JsonGeneratorExample.cpp new file mode 100644 index 00000000..75b4022d --- /dev/null +++ b/scripts/wandbox/JsonGeneratorExample.cpp @@ -0,0 +1,57 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License +// +// This example shows how to generate a JSON document with ArduinoJson. + +#include +#include "ArduinoJson.h" + +int main() { + // The JSON document + // + // Inside the brackets, 200 is the RAM allocated to this document. + // Don't forget to change this value to match your requirement. + // Use arduinojson.org/assistant to compute the capacity. + StaticJsonDocument<200> doc; + + // StaticJsonObject allocates memory on the stack, it can be + // replaced by DynamicJsonDocument which allocates in the heap. + // + // DynamicJsonDocument doc(200); + + // Make our document be an object + JsonObject root = doc.to(); + + // Add values in the object + // + // Most of the time, you can rely on the implicit casts. + // In other case, you can do root.set("time", 1351824120); + root["sensor"] = "gps"; + root["time"] = 1351824120; + + // Add an array. + // + JsonArray data = root.createNestedArray("data"); + data.add(48.756080); + data.add(2.302038); + + serializeJson(root, std::cout); + // This prints: + // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} + + std::cout << std::endl; + + serializeJsonPretty(root, std::cout); + // This prints: + // { + // "sensor": "gps", + // "time": 1351824120, + // "data": [ + // 48.756080, + // 2.302038 + // ] + // } + + return 0; +} diff --git a/scripts/wandbox/JsonParserExample.cpp b/scripts/wandbox/JsonParserExample.cpp new file mode 100644 index 00000000..93ad3426 --- /dev/null +++ b/scripts/wandbox/JsonParserExample.cpp @@ -0,0 +1,59 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License +// +// This example shows how to deserialize a JSON document with ArduinoJson. + +#include +#include "ArduinoJson.h" + +int main() { + // Root JSON object + // + // Inside the brackets, 300 is the size of the memory pool in bytes. + // Don't forget to change this value to match your JSON document. + // Use arduinojson.org/assistant to compute the capacity. + StaticJsonDocument<300> doc; + + // StaticJsonDocument allocates memory on the stack, it can be + // replaced by DynamicJsonObject which allocates in the heap. + // + // DynamicJsonObject doc(200); + + // JSON input string. + // + // It's better to use a char[] as shown here. + // If you use a const char* or a String, ArduinoJson will + // have to make a copy of the input in the JsonBuffer. + char json[] = + "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; + + // Deserialize the JSON document + DeserializationError error = deserializeJson(doc, json); + + // Test if parsing succeeds. + if (error) { + std::cerr << "deserializeJson() failed: " << error.c_str() << std::endl; + return 1; + } + + // Get the root object in the document + JsonObject root = doc.as(); + + // Fetch values. + // + // Most of the time, you can rely on the implicit casts. + // In other case, you can do doc["time"].as(); + const char* sensor = root["sensor"]; + long time = root["time"]; + double latitude = root["data"][0]; + double longitude = root["data"][1]; + + // Print values. + std::cout << sensor << std::endl; + std::cout << time << std::endl; + std::cout << latitude << std::endl; + std::cout << longitude << std::endl; + + return 0; +} diff --git a/scripts/wandbox/MsgPackParserExample.cpp b/scripts/wandbox/MsgPackParserExample.cpp new file mode 100644 index 00000000..47c2d879 --- /dev/null +++ b/scripts/wandbox/MsgPackParserExample.cpp @@ -0,0 +1,71 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License +// +// This example shows how to generate a JSON document with ArduinoJson. + +#include +#include "ArduinoJson.h" + +int main() { + // Allocate the JSON document + // + // Inside the brackets, 300 is the size of the memory pool in bytes. + // Don't forget to change this value to match your JSON document. + // Use arduinojson.org/assistant to compute the capacity. + StaticJsonDocument<300> doc; + + // StaticJsonObject allocates memory on the stack, it can be + // replaced by DynamicJsonObject which allocates in the heap. + // + // DynamicJsonObject doc(200); + + // MessagePack input string. + // + // It's better to use a char[] as shown here. + // If you use a const char* or a String, ArduinoJson will + // have to make a copy of the input in the JsonBuffer. + uint8_t input[] = {131, 166, 115, 101, 110, 115, 111, 114, 163, 103, 112, 115, + 164, 116, 105, 109, 101, 206, 80, 147, 50, 248, 164, 100, + 97, 116, 97, 146, 203, 64, 72, 96, 199, 58, 188, 148, + 112, 203, 64, 2, 106, 146, 230, 33, 49, 169}; + // This MessagePack document contains: + // { + // "sensor": "gps", + // "time": 1351824120, + // "data": [48.75608, 2.302038] + // } + + // doc of the object tree. + // + // It's a reference to the JsonObject, the actual bytes are inside the + // JsonBuffer with all the other nodes of the object tree. + // Memory is freed when jsonBuffer goes out of scope. + DeserializationError error = deserializeMsgPack(doc, input); + + // Test if parsing succeeds. + if (error) { + std::cerr << "deserializeMsgPack() failed: " << error.c_str() << std::endl; + return 1; + } + + // Get the root object in the document + JsonObject root = doc.as(); + + // Fetch values. + // + // Most of the time, you can rely on the implicit casts. + // In other case, you can do doc["time"].as(); + const char* sensor = root["sensor"]; + long time = root["time"]; + double latitude = root["data"][0]; + double longitude = root["data"][1]; + + // Print values. + std::cout << sensor << std::endl; + std::cout << time << std::endl; + std::cout << latitude << std::endl; + std::cout << longitude << std::endl; + + return 0; +} diff --git a/scripts/wandbox/publish.sh b/scripts/wandbox/publish.sh new file mode 100644 index 00000000..87067903 --- /dev/null +++ b/scripts/wandbox/publish.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -eu + +ARDUINOJSON_H="$1" + +read_string() { + jq --slurp --raw-input '.' "$1" +} + +compile() { + FILE_PATH="$(dirname $0)/$1.cpp" + cat >parameters.json <