180922886Sopenharmony_ci/*
280922886Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
480922886Sopenharmony_ci * you may not use this file except in compliance with the License.
580922886Sopenharmony_ci * You may obtain a copy of the License at
680922886Sopenharmony_ci *
780922886Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
880922886Sopenharmony_ci *
980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1280922886Sopenharmony_ci * See the License for the specific language governing permissions and
1380922886Sopenharmony_ci * limitations under the License.
1480922886Sopenharmony_ci */
1580922886Sopenharmony_ci
1680922886Sopenharmony_ci#ifndef OHOS_JSON_UTILS_H
1780922886Sopenharmony_ci#define OHOS_JSON_UTILS_H
1880922886Sopenharmony_ci
1980922886Sopenharmony_ci#include <algorithm>
2080922886Sopenharmony_ci#include <iterator>
2180922886Sopenharmony_ci#include <nlohmann/json.hpp>
2280922886Sopenharmony_ci#include <string>
2380922886Sopenharmony_ci#include <vector>
2480922886Sopenharmony_ci
2580922886Sopenharmony_ci#include "avsession_info.h"
2680922886Sopenharmony_ci#include "avsession_errors.h"
2780922886Sopenharmony_ci
2880922886Sopenharmony_cinamespace OHOS::AVSession {
2980922886Sopenharmony_ciusing json = nlohmann::json;
3080922886Sopenharmony_ciclass JsonUtils {
3180922886Sopenharmony_cipublic:
3280922886Sopenharmony_ci    static int32_t GetJsonCapability(const std::vector<std::vector<int32_t>>& capability, std::string& jsonCapability);
3380922886Sopenharmony_ci    static int32_t GetVectorCapability(const std::string& jsonCapability,
3480922886Sopenharmony_ci                                       std::vector<std::vector<int32_t>>& vectorCapability);
3580922886Sopenharmony_ci    static int32_t GetAllCapability(const std::string& sessionInfo, std::string& jsonCapability);
3680922886Sopenharmony_ci
3780922886Sopenharmony_ci    static int32_t SetSessionBasicInfo(std::string& sessionInfo, const AVSessionBasicInfo& basicInfo);
3880922886Sopenharmony_ci    static int32_t GetSessionBasicInfo(const std::string& sessionInfo, AVSessionBasicInfo& basicInfo);
3980922886Sopenharmony_ci
4080922886Sopenharmony_ci    static int32_t SetSessionDescriptors(std::string& sessionInfo, const std::vector<AVSessionDescriptor>& descriptors);
4180922886Sopenharmony_ci    static int32_t GetSessionDescriptors(const std::string& sessionInfo, std::vector<AVSessionDescriptor>& descriptors);
4280922886Sopenharmony_ci
4380922886Sopenharmony_ci    static int32_t SetSessionDescriptor(std::string& sessionInfo, const AVSessionDescriptor& descriptor);
4480922886Sopenharmony_ci    static int32_t GetSessionDescriptor(const std::string& sessionInfo, AVSessionDescriptor& descriptor);
4580922886Sopenharmony_ci
4680922886Sopenharmony_ciprivate:
4780922886Sopenharmony_ci    static int32_t JsonToVector(json object, std::vector<int32_t>& out);
4880922886Sopenharmony_ci    static int32_t ConvertSessionType(const std::string& typeString);
4980922886Sopenharmony_ci    static std::string ConvertSessionType(int32_t type);
5080922886Sopenharmony_ci    static bool IsString(const json& jsonObj, const std::string& key);
5180922886Sopenharmony_ci    static bool IsInt32(const json& jsonObj, const std::string& key);
5280922886Sopenharmony_ci    static bool IsBool(const json& jsonObj, const std::string& key);
5380922886Sopenharmony_ci};
5480922886Sopenharmony_ci} // namespace OHOS::AVSession
5580922886Sopenharmony_ci#endif // OHOS_JSON_UTILS_H
56