Joedb 10.0.1
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_to_json.cpp
Go to the documentation of this file.
1#include "joedb/ui/json.h"
6
7#include <iostream>
8
9namespace joedb
10{
11 /////////////////////////////////////////////////////////////////////////////
12 static int joedb_to_json(Arguments &arguments)
13 /////////////////////////////////////////////////////////////////////////////
14 {
15 const bool base64 = arguments.has_flag("base64");
16 const std::string_view file_name = arguments.get_next("file.joedb");
17
18 if (arguments.missing())
19 {
20 arguments.print_help(std::cerr);
21 return 1;
22 }
23
24 File file(file_name.data(), Open_Mode::read_existing);
25 Readonly_Journal journal(file);
26 Database db;
27 journal.replay_log(db);
28 const int error = write_json(std::cout, db, base64);
29
30 if (error & JSON_Error::utf8)
31 std::cerr << "warning: a string could not be encoded. Maybe you should use --base64 instead.\n";
32
33 if (error & JSON_Error::infnan)
34 std::cerr << "warning: inf or nan value encoded as 0. JSON does not support inf and nan.\n";
35
36 return 0;
37 }
38}
39
40/////////////////////////////////////////////////////////////////////////////
41int main(int argc, char **argv)
42/////////////////////////////////////////////////////////////////////////////
43{
44 return joedb::main_wrapper(joedb::joedb_to_json, argc, argv);
45}
int main()
@ read_existing
fails if does not exist
int main_wrapper(int(*main)(Arguments &), int argc, char **argv)
Process command-line arguments and catch exceptions from main.
int write_json(std::ostream &out, const Readable &db, bool base64)
Definition json.cpp:16
@ infnan
Definition json.h:12
@ utf8
Definition json.h:12
Definition Blob.h:7
JOEDB_FILE File
Definition File.h:25