Joedb 9.1.4
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(int argc, char **argv)
13 /////////////////////////////////////////////////////////////////////////////
14 {
15 if (argc <= 1)
16 {
17 std::cerr << "usage: " << argv[0] << " [--base64] <file.joedb>\n";
18 return 1;
19 }
20
21 bool base64 = false;
22 int file_index = 1;
23
24 if (argc > 2 && argv[1] == std::string("--base64"))
25 {
26 file_index++;
27 base64 = true;
28 }
29
30 File file(argv[file_index], Open_Mode::read_existing);
31 Readonly_Journal journal(file);
32 Database db;
33 journal.replay_log(db);
34 const int error = write_json(std::cout, db, base64);
35
36 if (error & JSON_Error::utf8)
37 std::cerr << "warning: a string could not be encoded. Maybe you should use --base64 instead.\n";
38
39 if (error & JSON_Error::infnan)
40 std::cerr << "warning: inf or nan value encoded as 0. JSON does not support inf and nan.\n";
41
42 return 0;
43 }
44}
45
46/////////////////////////////////////////////////////////////////////////////
47int main(int argc, char **argv)
48/////////////////////////////////////////////////////////////////////////////
49{
50 return joedb::main_exception_catcher(joedb::joedb_to_json, argc, argv);
51}
int main()
@ read_existing
fails if does not exist
int main_exception_catcher(int(*main)(int, char **), int argc, char **argv)
Catch exception 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