#pragma once #include #include #include #include #include "wire.h" using handler_fn = std::vector> (*)(uint32_t message_id, std::span payload); struct handler_entry { int8_t type_id; handler_fn handle; }; template std::vector> typed_handler(uint32_t message_id, std::span payload) { msgpack::parser p(payload.data(), static_cast(payload.size())); Req req; auto tup = req.as_tuple(); auto r = msgpack::unpack(p, tup); if (!r) { return {encode_response(message_id, DeviceError{1, "decode request ext_id=" + std::to_string(Req::ext_id) + ": msgpack error " + std::to_string(static_cast(r.error()))})}; } return Fn(message_id, req); } void dispatch_init(); void dispatch_schedule_ms(uint32_t ms, std::function fn); [[noreturn]] void dispatch_run(std::span handlers);