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