2018-10-28 14:09:26 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
using json = nlohmann::json;
|
2022-07-31 15:38:52 +00:00
|
|
|
using namespace nlohmann::literals;
|
2018-10-28 14:09:26 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// create a JSON value
|
|
|
|
json j = R"({"compact": true, "schema": 0})"_json;
|
|
|
|
|
|
|
|
// serialize it to BSON
|
2021-12-29 12:41:01 +00:00
|
|
|
std::vector<std::uint8_t> v = json::to_bson(j);
|
2018-10-28 14:09:26 +00: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;
|
|
|
|
}
|