Coverage Report

Created: 2026-01-17 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/arduinojson/src/ArduinoJson/compatibility.hpp
Line
Count
Source
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2025, Benoit BLANCHON
3
// MIT License
4
//
5
// clang-format off
6
7
#include <ArduinoJson/Namespace.hpp>
8
9
#ifdef ARDUINOJSON_SLOT_OFFSET_SIZE
10
#error ARDUINOJSON_SLOT_OFFSET_SIZE has been removed, use ARDUINOJSON_SLOT_ID_SIZE instead
11
#endif
12
13
#ifdef ARDUINOJSON_ENABLE_STRING_DEDUPLICATION
14
#warning "ARDUINOJSON_ENABLE_STRING_DEDUPLICATION has been removed, string deduplication is now always enabled"
15
#endif
16
17
#ifdef __GNUC__
18
19
#define ARDUINOJSON_PRAGMA(x) _Pragma(#x)
20
21
#define ARDUINOJSON_COMPILE_ERROR(msg) ARDUINOJSON_PRAGMA(GCC error msg)
22
23
#define ARDUINOJSON_STRINGIFY(S) #S
24
25
#define ARDUINOJSON_DEPRECATION_ERROR(X, Y) \
26
  ARDUINOJSON_COMPILE_ERROR(ARDUINOJSON_STRINGIFY(X is a Y from ArduinoJson 5. Please see https:/\/arduinojson.org/v7/upgrade-from-v5/ to learn how to upgrade to ArduinoJson 7))
27
28
#define StaticJsonBuffer ARDUINOJSON_DEPRECATION_ERROR(StaticJsonBuffer, class)
29
#define DynamicJsonBuffer ARDUINOJSON_DEPRECATION_ERROR(DynamicJsonBuffer, class)
30
#define JsonBuffer ARDUINOJSON_DEPRECATION_ERROR(JsonBuffer, class)
31
#define RawJson ARDUINOJSON_DEPRECATION_ERROR(RawJson, function)
32
33
#define ARDUINOJSON_NAMESPACE _Pragma ("GCC warning \"ARDUINOJSON_NAMESPACE is deprecated, use ArduinoJson instead\"") ArduinoJson
34
35
// DEPRECATED: you don't need to compute the size anymore
36
#define JSON_ARRAY_SIZE(N) _Pragma ("GCC warning \"JSON_ARRAY_SIZE is deprecated, you don't need to compute the size anymore\"") (ArduinoJson::detail::sizeofArray(N))
37
38
// DEPRECATED: you don't need to compute the size anymore
39
#define JSON_OBJECT_SIZE(N) _Pragma ("GCC warning \"JSON_OBJECT_SIZE is deprecated, you don't need to compute the size anymore\"") (ArduinoJson::detail::sizeofObject(N))
40
41
// DEPRECATED: you don't need to compute the size anymore
42
#define JSON_STRING_SIZE(N) _Pragma ("GCC warning \"JSON_STRING_SIZE is deprecated, you don't need to compute the size anymore\"") (N+1)
43
44
#else
45
46
// DEPRECATED: you don't need to compute the size anymore
47
#define JSON_ARRAY_SIZE(N) (ArduinoJson::detail::sizeofArray(N))
48
49
// DEPRECATED: you don't need to compute the size anymore
50
#define JSON_OBJECT_SIZE(N) (ArduinoJson::detail::sizeofObject(N))
51
52
// DEPRECATED: you don't need to compute the size anymore
53
#define JSON_STRING_SIZE(N) (N+1)
54
55
#endif
56
57
// clang-format on
58
59
ARDUINOJSON_BEGIN_PUBLIC_NAMESPACE
60
61
// DEPRECATED: use JsonDocument instead
62
template <size_t N>
63
class ARDUINOJSON_DEPRECATED("use JsonDocument instead") StaticJsonDocument
64
    : public JsonDocument {
65
 public:
66
  using JsonDocument::JsonDocument;
67
68
  size_t capacity() const {
69
    return N;
70
  }
71
};
72
73
namespace detail {
74
template <typename TAllocator>
75
class AllocatorAdapter : public Allocator {
76
 public:
77
  AllocatorAdapter(const AllocatorAdapter&) = delete;
78
  AllocatorAdapter& operator=(const AllocatorAdapter&) = delete;
79
80
  void* allocate(size_t size) override {
81
    return _allocator.allocate(size);
82
  }
83
84
  void deallocate(void* ptr) override {
85
    _allocator.deallocate(ptr);
86
  }
87
88
  void* reallocate(void* ptr, size_t new_size) override {
89
    return _allocator.reallocate(ptr, new_size);
90
  }
91
92
  static Allocator* instance() {
93
    static AllocatorAdapter instance;
94
    return &instance;
95
  }
96
97
 private:
98
  AllocatorAdapter() = default;
99
  ~AllocatorAdapter() = default;
100
101
  TAllocator _allocator;
102
};
103
}  // namespace detail
104
105
// DEPRECATED: use JsonDocument instead
106
template <typename TAllocator>
107
class ARDUINOJSON_DEPRECATED("use JsonDocument instead") BasicJsonDocument
108
    : public JsonDocument {
109
 public:
110
  BasicJsonDocument(size_t capacity)
111
      : JsonDocument(detail::AllocatorAdapter<TAllocator>::instance()),
112
        _capacity(capacity) {}
113
114
  size_t capacity() const {
115
    return _capacity;
116
  }
117
118
  void garbageCollect() {}
119
120
 private:
121
  size_t _capacity;
122
};
123
124
// DEPRECATED: use JsonDocument instead
125
class ARDUINOJSON_DEPRECATED("use JsonDocument instead") DynamicJsonDocument
126
    : public JsonDocument {
127
 public:
128
0
  DynamicJsonDocument(size_t capacity) : _capacity(capacity) {}
129
130
0
  size_t capacity() const {
131
0
    return _capacity;
132
0
  }
133
134
0
  void garbageCollect() {}
135
136
 private:
137
  size_t _capacity;
138
};
139
140
0
inline JsonObject JsonArray::createNestedObject() const {
141
0
  return add<JsonObject>();
142
0
}
143
144
ARDUINOJSON_END_PUBLIC_NAMESPACE