1 /* 2 * Copyright (c) 2021 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 STREAM_DEPACKETTIZER_H 17 #define STREAM_DEPACKETTIZER_H 18 19 #include <memory> 20 #include <utility> 21 22 #include "stream_packet_header.h" 23 24 namespace Communication { 25 namespace SoftBus { 26 class StreamDepacketizer { 27 public: StreamDepacketizer(int type)28 explicit StreamDepacketizer(int type) : streamType_(type) {} 29 virtual ~StreamDepacketizer() = default; 30 31 void DepacketizeHeader(const char *header); 32 void DepacketizeBuffer(char *buffer); 33 GetHeaderDataLen()34 uint32_t GetHeaderDataLen() const 35 { 36 return header_.GetDataLen(); 37 } 38 GetStreamId()39 uint32_t GetStreamId() const 40 { 41 return header_.GetStreamId(); 42 } 43 GetSeqNum()44 uint32_t GetSeqNum() const 45 { 46 return header_.GetSeqNum(); 47 } 48 GetUserExt()49 std::unique_ptr<char[]> GetUserExt() 50 { 51 return tlvs_.GetExtBuffer(); 52 } 53 GetUserExtSize()54 ssize_t GetUserExtSize() const 55 { 56 return tlvs_.GetExtLen(); 57 } 58 GetData()59 std::unique_ptr<char[]> GetData() 60 { 61 return std::move(data_); 62 } 63 GetDataLength()64 int GetDataLength() const 65 { 66 return dataLength_; 67 } 68 69 private: 70 int streamType_; 71 StreamPacketHeader header_ {}; 72 TwoLevelsTlv tlvs_ {}; 73 std::unique_ptr<char[]> data_ = nullptr; 74 int dataLength_ = 0; 75 }; 76 } // namespace SoftBus 77 } // namespace Communication 78 79 #endif 80