Skip to content

Commit

Permalink
pandaproxy/json: Move string version of rjson_parse
Browse files Browse the repository at this point in the history
It shouldn't be used in the general case.

Signed-off-by: Ben Pope <ben@redpanda.com>
(cherry picked from commit ac7c7dd)
  • Loading branch information
BenPope committed Jul 16, 2024
1 parent bba5270 commit 84acab6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
22 changes: 11 additions & 11 deletions src/v/pandaproxy/json/requests/test/produce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_binary_request) {
]
})";

auto records = ppj::rjson_parse(input, make_binary_v2_handler());
auto records = ppj::impl::rjson_parse(input, make_binary_v2_handler());
BOOST_TEST(records.size() == 2);
BOOST_TEST(!!records[0].value);

Expand Down Expand Up @@ -77,7 +77,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_json_request) {
]
})";

auto records = ppj::rjson_parse(input, make_json_v2_handler());
auto records = ppj::impl::rjson_parse(input, make_json_v2_handler());
BOOST_REQUIRE_EQUAL(records.size(), 2);
BOOST_REQUIRE_EQUAL(records[0].partition_id, model::partition_id(0));
BOOST_REQUIRE(!records[0].key);
Expand Down Expand Up @@ -111,7 +111,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_invalid_json_request) {
})";

BOOST_CHECK_THROW(
ppj::rjson_parse(input, make_json_v2_handler()),
ppj::impl::rjson_parse(input, make_json_v2_handler()),
pandaproxy::json::parse_error);
}

Expand All @@ -121,7 +121,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_empty) {
"records": []
})";

auto records = ppj::rjson_parse(input, make_binary_v2_handler());
auto records = ppj::impl::rjson_parse(input, make_binary_v2_handler());
BOOST_TEST(records.size() == 0);
}

Expand All @@ -137,7 +137,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_error_records_name) {
})";

BOOST_CHECK_EXCEPTION(
ppj::rjson_parse(input, make_binary_v2_handler()),
ppj::impl::rjson_parse(input, make_binary_v2_handler()),
ppj::parse_error,
[](ppj::parse_error const& e) {
return e.what() == std::string_view("parse error at offset 25");
Expand All @@ -156,7 +156,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_error_partition_name) {
})";

BOOST_CHECK_EXCEPTION(
ppj::rjson_parse(input, make_binary_v2_handler()),
ppj::impl::rjson_parse(input, make_binary_v2_handler()),
ppj::parse_error,
[](ppj::parse_error const& e) {
return e.what() == std::string_view("parse error at offset 99");
Expand All @@ -175,7 +175,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_error_partition_type) {
})";

BOOST_CHECK_EXCEPTION(
ppj::rjson_parse(input, make_binary_v2_handler()),
ppj::impl::rjson_parse(input, make_binary_v2_handler()),
ppj::parse_error,
[](ppj::parse_error const& e) {
return e.what() == std::string_view("parse error at offset 112");
Expand All @@ -195,7 +195,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_error_before_records) {
})";

BOOST_CHECK_EXCEPTION(
ppj::rjson_parse(input, make_binary_v2_handler()),
ppj::impl::rjson_parse(input, make_binary_v2_handler()),
ppj::parse_error,
[](ppj::parse_error const& e) {
return e.what() == std::string_view("parse error at offset 28");
Expand All @@ -215,7 +215,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_error_after_records) {
})";

BOOST_CHECK_EXCEPTION(
ppj::rjson_parse(input, make_binary_v2_handler()),
ppj::impl::rjson_parse(input, make_binary_v2_handler()),
ppj::parse_error,
[](ppj::parse_error const& e) {
return e.what() == std::string_view("parse error at offset 152");
Expand All @@ -235,7 +235,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_error_between_records) {
})";

BOOST_CHECK_EXCEPTION(
ppj::rjson_parse(input, make_binary_v2_handler()),
ppj::impl::rjson_parse(input, make_binary_v2_handler()),
ppj::parse_error,
[](ppj::parse_error const& e) {
return e.what() == std::string_view("parse error at offset 144");
Expand All @@ -250,7 +250,7 @@ SEASTAR_THREAD_TEST_CASE(test_produce_request_error_no_records) {
})";

BOOST_CHECK_EXCEPTION(
ppj::rjson_parse(input, make_binary_v2_handler()),
ppj::impl::rjson_parse(input, make_binary_v2_handler()),
ppj::parse_error,
[](ppj::parse_error const& e) {
return e.what() == std::string_view("parse error at offset 24");
Expand Down
6 changes: 3 additions & 3 deletions src/v/pandaproxy/json/rjson_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ rjson_parse_buf(Arg&& arg, Handler&& handler) {
return std::forward<Handler>(handler).result;
}

} // namespace impl

/// \brief Parse a payload using the handler.
///
/// \warning rjson_parse is preferred, since it can be chunked.
Expand All @@ -132,6 +130,8 @@ rjson_parse(const char* const s, Handler&& handler) {
s, std::forward<Handler>(handler));
}

} // namespace impl

