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>
template <typename T>
@ -146,6 +147,17 @@ TEST_CASE("serialize MsgPack value") {
checkVariant(serialized("\xDB\x00\x01\x00\x00", 5), "\xDB\x00\x01\x00\x00");
}
SECTION("bin 8") {
auto str = std::string(1, 1);
checkVariant(MsgPackBinary(str.data(), str.size()), "\xC4\x01\x01");
}
SECTION("bin 16") {
auto str = std::string(256, 1);
checkVariant(MsgPackBinary(str.data(), str.size()),
std::string("\xC5\x01\x00", 3) + str);
}
SECTION("serialize round double as integer") { // Issue #1718
checkVariant(-32768.0, "\xD1\x80\x00");
checkVariant(-129.0, "\xD1\xFF\x7F");