LCOV - code coverage report
Current view: top level - adump/common - json_parser.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.0 % 20 16
Test Date: 2026-07-28 10:54:24 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : #include "adump_pub.h"
      11              : #include "log/adx_log.h"
      12              : #include "json_parser.h"
      13              : #include "adump_error_manager.h"
      14              : #include "common/str_utils.h"
      15              : 
      16              : #include <fstream>
      17              : #include <sstream>
      18              : #include <regex>
      19              : #include <sys/stat.h>
      20              : #include "mmpa/mmpa_api.h"
      21              : 
      22              : namespace Adx {
      23              : 
      24          859 : int32_t JsonParser::ParseJsonFromMemory(const char *dumpConfigData, size_t dumpConfigSize, 
      25              :     nlohmann::json &js, std::string &errMsg)
      26              : {
      27          859 :     errMsg.clear();
      28          859 :     if ((dumpConfigData == nullptr) || (dumpConfigSize == 0U)) {
      29            6 :         errMsg = "Invalid input parameters";
      30            6 :         IDE_LOGD("Parse json from memory failed: invaild input parameters.");
      31            6 :         return ADUMP_INPUT_FAILED;
      32              :     }
      33              :     try
      34              :     {
      35          853 :         std::string_view jsonString(dumpConfigData, dumpConfigSize);
      36          853 :         IDE_LOGI("Parse json string: %.*s", static_cast<int>(jsonString.size()), jsonString.data());
      37          868 :         js = nlohmann::json::parse(jsonString);
      38          838 :         IDE_LOGD("Parse json successfully.");
      39          838 :         return ADUMP_SUCCESS;
      40              :     }
      41           15 :     catch(const nlohmann::json::parse_error& e)
      42              :     {
      43           15 :         errMsg = e.what();
      44           15 :         IDE_LOGE("JSON parse error: %s", e.what());
      45           15 :     }
      46            0 :     catch(const std::exception& e)
      47              :     {
      48            0 :         errMsg = e.what();
      49            0 :         IDE_LOGE("Unexpected error while parsing JSON from memory: %s", e.what());
      50            0 :     }
      51           15 :     return ADUMP_INPUT_FAILED;
      52              : }
      53              : } // namespace Adx
        

Generated by: LCOV version 2.0-1