|
|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
#include <ArduinoJson/Memory/StringNode.hpp>
|
|
|
#include <ArduinoJson/Misc/SerializedValue.hpp>
|
|
|
+#include <ArduinoJson/MsgPack/MsgPackBinary.hpp>
|
|
|
#include <ArduinoJson/Numbers/convertNumber.hpp>
|
|
|
#include <ArduinoJson/Strings/JsonString.hpp>
|
|
|
#include <ArduinoJson/Strings/StringAdapters.hpp>
|
|
|
@@ -48,6 +49,10 @@ class VariantData {
|
|
|
return visit.visit(RawString(content_.asOwnedString->data,
|
|
|
content_.asOwnedString->length));
|
|
|
|
|
|
+ case VALUE_IS_BINARY:
|
|
|
+ return visit.visit(MsgPackBinary(content_.asOwnedString->data,
|
|
|
+ content_.asOwnedString->length));
|
|
|
+
|
|
|
case VALUE_IS_SIGNED_INTEGER:
|
|
|
return visit.visit(content_.asSignedInteger);
|
|
|
|
|
|
@@ -185,6 +190,16 @@ class VariantData {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ MsgPackBinary asBinary() const {
|
|
|
+ switch (type()) {
|
|
|
+ case VALUE_IS_BINARY:
|
|
|
+ return MsgPackBinary(content_.asOwnedString->data,
|
|
|
+ content_.asOwnedString->length);
|
|
|
+ default:
|
|
|
+ return MsgPackBinary(nullptr, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
VariantData* getElement(size_t index,
|
|
|
const ResourceManager* resources) const {
|
|
|
return ArrayData::getElement(asArray(), index, resources);
|
|
|
@@ -274,6 +289,10 @@ class VariantData {
|
|
|
return type() == VALUE_IS_LINKED_STRING || type() == VALUE_IS_OWNED_STRING;
|
|
|
}
|
|
|
|
|
|
+ bool isBinary() const {
|
|
|
+ return type() == VALUE_IS_BINARY;
|
|
|
+ }
|
|
|
+
|
|
|
size_t nesting(const ResourceManager* resources) const {
|
|
|
auto collection = asCollection();
|
|
|
if (collection)
|
|
|
@@ -394,6 +413,28 @@ class VariantData {
|
|
|
var->setRawString(value, resources);
|
|
|
}
|
|
|
|
|
|
+ void setBinary(StringNode* s) {
|
|
|
+ ARDUINOJSON_ASSERT(s);
|
|
|
+ setType(VALUE_IS_BINARY);
|
|
|
+ content_.asOwnedString = s;
|
|
|
+ }
|
|
|
+
|
|
|
+ void setBinary(MsgPackBinary value, ResourceManager* resources) {
|
|
|
+ auto dup = resources->saveString(
|
|
|
+ adaptString(reinterpret_cast<const char*>(value.data()), value.size()));
|
|
|
+ if (dup)
|
|
|
+ setBinary(dup);
|
|
|
+ else
|
|
|
+ setNull();
|
|
|
+ }
|
|
|
+
|
|
|
+ static void setBinary(VariantData* var, MsgPackBinary value,
|
|
|
+ ResourceManager* resources) {
|
|
|
+ if (!var)
|
|
|
+ return;
|
|
|
+ var->setBinary(value, resources);
|
|
|
+ }
|
|
|
+
|
|
|
template <typename TAdaptedString>
|
|
|
void setString(TAdaptedString value, ResourceManager* resources) {
|
|
|
setNull(resources);
|