Check for trailing tokens in json2msgpack ondemand benchmark (#1908)

Related to #1904

Users of the simdjson library will see json2msgpack as an available
example of how to recursively process json with the ondemand parser,
and checking for trailing tokens in a document is one part of json validation.

These checks shouldn't affect benchmark results performance.
The benchmark is run on the 631KB twitter.json file.
This commit is contained in:
Tyson Andre
2022-10-05 08:49:09 -04:00
committed by GitHub
parent 137cb14bcc
commit 46241287c6
+8 -1
View File
@@ -75,17 +75,24 @@ simdjson2msgpack::to_msgpack(const simdjson::padded_string &json,
break;
case simdjson::ondemand::json_type::null:
write_byte(0xc0);
// As a side effect, the is_null call advances the document's iterator
// so that the current_location check would work in all cases.
doc.is_null();
break;
case simdjson::ondemand::json_type::array:
case simdjson::ondemand::json_type::object:
default:
// impossible
break;
SIMDJSON_UNREACHABLE();
}
} else {
simdjson::ondemand::value val = doc;
recursive_processor(val);
}
if (doc.current_location().error() == simdjson::SUCCESS) {
// Example of error detection - this won't be reached on twitter.json in the benchmark.
throw "There are unexpectedly tokens after the end of the json in the json2msgpack sample data";
}
return std::string_view(reinterpret_cast<char *>(buf), size_t(buff - buf));
}