| 1 |
/* |
| 2 |
* Copyright (C) 2010-2021 Team Kodi (https://kodi.tv) |
| 3 |
* Copyright (C) 2010 Alwin Esch (Team Kodi) |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSE.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#pragma once |
| 10 |
|
| 11 |
#include <kodi/AddonBase.h> |
| 12 |
#include <stddef.h> |
| 13 |
#include <stdint.h> |
| 14 |
|
| 15 |
class ATTR_DLL_LOCAL cRequestPacket |
| 16 |
{ |
| 17 |
public: |
| 18 |
cRequestPacket() = default; |
| 19 |
~cRequestPacket(); |
| 20 |
|
| 21 |
void init(uint32_t opcode, |
| 22 |
bool stream = false, |
| 23 |
bool setUserDataLength = false, |
| 24 |
size_t userDataLength = 0); |
| 25 |
void add_String(const char* string); |
| 26 |
void add_U8(uint8_t c); |
| 27 |
void add_U32(uint32_t ul); |
| 28 |
void add_S32(int32_t l); |
| 29 |
void add_U64(uint64_t ull); |
| 30 |
void add_S64(int64_t ll); |
| 31 |
|
| 32 |
uint8_t* getPtr() const { return m_buffer; } |
| 33 |
size_t getLen() const { return m_bufUsed; } |
| 34 |
uint32_t getChannel() const { return m_channel; } |
| 35 |
uint32_t getSerial() const { return m_serialNumber; } |
| 36 |
uint32_t getOpcode() const { return m_opcode; } |
| 37 |
|
| 38 |
private: |
| 39 |
static uint32_t m_serialNumberCounter; |
| 40 |
|
| 41 |
uint8_t* m_buffer = nullptr; |
| 42 |
size_t m_bufSize = 0; |
| 43 |
size_t m_bufUsed = 0; |
| 44 |
bool lengthSet = false; |
| 45 |
|
| 46 |
uint32_t m_channel = 0; |
| 47 |
uint32_t m_serialNumber = 0; |
| 48 |
|
| 49 |
uint32_t m_opcode = 0; |
| 50 |
|
| 51 |
void checkExtend(size_t by); |
| 52 |
|
| 53 |
const static size_t m_headerLength = 16; |
| 54 |
const static size_t m_userDataLenPos = 12; |
| 55 |
}; |