forked from bblanchon/ArduinoJson
Don't call shrinkToFit()
for deserializeXxx(JsonVariant)
This commit is contained in:
@ -43,11 +43,9 @@ TEST_CASE("deserializeJson(JsonVariant)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{
|
||||||
AllocatorLog{
|
Deallocate(sizeofString("hello")),
|
||||||
Deallocate(sizeofString("hello")),
|
});
|
||||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("variant is unbound") {
|
SECTION("variant is unbound") {
|
||||||
@ -70,11 +68,9 @@ TEST_CASE("deserializeJson(ElementProxy)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{
|
||||||
AllocatorLog{
|
Deallocate(sizeofString("hello")),
|
||||||
Deallocate(sizeofString("hello")),
|
});
|
||||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("element must be created") {
|
SECTION("element must be created") {
|
||||||
@ -82,10 +78,7 @@ TEST_CASE("deserializeJson(ElementProxy)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "[\"hello\",[42]]");
|
REQUIRE(doc.as<std::string>() == "[\"hello\",[42]]");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{});
|
||||||
AllocatorLog{
|
|
||||||
Reallocate(sizeofPool(), sizeofArray(2) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,11 +93,9 @@ TEST_CASE("deserializeJson(MemberProxy)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}");
|
REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{
|
||||||
AllocatorLog{
|
Deallocate(sizeofString("world")),
|
||||||
Deallocate(sizeofString("world")),
|
});
|
||||||
Reallocate(sizeofPool(), sizeofObject(1) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("member must be created exists") {
|
SECTION("member must be created exists") {
|
||||||
@ -112,9 +103,6 @@ TEST_CASE("deserializeJson(MemberProxy)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\",\"value\":[42]}");
|
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\",\"value\":[42]}");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{});
|
||||||
AllocatorLog{
|
|
||||||
Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,9 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{
|
||||||
AllocatorLog{
|
Deallocate(sizeofString("hello")),
|
||||||
Deallocate(sizeofString("hello")),
|
});
|
||||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("variant is unbound") {
|
SECTION("variant is unbound") {
|
||||||
@ -70,11 +68,9 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{
|
||||||
AllocatorLog{
|
Deallocate(sizeofString("hello")),
|
||||||
Deallocate(sizeofString("hello")),
|
});
|
||||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("element must be created exists") {
|
SECTION("element must be created exists") {
|
||||||
@ -82,10 +78,7 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "[\"hello\",[42]]");
|
REQUIRE(doc.as<std::string>() == "[\"hello\",[42]]");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{});
|
||||||
AllocatorLog{
|
|
||||||
Reallocate(sizeofPool(), sizeofArray(2) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,7 +95,6 @@ TEST_CASE("deserializeMsgPack(MemberProxy)") {
|
|||||||
REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}");
|
REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}");
|
||||||
REQUIRE(spy.log() == AllocatorLog{
|
REQUIRE(spy.log() == AllocatorLog{
|
||||||
Deallocate(sizeofString("world")),
|
Deallocate(sizeofString("world")),
|
||||||
Reallocate(sizeofPool(), sizeofObject(2)),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,9 +103,6 @@ TEST_CASE("deserializeMsgPack(MemberProxy)") {
|
|||||||
|
|
||||||
REQUIRE(err == DeserializationError::Ok);
|
REQUIRE(err == DeserializationError::Ok);
|
||||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\",\"value\":[42]}");
|
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\",\"value\":[42]}");
|
||||||
REQUIRE(spy.log() ==
|
REQUIRE(spy.log() == AllocatorLog{});
|
||||||
AllocatorLog{
|
|
||||||
Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(1)),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,17 @@ struct is_deserialize_destination<
|
|||||||
ResourceManager*>::value>::type> : true_type {
|
ResourceManager*>::value>::type> : true_type {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename TDestination>
|
||||||
|
inline void shrinkJsonDocument(TDestination&) {
|
||||||
|
// no-op by default
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ARDUINOJSON_AUTO_SHRINK
|
||||||
|
inline void shrinkJsonDocument(JsonDocument& doc) {
|
||||||
|
doc.shrinkToFit();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
template <template <typename> class TDeserializer, typename TDestination,
|
template <template <typename> class TDeserializer, typename TDestination,
|
||||||
typename TReader, typename TOptions>
|
typename TReader, typename TOptions>
|
||||||
DeserializationError doDeserialize(TDestination&& dst, TReader reader,
|
DeserializationError doDeserialize(TDestination&& dst, TReader reader,
|
||||||
@ -45,9 +56,7 @@ DeserializationError doDeserialize(TDestination&& dst, TReader reader,
|
|||||||
dst.clear();
|
dst.clear();
|
||||||
auto err = TDeserializer<TReader>(resources, reader)
|
auto err = TDeserializer<TReader>(resources, reader)
|
||||||
.parse(*data, options.filter, options.nestingLimit);
|
.parse(*data, options.filter, options.nestingLimit);
|
||||||
#if ARDUINOJSON_AUTO_SHRINK
|
shrinkJsonDocument(dst);
|
||||||
resources->shrinkToFit();
|
|
||||||
#endif
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user