Message.h 771 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/Optional.h>
  9. namespace WebSocket {
  10. class Message {
  11. public:
  12. explicit Message(String const& data)
  13. : m_is_text(true)
  14. , m_data(ByteBuffer::copy(data.bytes()))
  15. {
  16. }
  17. explicit Message(ByteBuffer data, bool is_text)
  18. : m_is_text(is_text)
  19. , m_data(move(data))
  20. {
  21. }
  22. explicit Message(ByteBuffer const&& data, bool is_text)
  23. : m_is_text(is_text)
  24. , m_data(move(data))
  25. {
  26. }
  27. bool is_text() const { return m_is_text; }
  28. ByteBuffer const& data() const { return m_data; }
  29. private:
  30. bool m_is_text { false };
  31. ByteBuffer m_data;
  32. };
  33. }