MythTV master
mythwebsockettypes.cpp
Go to the documentation of this file.
1// Qt
2#include <QStringList>
3
4// MythTV
6
7WSFrame MythWebSocketFrame::CreateFrame(const QByteArray &Header)
8{
9 if (Header.size() != 2)
10 return nullptr;
11
12 bool final = (Header[0] & 0x80) != 0;
13 auto code = static_cast<WSOpCode>(Header[0] & 0x0F);
14 bool masked = (Header[1] & 0x80) != 0;
15 uint64_t length = (Header[1] & 0x7F);
16 bool invalid = (Header[0] & 0x70) != 0;
17 return std::shared_ptr<MythWebSocketFrame>(new MythWebSocketFrame(invalid, code, final, masked, length));
18}
19
20MythWebSocketFrame::MythWebSocketFrame(bool Invalid, WSOpCode Code, bool Final,
21 bool Masked, uint64_t Length)
22 : m_invalid(Invalid),
23 m_opCode(Code),
24 m_length(Length),
25 m_final(Final),
26 m_masked(Masked)
27{
28}
29
31{
32 switch (Code)
33 {
34 case WSOpClose: return "Close";
35 case WSOpContinuation: return "Continuation";
36 case WSOpPing: return "Ping";
37 case WSOpPong: return "Pong";
38 case WSOpBinaryFrame: return "Binary";
39 case WSOpTextFrame: return "Text";
40 default: break;
41 }
42 return "Reserved";
43}
44
46{
47 switch (Protocol)
48 {
49 case ProtJSONRPC:
50 case ProtXMLRPC:
51 case ProtPLISTRPC: return WSOpTextFrame;
52 case ProtCBORRPC: return WSOpBinaryFrame;
53 default: break;
54 }
55 return WSOpBinaryFrame;
56}
57
59{
60 switch (Protocol)
61 {
62 case ProtFrame: // for testing atm
63 case ProtJSONRPC: return true;
64 default: break;
65 }
66 return false;
67}
static QString OpCodeToString(WSOpCode Code)
static WSOpCode FrameFormatForProtocol(MythSocketProtocol Protocol)
static bool UseRawTextForProtocol(MythSocketProtocol Protocol)
MythWebSocketFrame(bool Invalid, WSOpCode Code, bool Final, bool Masked, uint64_t Length)
static WSFrame CreateFrame(const QByteArray &Header)
MythSocketProtocol
@ ProtPLISTRPC
@ ProtCBORRPC
@ ProtXMLRPC
@ ProtFrame
@ ProtJSONRPC
std::shared_ptr< MythWebSocketFrame > WSFrame
@ WSOpTextFrame
@ WSOpBinaryFrame
@ WSOpContinuation
@ WSOpClose
@ WSOpPing
@ WSOpPong