2021-03-29 17:14:01 +02:00
|
|
|
// ArduinoJson - https://arduinojson.org
|
2022-01-01 10:00:54 +01:00
|
|
|
// Copyright © 2014-2022, Benoit BLANCHON
|
2018-11-30 17:53:54 +01:00
|
|
|
// MIT License
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-19 12:02:48 +01:00
|
|
|
#include <ArduinoJson/Strings/JsonString.hpp>
|
2022-10-03 19:14:05 +02:00
|
|
|
#include <ArduinoJson/Variant/VariantConstRef.hpp>
|
2019-08-26 11:57:57 +02:00
|
|
|
#include <ArduinoJson/Variant/VariantRef.hpp>
|
2018-11-30 17:53:54 +01:00
|
|
|
|
|
|
|
namespace ARDUINOJSON_NAMESPACE {
|
2018-12-07 09:16:58 +01:00
|
|
|
// A key value pair for CollectionData.
|
2022-12-19 12:16:35 +01:00
|
|
|
class JsonPair {
|
2018-11-30 17:53:54 +01:00
|
|
|
public:
|
2022-12-19 12:16:35 +01:00
|
|
|
JsonPair(MemoryPool* pool, VariantSlot* slot) {
|
2018-11-30 17:53:54 +01:00
|
|
|
if (slot) {
|
2022-12-19 12:02:48 +01:00
|
|
|
_key = JsonString(slot->key(), slot->ownsKey() ? JsonString::Copied
|
|
|
|
: JsonString::Linked);
|
2018-12-07 09:16:58 +01:00
|
|
|
_value = VariantRef(pool, slot->data());
|
2018-11-30 17:53:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 12:02:48 +01:00
|
|
|
JsonString key() const {
|
2018-11-30 17:53:54 +01:00
|
|
|
return _key;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantRef value() const {
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-12-19 12:02:48 +01:00
|
|
|
JsonString _key;
|
2018-11-30 17:53:54 +01:00
|
|
|
VariantRef _value;
|
|
|
|
};
|
|
|
|
|
2022-12-19 12:16:35 +01:00
|
|
|
class JsonPairConst {
|
2018-11-30 17:53:54 +01:00
|
|
|
public:
|
2022-12-19 12:16:35 +01:00
|
|
|
JsonPairConst(const VariantSlot* slot) {
|
2018-11-30 17:53:54 +01:00
|
|
|
if (slot) {
|
2022-12-19 12:02:48 +01:00
|
|
|
_key = JsonString(slot->key(), slot->ownsKey() ? JsonString::Copied
|
|
|
|
: JsonString::Linked);
|
2018-12-07 09:16:58 +01:00
|
|
|
_value = VariantConstRef(slot->data());
|
2018-11-30 17:53:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 12:02:48 +01:00
|
|
|
JsonString key() const {
|
2018-11-30 17:53:54 +01:00
|
|
|
return _key;
|
|
|
|
}
|
|
|
|
|
|
|
|
VariantConstRef value() const {
|
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-12-19 12:02:48 +01:00
|
|
|
JsonString _key;
|
2018-11-30 17:53:54 +01:00
|
|
|
VariantConstRef _value;
|
|
|
|
};
|
|
|
|
} // namespace ARDUINOJSON_NAMESPACE
|