1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NET_PACKET_H 17 #define NET_PACKET_H 18 19 #include "stream_buffer.h" 20 21 #undef MMI_LOG_TAG 22 #define MMI_LOG_TAG "NetPacket" 23 24 #pragma pack(1) 25 using PACKHEAD = struct PackHead { 26 MmiMessageId idMsg; 27 int32_t size; 28 }; 29 #pragma pack() 30 31 namespace OHOS { 32 namespace MMI { 33 class NetPacket : public StreamBuffer { 34 public: 35 explicit NetPacket(MmiMessageId msgId); 36 NetPacket(const NetPacket &pkt); 37 NetPacket &operator = (const NetPacket &pkt); 38 DISALLOW_MOVE(NetPacket); 39 virtual ~NetPacket(); 40 41 virtual void MakeData(StreamBuffer &buf) const; 42 GetSize()43 size_t GetSize() const 44 { 45 return Size(); 46 } GetPacketLength()47 int32_t GetPacketLength() const 48 { 49 return (static_cast<int32_t>(sizeof(PackHead)) + wPos_); 50 } GetData()51 const char *GetData() const 52 { 53 return Data(); 54 } GetMsgId()55 MmiMessageId GetMsgId() const 56 { 57 return msgId_; 58 } 59 60 protected: 61 MmiMessageId msgId_ = MmiMessageId::INVALID; 62 }; 63 } // namespace MMI 64 } // namespace OHOS 65 #endif // NET_PACKET_H