1 /*
2  * Copyright (c) 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)
26 using PACKHEAD = struct PackHead {
27     OHOS::Sensors::MessageId idMsg;
28     size_t size;
29 };
30 
31 #pragma pack()
32 namespace OHOS {
33 namespace Sensors {
34 class NetPacket : public StreamBuffer {
35 public:
36     explicit NetPacket(MessageId msgId);
37     NetPacket(const NetPacket &pkt);
38     NetPacket &operator = (const NetPacket &pkt);
39     ~NetPacket() = default;
40     void MakeData(StreamBuffer &buf) const;
41     size_t GetSize() const;
42     size_t GetPacketLength() const;
43     const char *GetData() const;
44     MessageId GetMsgId() const;
45     DISALLOW_MOVE(NetPacket);
46 
47 protected:
48     MessageId msgId_ = MessageId::INVALID;
49 };
50 } // namespace Sensors
51 } // namespace OHOS
52 #endif // NET_PACKET_H