1 /* 2 * Copyright (c) 2024 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 WIFI_DIRECT_TLV_PROTOCOL_H 16 #define WIFI_DIRECT_TLV_PROTOCOL_H 17 18 #include "wifi_direct_protocol.h" 19 20 namespace OHOS::SoftBus { 21 class TlvProtocol : public WifiDirectProtocol { 22 public: GetType()23 ProtocolType GetType() override { return ProtocolType::TLV; }; 24 void SetFormat(const ProtocolFormat &format) override; 25 ProtocolFormat GetFormat() const override; 26 27 void Write(int key, Serializable::ValueType type, const uint8_t *value, size_t size) override; 28 bool Read(int &key, uint8_t *&value, size_t &size) override; 29 30 void SetInput(const std::vector<uint8_t> &input) override; 31 void GetOutput(std::vector<uint8_t> &output) override; 32 33 static constexpr int TLV_TAG_SIZE = 1; 34 static constexpr int TLV_LENGTH_SIZE1 = 1; 35 static constexpr int TLV_LENGTH_SIZE2 = 2; 36 37 private: 38 size_t readPos_ = 0; 39 std::vector<uint8_t> data_; 40 ProtocolFormat format_ { TLV_TAG_SIZE, TLV_LENGTH_SIZE2 }; 41 }; 42 } 43 44 #endif 45