[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / network / EventPacket.cpp
blob17389f1f63c2d0cfadf357350dfa49877581c236
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "EventPacket.h"
11 #include "Socket.h"
12 #include "utils/log.h"
14 using namespace EVENTPACKET;
16 /************************************************************************/
17 /* CEventPacket */
18 /************************************************************************/
19 bool CEventPacket::Parse(int datasize, const void *data)
21 unsigned char* buf = const_cast<unsigned char*>((const unsigned char *)data);
22 if (datasize < HEADER_SIZE || datasize > PACKET_SIZE)
23 return false;
25 // check signature
26 if (memcmp(data, (const void*)HEADER_SIG, HEADER_SIG_LENGTH) != 0)
27 return false;
29 buf += HEADER_SIG_LENGTH;
31 // extract protocol version
32 m_cMajVer = (*buf++);
33 m_cMinVer = (*buf++);
35 if (m_cMajVer != 2 && m_cMinVer != 0)
36 return false;
38 // get packet type
39 m_eType = (PacketType)ntohs(*((uint16_t*)buf));
41 if (m_eType < (unsigned short)PT_HELO || m_eType >= (unsigned short)PT_LAST)
42 return false;
44 // get packet sequence id
45 buf += 2;
46 m_iSeq = ntohl(*((uint32_t*)buf));
48 // get total message length
49 buf += 4;
50 m_iTotalPackets = ntohl(*((uint32_t*)buf));
52 // get payload size
53 buf += 4;
54 uint16_t payloadSize = ntohs(*(reinterpret_cast<uint16_t*>(buf)));
56 if ((payloadSize + HEADER_SIZE) != static_cast<uint16_t>(datasize))
57 return false;
59 // get the client's token
60 buf += 2;
61 m_iClientToken = ntohl(*((uint32_t*)buf));
63 buf += 4;
65 // get payload
66 if (payloadSize > 0)
68 // forward past reserved bytes
69 buf += 10;
71 m_pPayload = std::vector<uint8_t>(buf, buf + payloadSize);
73 m_bValid = true;
74 return true;
77 void CEventPacket::SetPayload(std::vector<uint8_t> payload)
79 m_pPayload = std::move(payload);