42 lines
938 B
C++
42 lines
938 B
C++
#pragma once
|
|
#include <base/assert.hpp>
|
|
#include <base/logger.hpp>
|
|
#include <base/types.hpp>
|
|
|
|
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<u8>& data);
|
|
explicit WebSocketMessage(const std::span<u8>& data);
|
|
|
|
Type GetType() const;
|
|
const std::string& AsText() const;
|
|
const std::vector<u8>& AsBinary() const;
|
|
|
|
private:
|
|
struct Text {
|
|
std::string data;
|
|
};
|
|
|
|
struct Binary {
|
|
std::vector<u8> data;
|
|
};
|
|
|
|
// no payload (yet?)
|
|
// struct Ping {};
|
|
|
|
std::variant<Text, Binary> payload;
|
|
};
|
|
|
|
// Helper to more easily build a websocket message object
|
|
template <class In>
|
|
inline std::shared_ptr<const WebSocketMessage> BuildMessage(const In& in) {
|
|
return std::make_shared<WebSocketMessage>(in);
|
|
}
|
|
|
|
} // namespace base::http
|