2022-10-12 22:43:23 +02:00
|
|
|
#include <fstream>
|
|
|
|
|
#include "nlohmann/json.hpp"
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2022-10-24 13:10:24 +02:00
|
|
|
if (argc < 2)
|
|
|
|
|
printf("Usage : cbor2json file.cbor file.json\n");
|
|
|
|
|
|
2022-10-12 22:43:23 +02:00
|
|
|
// Read file
|
|
|
|
|
std::vector<uint8_t> cbor_data;
|
|
|
|
|
std::ifstream in_file(argv[1], std::ios::binary);
|
|
|
|
|
while (!in_file.eof())
|
|
|
|
|
{
|
|
|
|
|
uint8_t b;
|
|
|
|
|
in_file.read((char *)&b, 1);
|
|
|
|
|
cbor_data.push_back(b);
|
|
|
|
|
}
|
|
|
|
|
in_file.close();
|
|
|
|
|
cbor_data.pop_back();
|
|
|
|
|
nlohmann::json contents = nlohmann::json::from_cbor(cbor_data);
|
|
|
|
|
|
|
|
|
|
std::ofstream output_file(argv[2], std::ios::binary);
|
|
|
|
|
output_file << contents.dump(4);
|
|
|
|
|
output_file.close();
|
|
|
|
|
}
|