winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

JsonUtil.h (2502B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <json/json.h>
      5 
      6 // Disable dllimport for cpprest JSON in any downstream consumers
      7 #ifndef _NO_ASYNCRTIMP
      8 #define _NO_ASYNCRTIMP
      9 #endif
     10 
     11 #ifndef WINGET_DISABLE_FOR_FUZZING
     12 #include <cpprest/json.h>
     13 #endif
     14 
     15 #include <optional>
     16 #include <string>
     17 #include <vector>
     18 
     19 namespace AppInstaller::JSON
     20 {
     21     // For JSON CPP Lib
     22     template<class T>
     23     std::optional<T> GetValue(const Json::Value& node);
     24 
     25     template<>
     26     std::optional<std::string> GetValue<std::string>(const Json::Value& node);
     27 
     28     template<>
     29     std::optional<uint32_t> GetValue<uint32_t>(const Json::Value& node);
     30 
     31     template<>
     32     std::optional<bool> GetValue<bool>(const Json::Value& node);
     33 
     34     template<>
     35     std::optional<std::vector<std::string>> GetValue<std::vector<std::string>>(const Json::Value& node);
     36 
     37 #ifndef WINGET_DISABLE_FOR_FUZZING
     38     // For cpprestsdk JSON
     39     std::optional<std::reference_wrapper<const web::json::value>> GetJsonValueFromNode(const web::json::value& node, const utility::string_t& keyName);
     40 
     41     std::optional<std::string> GetRawStringValueFromJsonValue(const web::json::value& value);
     42 
     43     std::optional<std::string> GetRawStringValueFromJsonNode(const web::json::value& node, const utility::string_t& keyName);
     44 
     45     std::optional<bool> GetRawBoolValueFromJsonValue(const web::json::value& value);
     46 
     47     std::optional<bool> GetRawBoolValueFromJsonNode(const web::json::value& node, const utility::string_t& keyName);
     48 
     49     std::optional<std::reference_wrapper<const web::json::array>> GetRawJsonArrayFromJsonNode(const web::json::value& node, const utility::string_t& keyName);
     50 
     51     std::vector<std::string> GetRawStringArrayFromJsonNode(const web::json::value& node, const utility::string_t& keyName);
     52     std::set<std::string> GetRawStringSetFromJsonNode(const web::json::value& node, const utility::string_t& keyName);
     53 
     54     std::optional<int> GetRawIntValueFromJsonValue(const web::json::value& value);
     55 
     56     std::optional<int> GetRawIntValueFromJsonNode(const web::json::value& value, const utility::string_t& keyName);
     57 
     58     utility::string_t GetUtilityString(std::string_view nodeName);
     59 
     60     web::json::value GetStringValue(std::string_view value);
     61 
     62     // Base64 encode
     63     std::string Base64Encode(const std::vector<BYTE>& input);
     64 
     65     // Base64 decode
     66     std::vector<BYTE>Base64Decode(const std::string& input);
     67 #endif
     68 
     69     bool IsValidNonEmptyStringValue(std::optional<std::string>& value);
     70 }