#pragma once #include "settlement/core/world.hpp" #include #include #include #include #include #include namespace settlement::viewer::lan_wire { inline constexpr std::uint32_t protocol_version = 11; inline constexpr std::uint8_t guest_player = 2; inline constexpr std::size_t frame_limit = 4 * 1024 * 1024; inline constexpr std::size_t frame_header_size = sizeof(std::uint32_t) + sizeof(std::uint8_t); enum class Message : std::uint8_t { Hello = 1, Snapshot, Command, Receipt, Reject, Ping }; struct Frame { Message message; std::string_view payload; std::size_t size; }; struct Hello { std::uint32_t version; std::uint64_t key; }; struct Receipt { CommandStatus status; std::uint64_t next_sequence; }; // The payload must be backed by storage separate from output. void append_frame(std::string& output, Message message, std::string_view payload = {}); // A complete frame borrows its payload from input. Invalid lengths throw even before the body arrives. [[nodiscard]] std::optional next_frame(std::string_view input); [[nodiscard]] std::array encode_hello(Hello hello); [[nodiscard]] std::optional decode_hello(std::string_view payload); [[nodiscard]] std::array encode_command(const PlayerCommand& command); [[nodiscard]] std::optional decode_command(std::string_view payload); [[nodiscard]] std::array encode_receipt(Receipt receipt); [[nodiscard]] std::optional decode_receipt(std::string_view payload); } // namespace settlement::viewer::lan_wire