• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bblanchon / ArduinoJson / 4466978960

pending completion
4466978960

push

github

Benoit Blanchon
Merge `DynamicJsonDocument` with `JsonDocument`

72 of 72 new or added lines in 1 file covered. (100.0%)

3279 of 3296 relevant lines covered (99.48%)

6214.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.73
/src/ArduinoJson/Variant/VariantSlot.hpp
1
// ArduinoJson - https://arduinojson.org
2
// Copyright © 2014-2023, Benoit BLANCHON
3
// MIT License
4

5
#pragma once
6

7
#include <ArduinoJson/Polyfills/integer.hpp>
8
#include <ArduinoJson/Polyfills/limits.hpp>
9
#include <ArduinoJson/Polyfills/type_traits.hpp>
10
#include <ArduinoJson/Variant/VariantContent.hpp>
11

12
ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE
13

14
typedef int_t<ARDUINOJSON_SLOT_OFFSET_SIZE * 8>::type VariantSlotDiff;
15

16
class VariantSlot {
17
  // CAUTION: same layout as VariantData
18
  // we cannot use composition because it adds padding
19
  // (+20% on ESP8266 for example)
20
  VariantContent _content;
21
  uint8_t _flags;
22
  VariantSlotDiff _next;
23
  const char* _key;
24

25
 public:
26
  // Must be a POD!
27
  // - no constructor
28
  // - no destructor
29
  // - no virtual
30
  // - no inheritance
31

32
  VariantData* data() {
3,703✔
33
    return reinterpret_cast<VariantData*>(&_content);
3,703✔
34
  }
35

36
  const VariantData* data() const {
133,792✔
37
    return reinterpret_cast<const VariantData*>(&_content);
133,792✔
38
  }
39

40
  VariantSlot* next() {
209,508✔
41
    return _next ? this + _next : 0;
209,508✔
42
  }
43

44
  const VariantSlot* next() const {
199,352✔
45
    return const_cast<VariantSlot*>(this)->next();
199,352✔
46
  }
47

48
  VariantSlot* next(size_t distance) {
442✔
49
    VariantSlot* slot = this;
442✔
50
    while (distance--) {
690✔
51
      if (!slot->_next)
255✔
52
        return 0;
7✔
53
      slot += slot->_next;
248✔
54
    }
55
    return slot;
435✔
56
  }
57

58
  const VariantSlot* next(size_t distance) const {
59
    return const_cast<VariantSlot*>(this)->next(distance);
60
  }
61

62
  void setNext(VariantSlot* slot) {
22✔
63
    ARDUINOJSON_ASSERT(!slot || slot - this >=
64
                                    numeric_limits<VariantSlotDiff>::lowest());
65
    ARDUINOJSON_ASSERT(!slot || slot - this <=
66
                                    numeric_limits<VariantSlotDiff>::highest());
67
    _next = VariantSlotDiff(slot ? slot - this : 0);
22✔
68
  }
22✔
69

70
  void setNextNotNull(VariantSlot* slot) {
68,534✔
71
    ARDUINOJSON_ASSERT(slot != 0);
72
    ARDUINOJSON_ASSERT(slot - this >=
73
                       numeric_limits<VariantSlotDiff>::lowest());
74
    ARDUINOJSON_ASSERT(slot - this <=
75
                       numeric_limits<VariantSlotDiff>::highest());
76
    _next = VariantSlotDiff(slot - this);
68,534✔
77
  }
68,534✔
78

79
  void setKey(JsonString k) {
2,115✔
80
    ARDUINOJSON_ASSERT(k);
81
    if (k.isLinked())
2,115✔
82
      _flags &= VALUE_MASK;
737✔
83
    else
84
      _flags |= OWNED_KEY_BIT;
1,378✔
85
    _key = k.c_str();
2,115✔
86
  }
2,115✔
87

88
  const char* key() const {
12,664✔
89
    return _key;
12,664✔
90
  }
91

92
  bool ownsKey() const {
675✔
93
    return (_flags & OWNED_KEY_BIT) != 0;
675✔
94
  }
95

96
  void clear() {
70,739✔
97
    _next = 0;
70,739✔
98
    _flags = 0;
70,739✔
99
    _key = 0;
70,739✔
100
  }
70,739✔
101

102
  void movePointers(ptrdiff_t stringDistance, ptrdiff_t variantDistance) {
7✔
103
    if (_flags & OWNED_KEY_BIT)
7✔
104
      _key += stringDistance;
1✔
105
    if (_flags & OWNED_VALUE_BIT)
7✔
106
      _content.asString.data += stringDistance;
3✔
107
    if (_flags & COLLECTION_MASK)
7✔
108
      _content.asCollection.movePointers(stringDistance, variantDistance);
×
109
  }
7✔
110
};
111

112
ARDUINOJSON_END_PRIVATE_NAMESPACE
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc