Message.h 893 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/ByteString.h>
  9. #include <AK/Optional.h>
  10. namespace WebSocket {
  11. class Message {
  12. public:
  13. explicit Message(ByteString const& data)
  14. : m_is_text(true)
  15. , m_data(ByteBuffer::copy(data.bytes()).release_value_but_fixme_should_propagate_errors()) // FIXME: Handle possible OOM situation.
  16. {
  17. }
  18. explicit Message(ByteBuffer data, bool is_text)
  19. : m_is_text(is_text)
  20. , m_data(move(data))
  21. {
  22. }
  23. explicit Message(ByteBuffer const&& data, bool is_text)
  24. : m_is_text(is_text)
  25. , m_data(move(data))
  26. {
  27. }
  28. bool is_text() const { return m_is_text; }
  29. ByteBuffer const& data() const { return m_data; }
  30. private:
  31. bool m_is_text { false };
  32. ByteBuffer m_data;
  33. };
  34. }