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.
9 #include "EventPacket.h"
12 #include "utils/log.h"
14 using namespace EVENTPACKET
;
16 /************************************************************************/
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
)
26 if (memcmp(data
, (const void*)HEADER_SIG
, HEADER_SIG_LENGTH
) != 0)
29 buf
+= HEADER_SIG_LENGTH
;
31 // extract protocol version
35 if (m_cMajVer
!= 2 && m_cMinVer
!= 0)
39 m_eType
= (PacketType
)ntohs(*((uint16_t*)buf
));
41 if (m_eType
< (unsigned short)PT_HELO
|| m_eType
>= (unsigned short)PT_LAST
)
44 // get packet sequence id
46 m_iSeq
= ntohl(*((uint32_t*)buf
));
48 // get total message length
50 m_iTotalPackets
= ntohl(*((uint32_t*)buf
));
54 uint16_t payloadSize
= ntohs(*(reinterpret_cast<uint16_t*>(buf
)));
56 if ((payloadSize
+ HEADER_SIZE
) != static_cast<uint16_t>(datasize
))
59 // get the client's token
61 m_iClientToken
= ntohl(*((uint32_t*)buf
));
68 // forward past reserved bytes
71 m_pPayload
= std::vector
<uint8_t>(buf
, buf
+ payloadSize
);
77 void CEventPacket::SetPayload(std::vector
<uint8_t> payload
)
79 m_pPayload
= std::move(payload
);