2017-07-09 17:51:38 +08:00
|
|
|
#include <iostream>
|
2018-08-17 03:53:47 +08:00
|
|
|
#include <iomanip>
|
2018-02-02 05:20:26 +08:00
|
|
|
#include <nlohmann/json.hpp>
|
2016-12-11 20:36:08 +08:00
|
|
|
|
|
|
|
using json = nlohmann::json;
|
2022-07-31 23:38:52 +08:00
|
|
|
using namespace nlohmann::literals;
|
2016-12-11 20:36:08 +08:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// create a JSON value
|
|
|
|
json j = R"({"compact": true, "schema": 0})"_json;
|
|
|
|
|
|
|
|
// serialize it to CBOR
|
2021-12-29 20:41:01 +08:00
|
|
|
std::vector<std::uint8_t> v = json::to_cbor(j);
|
2016-12-11 20:36:08 +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;
|
|
|
|
}
|