#pragma once #include #include #include // Forward declare so CommandEnvelope.hpp doesn't pull in CommandResult.hpp circularly struct CommandResult; // --------------------------------------------------------------------------- // CommandEnvelope // // Universal message wrapper. Every transport (MQTT, WebSocket, HTTP, UART) // parses its raw input and produces one of these before calling CommandBus::dispatch(). // // The reply lambda is injected by the transport so the bus and handlers never // need to know which wire the response goes back on. // --------------------------------------------------------------------------- struct CommandEnvelope { enum class Transport { MQTT, WEBSOCKET, HTTP, UART }; // Protocol version: 2 = v2 namespaced commands, 1 = legacy v1 (default 2) uint8_t version = 2; Transport transport = Transport::WEBSOCKET; // WebSocket client ID — 0 for transports that don't have per-client identity uint32_t clientId = 0; // Flat command name — e.g. "playback", "relay.set_durations", "system.restart" String command; // The "contents" object from the raw JSON message JsonDocument contents; // Reply callback injected by the transport layer. // The bus calls this exactly once after dispatch completes. std::function reply; };