#pragma once
#include
#include
namespace base::http {
struct WebSocketMessage {
enum class Type { Text, Binary };
WebSocketMessage() = default; // for d-construciton
explicit WebSocketMessage(const std::string& str);
explicit WebSocketMessage(const std::vector& data);
explicit WebSocketMessage(const std::span& data);
Type GetType() const;
const std::string& AsText() const;
const std::vector& AsBinary() const;
private:
struct Text {
std::string data;
};
struct Binary {
std::vector data;
};
// no payload (yet?)
// struct Ping {};
std::variant payload;
};
// Helper to more easily build a websocket message object
template
inline std::shared_ptr BuildMessage(const In& in) {
return std::make_shared(in);
}
} // namespace base::http