Skip to content

Commit

Permalink
pandaproxy/json: Avoid temporary for calls to write_body
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Pope <ben@redpanda.com>
  • Loading branch information
BenPope committed Jul 4, 2024
1 parent a455d23 commit 5d90218
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/v/pandaproxy/reply.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ errored_body(std::error_condition ec, ss::sstring msg) {
pandaproxy::json::error_body body{.ec = ec, .message = std::move(msg)};
auto rep = std::make_unique<ss::http::reply>();
rep->set_status(error_code_to_status(ec));
auto b = json::rjson_serialize(body);
rep->write_body("json", b);
rep->write_body("json", json::rjson_serialize(body));
return rep;
}

Expand Down
19 changes: 6 additions & 13 deletions src/v/pandaproxy/rest/handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ get_brokers(server::request_t rq, server::reply_t rp) {
return b.node_id;
});

auto json_rslt = ppj::rjson_serialize(brokers);
rp.rep->write_body("json", json_rslt);
rp.rep->write_body("json", ppj::rjson_serialize(brokers));

rp.mime_type = res_fmt;
return std::move(rp);
Expand Down Expand Up @@ -109,8 +108,7 @@ get_topics_names(server::request_t rq, server::reply_t rp) {
}
}

auto json_rslt = ppj::rjson_serialize(names);
rp.rep->write_body("json", json_rslt);
rp.rep->write_body("json", ppj::rjson_serialize(names));
rp.mime_type = res_fmt;
return std::move(rp);
});
Expand Down Expand Up @@ -186,8 +184,8 @@ post_topics_name(server::request_t rq, server::reply_t rp) {
return client.produce_records(topic, std::move(records))
.then([rp{std::move(rp)},
res_fmt](kafka::produce_response res) mutable {
auto json_rslt = ppj::rjson_serialize(res.data.responses[0]);
rp.rep->write_body("json", json_rslt);
rp.rep->write_body(
"json", ppj::rjson_serialize(res.data.responses[0]));
rp.mime_type = res_fmt;
return std::move(rp);
});
Expand Down Expand Up @@ -278,8 +276,7 @@ create_consumer(server::request_t rq, server::reply_t rp) {
kafka::member_id name) mutable {
json::create_consumer_response res{
.instance_id = name, .base_uri = base_uri + name};
auto json_rslt = ppj::rjson_serialize(res);
rp.rep->write_body("json", json_rslt);
rp.rep->write_body("json", ppj::rjson_serialize(res));
rp.mime_type = res_fmt;
return std::move(rp);
});
Expand Down Expand Up @@ -444,11 +441,7 @@ get_consumer_offsets(server::request_t rq, server::reply_t rp) {
return client
.consumer_offset_fetch(group_id, member_id, std::move(req_data))
.then([rp{std::move(rp)}, res_fmt](auto res) mutable {
::json::StringBuffer str_buf;
::json::Writer<::json::StringBuffer> w(str_buf);
ppj::rjson_serialize(w, res);
ss::sstring json_rslt = str_buf.GetString();
rp.rep->write_body("json", json_rslt);
rp.rep->write_body("json", ppj::rjson_serialize(res));
rp.mime_type = res_fmt;
return std::move(rp);
});
Expand Down

0 comments on commit 5d90218

Please sign in to comment.