• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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     MessageId idMsg { MessageId::INVALID };
24     int32_t size { 0 };
25 };
26 #pragma pack()
27 
28 namespace OHOS {
29 namespace Msdp {
30 class NetPacket : public StreamBuffer {
31     static constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "NetPacket" };
32 public:
33     explicit NetPacket(MessageId 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;
GetPacketLength()40     int32_t GetPacketLength() const
41     {
42         return (static_cast<int32_t>(sizeof(PackHead)) + wPos_);
43     }
GetData()44     const char *GetData() const
45     {
46         return Data();
47     }
GetMsgId()48     MessageId GetMsgId() const
49     {
50         return msgId_;
51     }
52 
53 protected:
54     MessageId msgId_ { MessageId::INVALID };
55 };
56 } // namespace Msdp
57 } // namespace OHOS
58 #endif // NET_PACKET_H