2018-10-28 22:09:26 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
using json = nlohmann::json;
|
2022-07-31 23:38:52 +08:00
|
|
|
using namespace nlohmann::literals;
|
2018-10-28 22:09:26 +08:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// create a JSON value
|
|
|
|
json j = R"({"compact": true, "schema": 0})"_json;
|
|
|
|
|
|
|
|
// serialize it to BSON
|
2021-12-29 20:41:01 +08:00
|
|
|
std::vector<std::uint8_t> v = json::to_bson(j);
|
2018-10-28 22:09:26 +08:00
|
|
|
|
|
|
|
// print the vector content
|
|
|
|
for (auto& byte : v)
|
|
|
|
{
|
|
|
|
std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int)byte << " ";
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|