2021-04-17 15:20:24 +00:00
|
|
|
/*
|
2021-04-25 09:30:39 +00:00
|
|
|
* Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
|
2021-04-17 15:20:24 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-17 15:20:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2021-04-17 15:20:24 +00:00
|
|
|
#include <AK/Optional.h>
|
|
|
|
|
|
|
|
namespace WebSocket {
|
|
|
|
|
|
|
|
class Message {
|
|
|
|
public:
|
2022-12-04 18:02:33 +00:00
|
|
|
explicit Message(DeprecatedString const& data)
|
2021-04-17 15:20:24 +00:00
|
|
|
: m_is_text(true)
|
2022-01-20 17:47:39 +00:00
|
|
|
, m_data(ByteBuffer::copy(data.bytes()).release_value_but_fixme_should_propagate_errors()) // FIXME: Handle possible OOM situation.
|
2021-04-17 15:20:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit Message(ByteBuffer data, bool is_text)
|
|
|
|
: m_is_text(is_text)
|
|
|
|
, m_data(move(data))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit Message(ByteBuffer const&& data, bool is_text)
|
|
|
|
: m_is_text(is_text)
|
|
|
|
, m_data(move(data))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_text() const { return m_is_text; }
|
|
|
|
ByteBuffer const& data() const { return m_data; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_is_text { false };
|
|
|
|
ByteBuffer m_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|