You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

4 months ago
  1. /*
  2. * IXWebSocketMessage.h
  3. * Author: Benjamin Sergeant
  4. * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved.
  5. */
  6. #pragma once
  7. #include "IXWebSocketCloseInfo.h"
  8. #include "IXWebSocketErrorInfo.h"
  9. #include "IXWebSocketMessageType.h"
  10. #include "IXWebSocketOpenInfo.h"
  11. #include <memory>
  12. #include <string>
  13. namespace ix
  14. {
  15. struct WebSocketMessage
  16. {
  17. WebSocketMessageType type;
  18. const std::string& str;
  19. size_t wireSize;
  20. WebSocketErrorInfo errorInfo;
  21. WebSocketOpenInfo openInfo;
  22. WebSocketCloseInfo closeInfo;
  23. bool binary;
  24. WebSocketMessage(WebSocketMessageType t,
  25. const std::string& s,
  26. size_t w,
  27. WebSocketErrorInfo e,
  28. WebSocketOpenInfo o,
  29. WebSocketCloseInfo c,
  30. bool b = false)
  31. : type(t)
  32. , str(s)
  33. , wireSize(w)
  34. , errorInfo(e)
  35. , openInfo(o)
  36. , closeInfo(c)
  37. , binary(b)
  38. {
  39. ;
  40. }
  41. /**
  42. * @brief Deleted overload to prevent binding `str` to a temporary, which would cause
  43. * undefined behavior since class members don't extend lifetime beyond the constructor call.
  44. */
  45. WebSocketMessage(WebSocketMessageType t,
  46. std::string&& s,
  47. size_t w,
  48. WebSocketErrorInfo e,
  49. WebSocketOpenInfo o,
  50. WebSocketCloseInfo c,
  51. bool b = false) = delete;
  52. };
  53. using WebSocketMessagePtr = std::unique_ptr<WebSocketMessage>;
  54. } // namespace ix