/*** This file is part of snapcast Copyright (C) 2014-2024 Johannes Pohl This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #pragma once // local headers #include "client_info.hpp" #include "codec_header.hpp" #include "hello.hpp" #include "pcm_chunk.hpp" #include "server_settings.hpp" #include "time.hpp" namespace msg { template static std::unique_ptr message_cast(std::unique_ptr message) { ToType* tmp = dynamic_cast(message.get()); std::unique_ptr result; if (tmp != nullptr) { message.release(); result.reset(tmp); return result; } return nullptr; } namespace factory { template static std::unique_ptr createMessage(const BaseMessage& base_message, char* buffer) { std::unique_ptr result = std::make_unique(); if (!result) return nullptr; result->deserialize(base_message, buffer); return result; } static std::unique_ptr createMessage(const BaseMessage& base_message, char* buffer) { std::unique_ptr result; switch (base_message.type) { case message_type::kCodecHeader: return createMessage(base_message, buffer); case message_type::kHello: return createMessage(base_message, buffer); case message_type::kServerSettings: return createMessage(base_message, buffer); case message_type::kTime: return createMessage