mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
add dv::value support to binary_json
This commit is contained in:
parent
271db9a6f1
commit
27c8307562
4 changed files with 210 additions and 1 deletions
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue