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