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 UDMF_CUSTOM_UTD_JSON_PARSER_H 17 #define UDMF_CUSTOM_UTD_JSON_PARSER_H 18 #include <string> 19 #include <vector> 20 #include <set> 21 #include <map> 22 #include <cstdint> 23 #include "visibility.h" 24 #include "cJSON.h" 25 #include "utd_common.h" 26 namespace OHOS { 27 namespace UDMF { 28 class API_EXPORT CustomUtdJsonParser { 29 public: 30 using json = cJSON; 31 CustomUtdJsonParser(); 32 ~CustomUtdJsonParser(); 33 bool ParseStoredCustomUtdJson(const std::string &jsonData, std::vector<TypeDescriptorCfg> &typesCfg); 34 bool ParseUserCustomUtdJson(const std::string &jsonData, std::vector<TypeDescriptorCfg> &typesDeclarations, 35 std::vector<TypeDescriptorCfg> &typesReference); 36 bool ConvertUtdCfgsToJson(const std::vector<TypeDescriptorCfg> &typesCfg, std::string &jsonData); 37 38 private: 39 bool AddJsonStringArray(const std::vector<std::string> &datas, const std::string &nodeName, json &node); 40 bool GetTypeDescriptors(const json &jsonRoot, const std::string &nodeName, 41 std::vector<TypeDescriptorCfg> &typesCfg); 42 std::string GetStringValue(const json &node, const std::string &nodeName); 43 std::vector<std::string> GetStringArrayValue(const json &node, const std::string &nodeName); 44 }; 45 } // namespace UDMF 46 } // namespace OHOS 47 #endif // UDMF_CUSTOM_UTD_JSON_PARSER_H