8000 Added StaticJsonArray · sarfata/ArduinoJson@af42239 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit af42239

Browse files
committed
Added StaticJsonArray
1 parent 2e39328 commit af42239

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

src/ArduinoJson.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "ArduinoJson/JsonArray.hpp"
1212
#include "ArduinoJson/JsonObject.hpp"
1313
#include "ArduinoJson/JsonVariantComparisons.hpp"
14+
#include "ArduinoJson/StaticJsonArray.hpp"
1415
#include "ArduinoJson/StaticJsonBuffer.hpp"
1516
#include "ArduinoJson/parseJson.hpp"
1617

src/ArduinoJson/StaticJsonArray.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 "StaticJsonBuffer.hpp"
11+
12+
namespace ArduinoJson {
13+
14+
template <size_t CAPACITY>
15+
class StaticJsonArray : public JsonArray {
16+
StaticJsonBuffer<CAPACITY> _buffer;
17+
18+
public:
19+
StaticJsonArray() : JsonArray(&_buffer) {
20+
// TODO: remove !!!!!!
21+
// it's just here to make the old test suite pass
22+
_buffer.alloc(sizeof(JsonArray));
23+
}
24+
25+
StaticJsonBufferBase& buffer() {
26+
return _buffer;
27+
}
28+
};
29+
}

test/StaticJsonBuffer/parseArray.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,38 @@
99
#include <catch.hpp>
1010

1111
TEST_CASE("StaticJsonBuffer::parseArray()") {
12-
SECTION("StaticJsonBuffer of the right size of 0 elements& 10000 quot;) {
13-
StaticJsonBuffer<JSON_ARRAY_SIZE(0)> jb;
14-
JsonArray& arr = jb.createArray();
12+
SECTION("StaticJsonArray of the right size of 0 elements") {
13+
StaticJsonArray<JSON_ARRAY_SIZE(0)> arr;
1514
char input[] = "[]";
1615
REQUIRE(true == parseJson(arr, input));
1716
}
1817

19-
SECTION("StaticJsonBuffer too small for 1 element") {
20-
StaticJsonBuffer<JSON_ARRAY_SIZE(1) - 1> jb;
21-
JsonArray& arr = jb.createArray();
18+
SECTION("StaticJsonArray too small for 1 element") {
19+
StaticJsonArray<JSON_ARRAY_SIZE(1) - 1> arr;
2220
char input[] = "[1]";
2321
REQUIRE(false == parseJson(arr, input));
2422
}
2523

26-
SECTION("StaticJsonBuffer of the right size of 1 element") {
27-
StaticJsonBuffer<JSON_ARRAY_SIZE(1)> jb;
28-
JsonArray& arr = jb.createArray();
24+
SECTION("StaticJsonArray of the right size of 1 element") {
25+
StaticJsonArray<JSON_ARRAY_SIZE(1)> arr;
2926
char input[] = "[1]";
3027
REQUIRE(true == parseJson(arr, input));
3128
}
3229

33-
SECTION("StaticJsonBuffer too small for 1 nested object") {
34-
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0) - 1> jb;
35-
JsonArray& arr = jb.createArray();
30+
SECTION("StaticJsonArray too small for 1 nested object") {
31+
StaticJsonArray<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0) - 1> arr;
3632
char input[] = "[{}]";
3733
REQUIRE(false == parseJson(arr, input));
3834
}
3935

40-
SECTION("StaticJsonBuffer of the right size of 1 nested object") {
41-
StaticJsonBuffer<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0)> jb;
42-
JsonArray& arr = jb.createArray();
36+
SECTION("StaticJsonArray of the right size of 1 nested object") {
37+
StaticJsonArray<JSON_ARRAY_SIZE(1) + JSON_OBJECT_SIZE(0)> arr;
4338
char input[] = "[{}]";
4439
REQUIRE(true == parseJson(arr, input));
4540
}
4641

4742
SECTION("Input is char* NULL") {
48-
StaticJsonBuffer<100> jb;
49-
JsonArray& arr = jb.createArray();
43+
StaticJsonArray<100> arr;
5044
REQUIRE(false == parseJson(arr, static_cast<char*>(0)));
5145
}
5246

0 commit comments

Comments
 (0)
0