///\brief Parse a payload using the handler.
template<impl::RjsonParseHandler Handler>
typename Handler::rjson_parse_result rjson_parse(iobuf buf, Handler&& handler) {
Expand All @@ -144,7 +144,7 @@ template<impl::RjsonParseHandler Handler>
typename ss::future<typename Handler::rjson_parse_result>
rjson_parse(std::unique_ptr<ss::http::request> req, Handler handler) {
if (!req->content.empty()) {
co_return rjson_parse(req->content.data(), std::move(handler));
co_return impl::rjson_parse(req->content.data(), std::move(handler));
}

iobuf buf;
Expand Down
3 changes: 2 additions & 1 deletion src/v/pandaproxy/json/test/parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ inline void parse_test(size_t data_size) {
auto input = gen(data_size);

perf_tests::start_measuring_time();
auto records = ppj::rjson_parse(input.c_str(), make_binary_v2_handler());
auto records = ppj::impl::rjson_parse(
input.c_str(), make_binary_v2_handler());
perf_tests::stop_measuring_time();
}

Expand Down
4 changes: 2 additions & 2 deletions src/v/pandaproxy/rest/test/consumer_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ FIXTURE_TEST(pandaproxy_consumer_group, pandaproxy_test_fixture) {
BOOST_REQUIRE_EQUAL(
res.headers.result(), boost::beast::http::status::ok);

auto res_data = ppj::rjson_parse(
auto res_data = ppj::impl::rjson_parse(
res.body.data(), ppj::create_consumer_response_handler());
BOOST_REQUIRE_EQUAL(res_data.instance_id, "test_consumer");
member_id = res_data.instance_id;
Expand Down Expand Up @@ -315,7 +315,7 @@ FIXTURE_TEST(
BOOST_REQUIRE_EQUAL(
res.headers.result(), boost::beast::http::status::ok);

auto res_data = ppj::rjson_parse(
auto res_data = ppj::impl::rjson_parse(
res.body.data(), ppj::create_consumer_response_handler());
BOOST_REQUIRE_EQUAL(res_data.instance_id, "test_consumer");
member_id = res_data.instance_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SEASTAR_THREAD_TEST_CASE(test_post_subject_versions_parser) {
const parse_result expected{
{sub, expected_schema_def}, std::nullopt, std::nullopt};

auto result{ppj::rjson_parse(
auto result{ppj::impl::rjson_parse(
payload.data(), pps::post_subject_versions_request_handler{sub})};

// canonicalisation now requires a sharded_store, for now, minify.
Expand Down
16 changes: 8 additions & 8 deletions src/v/pandaproxy/schema_registry/test/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const pps::delete_subject_value delete_subject_value{

BOOST_AUTO_TEST_CASE(test_storage_serde) {
{
auto key = ppj::rjson_parse(
auto key = ppj::impl::rjson_parse(
avro_schema_key_sv.data(), pps::schema_key_handler<>{});
BOOST_CHECK_EQUAL(avro_schema_key, key);

Expand All @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(test_storage_serde) {
}

{
auto val = ppj::rjson_parse(
auto val = ppj::impl::rjson_parse(
avro_schema_value_sv.data(), pps::canonical_schema_value_handler<>{});
BOOST_CHECK_EQUAL(avro_schema_value, val);

Expand All @@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(test_storage_serde) {
}

{
auto val = ppj::rjson_parse(
auto val = ppj::impl::rjson_parse(
config_key_sv.data(), pps::config_key_handler<>{});
BOOST_CHECK_EQUAL(config_key, val);

Expand All @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(test_storage_serde) {
}

{
auto val = ppj::rjson_parse(
auto val = ppj::impl::rjson_parse(
config_key_sub_sv.data(), pps::config_key_handler<>{});
BOOST_CHECK_EQUAL(config_key_sub, val);

Expand All @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(test_storage_serde) {
}

{
auto val = ppj::rjson_parse(
auto val = ppj::impl::rjson_parse(
config_value_sv.data(), pps::config_value_handler<>{});
BOOST_CHECK_EQUAL(config_value, val);

Expand All @@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(test_storage_serde) {
}

{
auto val = ppj::rjson_parse(
auto val = ppj::impl::rjson_parse(
config_value_sub_sv.data(), pps::config_value_handler<>{});
BOOST_CHECK_EQUAL(config_value_sub, val);

Expand All @@ -181,7 +181,7 @@ BOOST_AUTO_TEST_CASE(test_storage_serde) {
}

{
auto val = ppj::rjson_parse(
auto val = ppj::impl::rjson_parse(
delete_subject_key_sv.data(), pps::delete_subject_key_handler<>{});
BOOST_CHECK_EQUAL(delete_subject_key, val);

Expand All @@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(test_storage_serde) {
}

{
auto val = ppj::rjson_parse(
auto val = ppj::impl::rjson_parse(
delete_subject_value_sv.data(),
pps::delete_subject_value_handler<>{});
BOOST_CHECK_EQUAL(delete_subject_value, val);
Expand Down

0 comments on commit 84acab6

Please sign in to comment.