Add MsgPack bin8/bin16/bin32 support

Closes #2078
Closes #922
This commit is contained in:
Aubrey (Sanae)
2024-04-29 14:47:40 +02:00
committed by Benoit Blanchon
parent cd4bf33132
commit 18a9a5b590
16 changed files with 358 additions and 11 deletions

View File

@ -3,6 +3,7 @@
// MIT License
#include <ArduinoJson.h>
#include <array>
#include <catch.hpp>
#include "Allocators.hpp"
@ -139,6 +140,36 @@ TEST_CASE("deserialize MsgPack value") {
SECTION("str 32") {
checkValue<std::string>("\xdb\x00\x00\x00\x05hello", std::string("hello"));
}
SECTION("bin 8") {
JsonDocument doc;
DeserializationError error = deserializeMsgPack(doc, "\xc4\x01?");
REQUIRE(error == DeserializationError::Ok);
REQUIRE(doc.is<MsgPackBinary>());
auto binary = doc.as<MsgPackBinary>();
REQUIRE(binary.size() == 1);
REQUIRE(binary.data() != nullptr);
REQUIRE(reinterpret_cast<const char*>(binary.data())[0] == '?');
}
SECTION("bin 16") {
JsonDocument doc;
auto str = std::string(256, '?');
auto input = std::string("\xc5\x01\x00", 3) + str;
DeserializationError error = deserializeMsgPack(doc, input);
REQUIRE(error == DeserializationError::Ok);
REQUIRE(doc.is<MsgPackBinary>());
auto binary = doc.as<MsgPackBinary>();
REQUIRE(binary.size() == 0x100);
REQUIRE(binary.data() != nullptr);
REQUIRE(std::string(reinterpret_cast<const char*>(binary.data()),
binary.size()) == str);
}
}
TEST_CASE("deserializeMsgPack() under memory constaints") {