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