add dv::value support to binary_json

This commit is contained in:
MihailRis
2024-09-16 22:53:27 +03:00
parent 271db9a6f1
commit 27c8307562
4 changed files with 210 additions and 1 deletions
+34
View File
@@ -36,3 +36,37 @@ TEST(BJSON, EncodeDecode) {
}
}
}
TEST(BJSON, EncodeDecodeDV) {
const std::string name = "JSON-encoder";
const int bytesSize = 5000;
const int year = 2019;
const float score = 3.141592;
dynamic::ByteBuffer srcBytes(bytesSize);
for (int i = 0; i < bytesSize; i ++) {
srcBytes[i] = rand();
}
std::vector<ubyte> bjsonBytes;
{
auto object = dv::object();
object["name"] = name;
object["year"] = year;
object["score"] = score;
object["data"] = srcBytes;
bjsonBytes = json::to_binaryDV(object, false);
}
{
auto object = json::from_binaryDV(bjsonBytes.data(), bjsonBytes.size());
EXPECT_EQ(object["name"].asString(), name);
EXPECT_EQ(object["year"].asInteger(), year);
EXPECT_FLOAT_EQ(object["score"].asNumber(), score);
const auto& bytes = object["data"].asBytes();
EXPECT_EQ(bytes.size(), bytesSize);
for (int i = 0; i < bytesSize; i++) {
EXPECT_EQ(bytes[i], srcBytes[i]);
}
}
}