add dv::value support to binary_json
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user