#include namespace base::http { WebSocketMessage::WebSocketMessage(const std::string& str) { payload.emplace(str); } WebSocketMessage::WebSocketMessage(const std::vector& data) { payload.emplace(data); } WebSocketMessage::WebSocketMessage(const std::span& data) { auto vec = std::vector {}; vec.resize(data.size()); std::memcpy(vec.data(), data.data(), data.size()); payload.emplace(vec); } WebSocketMessage::Type WebSocketMessage::GetType() const { if(std::holds_alternative(payload)) return Type::Text; else if(std::holds_alternative(payload)) return Type::Binary; BASE_CHECK(false, "Shouldn't get here."); } const std::string& WebSocketMessage::AsText() const { BASE_ASSERT(GetType() == Type::Text, "WebSocketMessage isn't holding a Text message"); return std::get(payload).data; } const std::vector& WebSocketMessage::AsBinary() const { BASE_ASSERT(GetType() == Type::Binary, "WebSocketMessage isn't holding a Binary message"); return std::get(payload).data; } } // namespace base::http