Simplify handler signatures: return response struct, typed_handler does encoding
This commit is contained in:
@@ -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>},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user