Skip to content

Commit eb4c7ee

Browse files
committed
update fuzz_dump to the non deprecated replacement
1 parent 51cce3d commit eb4c7ee

1 file changed

Lines changed: 48 additions & 46 deletions

File tree

‎fuzz/fuzz_dump.cpp‎

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,57 @@
66

77
#include "NullBuffer.h"
88

9-
// from the README on the front page
10-
void compute_dump(simdjson::ParsedJson::Iterator &pjh) {
11-
NulOStream os;
12-
13-
if (pjh.is_object()) {
14-
os << "{";
15-
if (pjh.down()) {
16-
pjh.print(os); // must be a string
17-
os << ":";
18-
pjh.next();
19-
compute_dump(pjh); // let us recurse
20-
while (pjh.next()) {
21-
os << ",";
22-
pjh.print(os);
23-
os << ":";
24-
pjh.next();
25-
compute_dump(pjh); // let us recurse
26-
}
27-
pjh.up();
28-
}
29-
os << "}";
30-
} else if (pjh.is_array()) {
31-
os << "[";
32-
if (pjh.down()) {
33-
compute_dump(pjh); // let us recurse
34-
while (pjh.next()) {
35-
os << ",";
36-
compute_dump(pjh); // let us recurse
37-
}
38-
pjh.up();
9+
// example from doc/basics.md#tree-walking-and-json-element-types
10+
void print_json(std::ostream& os, simdjson::dom::element element) {
11+
const char endl='\n';
12+
switch (element.type()) {
13+
case simdjson::dom::element_type::ARRAY:
14+
os << "[";
15+
for (simdjson::dom::element child : simdjson::dom::array(element)) {
16+
print_json(os, child);
17+
os << ",";
18+
}
19+
os << "]";
20+
break;
21+
case simdjson::dom::element_type::OBJECT:
22+
os << "{";
23+
for (simdjson::dom::key_value_pair field : simdjson::dom::object(element)) {
24+
os << "\"" << field.key << "\": ";
25+
print_json(os, field.value);
26+
}
27+
os << "}";
28+
break;
29+
case simdjson::dom::element_type::INT64:
30+
os << int64_t(element) << endl;
31+
break;
32+
case simdjson::dom::element_type::UINT64:
33+
os << uint64_t(element) << endl;
34+
break;
35+
case simdjson::dom::element_type::DOUBLE:
36+
os << double(element) << endl;
37+
break;
38+
case simdjson::dom::element_type::STRING:
39+
os << std::string_view(element) << endl;
40+
break;
41+
case simdjson::dom::element_type::BOOL:
42+
os << bool(element) << endl;
43+
break;
44+
case simdjson::dom::element_type::NULL_VALUE:
45+
os << "null" << endl;
46+
break;
3947
}
40-
os << "]";
41-
} else {
42-
pjh.print(os); // just print the lone value
43-
}
4448
}
45-
4649
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
4750

48-
try {
49-
auto pj = simdjson::build_parsed_json(Data, Size);
50-
if (!pj.is_valid()) {
51-
throw 1;
51+
try {
52+
simdjson::dom::parser pj;
53+
auto elem=pj.parse(Data, Size);
54+
auto v=elem.value();
55+
NulOStream os;
56+
//std::ostream& os(std::cout);
57+
print_json(os,v);
58+
} catch (...) {
5259
}
53-
simdjson::ParsedJson::Iterator pjh(pj);
54-
if (pjh.is_ok()) {
55-
compute_dump(pjh);
56-
}
57-
} catch (...) {
58-
}
59-
return 0;
60+
return 0;
61+
6062
}

0 commit comments

Comments
 (0)