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