@@ -15,13 +15,73 @@ Sketch read_min_hashes(const std::string& json_filename) {
15
15
json jsonData;
16
16
inputFile >> jsonData;
17
17
18
+ // data
19
+ std::vector<hash_t > min_hashes;
20
+ std::string name;
21
+ std::string md5;
22
+ int ksize;
23
+ hash_t max_hash;
24
+ int seed;
25
+
18
26
// Access and print values
19
- std::vector<hash_t > min_hashes = jsonData[0 ][" signatures" ][0 ][" mins" ];
20
- std::string name = jsonData[0 ][" name" ];
21
- std::string md5 = jsonData[0 ][" signatures" ][0 ][" md5sum" ];
22
- int ksize = jsonData[0 ][" signatures" ][0 ][" ksize" ];
23
- hash_t max_hash = jsonData[0 ][" signatures" ][0 ][" max_hash" ];
24
- int seed = jsonData[0 ][" signatures" ][0 ][" seed" ];
27
+ try {
28
+ std::vector<hash_t > min_hashes_loaded = jsonData[0 ][" signatures" ][0 ][" mins" ];
29
+ min_hashes = min_hashes_loaded;
30
+ } catch (json::exception & e) {
31
+ std::cerr << " Error: " << e.what () << std::endl;
32
+ std::cerr << " Error: cannot find the mins in filename: " << json_filename << std::endl;
33
+ std::cerr << " Error: The file is may not be a valid sketch file!" << std::endl;
34
+ exit (1 );
35
+ }
36
+
37
+ try {
38
+ name = jsonData[0 ][" name" ];
39
+ } catch (json::exception & e) {
40
+ std::cerr << " Warning: no name found in: " << json_filename << " , using empty string" << std::endl;
41
+ name = " " ;
42
+ }
43
+
44
+ try {
45
+ md5 = jsonData[0 ][" signatures" ][0 ][" md5sum" ];
46
+ } catch (json::exception & e) {
47
+ // crash
48
+ // std::cerr << "Error: " << e.what() << std::endl;
49
+ // std::cerr << "Error: cannot find the md5 in filename: " << json_filename << std::endl;
50
+ // std::cerr << "Error: The file is may not be a valid sketch file!" << std::endl;
51
+ // exit(1);
52
+ std::cerr << " Warning: no md5 found in: " << json_filename << " , using empty string" << std::endl;
53
+ md5 = " " ;
54
+ }
55
+
56
+ try {
57
+ ksize = jsonData[0 ][" signatures" ][0 ][" ksize" ];
58
+ } catch (json::exception & e) {
59
+ // crash
60
+ std::cerr << " Error: " << e.what () << std::endl;
61
+ std::cerr << " Error: cannot find the ksize in filename: " << json_filename << std::endl;
62
+ std::cerr << " Error: The file is may not be a valid sketch file!" << std::endl;
63
+ exit (1 );
64
+ }
65
+
66
+ try {
67
+ max_hash = jsonData[0 ][" signatures" ][0 ][" max_hash" ];
68
+ } catch (json::exception & e) {
69
+ // crash
70
+ std::cerr << " Error: " << e.what () << std::endl;
71
+ std::cerr << " Error: cannot find the max_hash in filename: " << json_filename << std::endl;
72
+ std::cerr << " Error: The file is may not be a valid sketch file!" << std::endl;
73
+ exit (1 );
74
+ }
75
+
76
+ try {
77
+ seed = jsonData[0 ][" signatures" ][0 ][" seed" ];
78
+ } catch (json::exception & e) {
79
+ // crash
80
+ std::cerr << " Error: " << e.what () << std::endl;
81
+ std::cerr << " Error: cannot find the seed in filename: " << json_filename << std::endl;
82
+ std::cerr << " Error: The file is may not be a valid sketch file!" << std::endl;
83
+ exit (1 );
84
+ }
25
85
26
86
// Close the file
27
87
inputFile.close ();
0 commit comments