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_JSON_PROTOCOL_H
16 #define WIFI_DIRECT_JSON_PROTOCOL_H
17 
18 #include "data/serializable.h"
19 #include "protocol/wifi_direct_protocol.h"
20 #include "nlohmann/json.hpp"
21 
22 namespace OHOS::SoftBus {
23 class JsonProtocol : public WifiDirectProtocol {
24 public:
GetType()25     ProtocolType GetType() override { return ProtocolType::JSON; };
26     void SetFormat(const ProtocolFormat &format) override;
27     ProtocolFormat GetFormat() const override;
28 
29     void Write(int key, Serializable::ValueType type, const uint8_t *value, size_t size) override;
30     bool Read(int &key, uint8_t *&value, size_t &size) override;
31 
32     void SetInput(const std::vector<uint8_t> &input) override;
33     void GetOutput(std::vector<uint8_t> &output) override;
34 
35 private:
36     ProtocolFormat format_;
37     nlohmann::json jsonObject_;
38     nlohmann::json::iterator readPos_;
39     static constexpr int DEFAULT_CAPACITY = 256;
40     uint8_t data_[DEFAULT_CAPACITY];
41 };
42 }
43 #endif
44