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