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 "proto.h" 20 #include "stream_buffer.h" 21 22 #pragma pack(1) 23 using PACKHEAD = struct PackHead { 24 MmiMessageId idMsg; 25 int32_t size; 26 }; 27 #pragma pack() 28 29 namespace OHOS { 30 namespace MMI { 31 class NetPacket : public StreamBuffer { 32 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "NetPacket" }; 33 public: 34 explicit NetPacket(MmiMessageId msgId); 35 NetPacket(const NetPacket &pkt); 36 NetPacket &operator = (const NetPacket &pkt); 37 DISALLOW_MOVE(NetPacket); 38 virtual ~NetPacket(); 39 40 virtual void MakeData(StreamBuffer &buf) const; 41 GetSize()42 size_t GetSize() const 43 { 44 return Size(); 45 } GetPacketLength()46 int32_t GetPacketLength() const 47 { 48 return (static_cast<int32_t>(sizeof(PackHead)) + wPos_); 49 } GetData()50 const char *GetData() const 51 { 52 return Data(); 53 } GetMsgId()54 MmiMessageId GetMsgId() const 55 { 56 return msgId_; 57 } 58 59 protected: 60 MmiMessageId msgId_ = MmiMessageId::INVALID; 61 }; 62 } // namespace MMI 63 } // namespace OHOS 64 #endif // NET_PACKET_H