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