Simplify handler signatures: return response struct, typed_handler does encoding

This commit is contained in:
Ian Gulliver
2026-04-10 22:21:31 +09:00
parent e2a5d97dae
commit 58db392bf3
5 changed files with 19 additions and 21 deletions

View File

@@ -97,17 +97,17 @@ static const std::unordered_map<std::string_view, test_fn> tests = {
{"discovery", test_discovery},
};
static size_t handle_test(uint32_t message_id, const RequestTest& req, span_writer &out) {
static ResponseTest handle_test(const RequestTest& req) {
auto it = tests.find(req.name);
if (it == tests.end())
return encode_response_into(out, message_id, ResponseTest{false, {"unknown test: " + req.name}});
return encode_response_into(out, message_id, it->second());
return {false, {"unknown test: " + req.name}};
return it->second();
}
static constexpr handler_entry handlers[] = {
{RequestPICOBOOT::ext_id, handle_picoboot},
{RequestInfo::ext_id, handle_info},
{RequestLog::ext_id, handle_log},
{RequestPICOBOOT::ext_id, typed_handler<RequestPICOBOOT, handle_picoboot>},
{RequestInfo::ext_id, typed_handler<RequestInfo, handle_info>},
{RequestLog::ext_id, typed_handler<RequestLog, handle_log>},
{RequestTest::ext_id, typed_handler<RequestTest, handle_test>},
};