| 17 | { |
| 18 | |
| 19 | class Packet |
| 20 | { |
| 21 | public: |
| 22 | Packet() |
| 23 | : m_Header(0) |
| 24 | , m_PacketFamily(0) |
| 25 | , m_PacketId(0) |
| 26 | , m_Length(0) |
| 27 | , m_Data(nullptr) |
| 28 | {} |
| 29 | |
| 30 | Packet(uint32_t header) |
| 31 | : m_Header(header) |
| 32 | , m_Length(0) |
| 33 | , m_Data(nullptr) |
| 34 | { |
| 35 | m_PacketId = ((header >> 16) & 1023); |
| 36 | m_PacketFamily = (header >> 26); |
| 37 | } |
| 38 | |
| 39 | Packet(uint32_t header, uint32_t length, std::unique_ptr<unsigned char[]>& data) |
| 40 | : m_Header(header) |
| 41 | , m_Length(length) |
| 42 | , m_Data(std::move(data)) |
| 43 | { |
| 44 | m_PacketId = ((header >> 16) & 1023); |
| 45 | m_PacketFamily = (header >> 26); |
| 46 | |
| 47 | if (length == 0 && m_Data != nullptr) |
| 48 | { |
| 49 | throw arm::pipe::InvalidArgumentException("Data should be null when length is zero"); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | Packet(Packet&& other) |
| 54 | : m_Header(other.m_Header) |
| 55 | , m_PacketFamily(other.m_PacketFamily) |
| 56 | , m_PacketId(other.m_PacketId) |
| 57 | , m_Length(other.m_Length) |
| 58 | , m_Data(std::move(other.m_Data)) |
| 59 | { |
| 60 | other.m_Header = 0; |
| 61 | other.m_PacketFamily = 0; |
| 62 | other.m_PacketId = 0; |
| 63 | other.m_Length = 0; |
| 64 | } |
| 65 | |
| 66 | ~Packet() = default; |
| 67 | |
| 68 | Packet(const Packet& other) = delete; |
| 69 | Packet& operator=(const Packet&) = delete; |
| 70 | Packet& operator=(Packet&&) = default; |
| 71 | |
| 72 | uint32_t GetHeader() const { return m_Header; } |
| 73 | uint32_t GetPacketFamily() const { return m_PacketFamily; } |
| 74 | uint32_t GetPacketId() const { return m_PacketId; } |
| 75 | uint32_t GetPacketClass() const { return m_PacketId >> 3; } |
| 76 | uint32_t GetPacketType() const { return m_PacketId & 7; } |
no outgoing calls