mirror of
https://github.com/eledio-devices/thirdparty-ArduinoJson.git
synced 2025-11-01 00:38:27 +01:00
Copy JsonArray and JsonObject, instead of storing pointers (fixes #780)
This commit is contained in:
@@ -19,13 +19,13 @@ class MsgPackSerializer {
|
||||
MsgPackSerializer(TWriter& writer) : _writer(&writer), _bytesWritten(0) {}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<sizeof(T) == 4>::type acceptFloat(T value32) {
|
||||
typename enable_if<sizeof(T) == 4>::type visitFloat(T value32) {
|
||||
writeByte(0xCA);
|
||||
writeInteger(value32);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename enable_if<sizeof(T) == 8>::type acceptFloat(T value64) {
|
||||
typename enable_if<sizeof(T) == 8>::type visitFloat(T value64) {
|
||||
float value32 = float(value64);
|
||||
if (value32 == value64) {
|
||||
writeByte(0xCA);
|
||||
@@ -36,7 +36,7 @@ class MsgPackSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
void acceptArray(const JsonArrayData& array) {
|
||||
void visitArray(JsonArray array) {
|
||||
size_t n = array.size();
|
||||
if (n < 0x10) {
|
||||
writeByte(uint8_t(0x90 + array.size()));
|
||||
@@ -47,13 +47,12 @@ class MsgPackSerializer {
|
||||
writeByte(0xDD);
|
||||
writeInteger(uint32_t(n));
|
||||
}
|
||||
for (JsonArrayData::const_iterator it = array.begin(); it != array.end();
|
||||
++it) {
|
||||
it->visit(*this);
|
||||
for (JsonArray::iterator it = array.begin(); it != array.end(); ++it) {
|
||||
it->accept(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void acceptObject(const JsonObjectData& object) {
|
||||
void visitObject(JsonObject object) {
|
||||
size_t n = object.size();
|
||||
if (n < 0x10) {
|
||||
writeByte(uint8_t(0x80 + n));
|
||||
@@ -64,14 +63,13 @@ class MsgPackSerializer {
|
||||
writeByte(0xDF);
|
||||
writeInteger(uint32_t(n));
|
||||
}
|
||||
for (JsonObjectData::const_iterator it = object.begin(); it != object.end();
|
||||
++it) {
|
||||
acceptString(it->key);
|
||||
it->value.visit(*this);
|
||||
for (JsonObject::iterator it = object.begin(); it != object.end(); ++it) {
|
||||
visitString(it->key());
|
||||
it->value().accept(*this);
|
||||
}
|
||||
}
|
||||
|
||||
void acceptString(const char* value) {
|
||||
void visitString(const char* value) {
|
||||
if (!value) return writeByte(0xC0); // nil
|
||||
|
||||
size_t n = strlen(value);
|
||||
@@ -91,11 +89,11 @@ class MsgPackSerializer {
|
||||
writeBytes(reinterpret_cast<const uint8_t*>(value), n);
|
||||
}
|
||||
|
||||
void acceptRawJson(const char* data, size_t size) {
|
||||
void visitRawJson(const char* data, size_t size) {
|
||||
writeBytes(reinterpret_cast<const uint8_t*>(data), size);
|
||||
}
|
||||
|
||||
void acceptNegativeInteger(JsonUInt value) {
|
||||
void visitNegativeInteger(JsonUInt value) {
|
||||
JsonUInt negated = JsonUInt(~value + 1);
|
||||
if (value <= 0x20) {
|
||||
writeInteger(int8_t(negated));
|
||||
@@ -117,7 +115,7 @@ class MsgPackSerializer {
|
||||
#endif
|
||||
}
|
||||
|
||||
void acceptPositiveInteger(JsonUInt value) {
|
||||
void visitPositiveInteger(JsonUInt value) {
|
||||
if (value <= 0x7F) {
|
||||
writeInteger(uint8_t(value));
|
||||
} else if (value <= 0xFF) {
|
||||
@@ -138,11 +136,11 @@ class MsgPackSerializer {
|
||||
#endif
|
||||
}
|
||||
|
||||
void acceptBoolean(bool value) {
|
||||
void visitBoolean(bool value) {
|
||||
writeByte(value ? 0xC3 : 0xC2);
|
||||
}
|
||||
|
||||
void acceptNull() {
|
||||
void visitNull() {
|
||||
writeByte(0xC0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user