Serenity Operating System
at master 43 lines 905 B view raw
1/* 2 * Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/ByteBuffer.h> 10#include <AK/DeprecatedString.h> 11#include <AK/Optional.h> 12 13namespace WebSocket { 14 15class Message { 16public: 17 explicit Message(DeprecatedString const& data) 18 : m_is_text(true) 19 , m_data(ByteBuffer::copy(data.bytes()).release_value_but_fixme_should_propagate_errors()) // FIXME: Handle possible OOM situation. 20 { 21 } 22 23 explicit Message(ByteBuffer data, bool is_text) 24 : m_is_text(is_text) 25 , m_data(move(data)) 26 { 27 } 28 29 explicit Message(ByteBuffer const&& data, bool is_text) 30 : m_is_text(is_text) 31 , m_data(move(data)) 32 { 33 } 34 35 bool is_text() const { return m_is_text; } 36 ByteBuffer const& data() const { return m_data; } 37 38private: 39 bool m_is_text { false }; 40 ByteBuffer m_data; 41}; 42 43}